#P3900. [湖南集训] 图森
[湖南集训] 图森
Description
There is a collection of strings; the concept of a collection here differs from the mathematical set in that duplicate elements are allowed (i.e., it is a multiset). Initially, contains strings . There are two operations:
- Add to a string that already exists in .
- Select two strings from , concatenate them, and add the resulting string to .
After performing any number of operations, among all strings in , what is the maximum possible length of a palindromic substring? If the length can be infinite, output .
Input Format
The first line contains an integer , the initial size of the collection.
Each of the next lines contains a string. The string on the -th line is . Each string contains only lowercase English letters.
Output Format
If the maximum length of a palindromic substring is not infinite, output an integer representing its length; otherwise output .
3
abc
abacde
ecab
7
1
ha
Infinity
Hint
Sample explanation
In the first sample, concatenate and to get , where the underlined part is the longest palindromic substring of length . It can be proven that no longer palindromic substring exists.
In the second sample, you can concatenate arbitrarily many copies of to obtain and so on, yielding palindromic substrings of any odd length. Therefore the answer is infinite, so output .
Constraints

Translated by ChatGPT 5
京公网安备 11011102002149号