#P3900. [湖南集训] 图森

[湖南集训] 图森

Description

There is a collection SS 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, SS contains nn strings s1,s2,,sns_1, s_2, \cdots, s_n. There are two operations:

  • Add to SS a string that already exists in SS.
  • Select two strings from SS, concatenate them, and add the resulting string to SS.

After performing any number of operations, among all strings in SS, what is the maximum possible length of a palindromic substring? If the length can be infinite, output Infinity\text{Infinity}.

Input Format

The first line contains an integer nn, the initial size of the collection.

Each of the next nn lines contains a string. The string on the ii-th line is sis_i. 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 Infinity\text{Infinity}.

3
abc
abacde
ecab
7
1
ha
Infinity

Hint

Sample explanation

In the first sample, concatenate ecab\text{ecab} and abacde\text{abacde} to get ecababacde\text{e}\underline{\text{cababac}}\text{de}, where the underlined part is the longest palindromic substring of length 77. It can be proven that no longer palindromic substring exists.

In the second sample, you can concatenate arbitrarily many copies of ha\text{ha} to obtain ha,\underline{\text{h}}\text{a}, haha,\underline{\text{hah}}\text{a}, hahaha\underline{\text{hahah}}\text{a} and so on, yielding palindromic substrings of any odd length. Therefore the answer is infinite, so output Infinity\text{Infinity}.

Constraints

OvO

Translated by ChatGPT 5