P28695 [洛谷] [Hunan Training] Tusen
省选
题目描述

Problem Description

There is a string set $S$, which differs from the mathematical concept of a set in that it can contain duplicate elements. Initially, $S$ contains $n$ strings $s_1, s_2, \cdots, s_n$. There are two types of operations:

  • Add a string that already exists in $S$ to $S$.
  • Select two strings from $S$ and add the concatenated result to $S$.

We want to know the maximum length of the longest palindromic substring that can be found in all strings in $S$ after performing any number of operations. If the length can be infinite, you need to output $\text{Infinity}$.

Input Format

The first line contains an integer $n$, representing the initial size of the set.

The next $n$ lines each contain a string. The string on the $i$-th line is $s_i$. It is guaranteed that the strings only contain lowercase English letters.

Output Format

If the length of the longest palindromic substring is not infinite, output an integer representing its length; otherwise, output $\text{Infinity}$.

Sample Input and Output

Sample Input #1

3
abc
abacde
ecab

Sample Output #1

7

Sample Input #2

1
ha

Sample Output #2

Infinity

Notes

Sample Explanation

In the first sample, concatenating $\text{ecab}$ and $\text{abacde}$ results in $\text{e}\underline{\text{cababac}}\text{de}$, where the underlined part is the longest palindromic substring with a length of $7$. It can be proven that no longer palindromic substring exists.

In the second sample, any number of $\text{ha}$ can be concatenated to form palindromic substrings of any odd length, such as $\underline{\text{h}}\text{a}$, $\underline{\text{hah}}\text{a}$, $\underline{\text{hahah}}\text{a}$, etc. Therefore, the answer is infinite, and $\text{Infinity}$ is output.

Data Size and Constraints

OvO

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 abc abacde ecab
样例输出
7