#P3900. Unbounded Palindromic Substring

    ID: 17148 Type: Default 1000ms 256MiB

Unbounded Palindromic Substring

Unbounded Palindromic Substring

Given a multiset \(S\) of strings (note that this multiset can contain duplicates). Initially, \(S\) contains \(n\) strings \(s_1, s_2, \dots, s_n\). You can perform the following two operations any number of times:

  1. Add to \(S\) any string that is already in \(S\>.
  2. Select any two strings from \(S\), concatenate them, and add the resulting string to \(S\).

After performing an arbitrary number of operations, consider every string in \(S\) and let \(L\) be the length of its longest palindromic substring. Determine the maximum possible value of \(L\) over all strings in \(S\). If \(L\) can be made arbitrarily large, output \(\text{Infinity}\).

A palindrome is a string that reads the same backward as forward.

inputFormat

The first line contains a single integer \(n\) \( (1 \le n \le 100)\), the number of strings in the initial multiset \(S\).

Each of the following \(n\) lines contains a non-empty string consisting of lowercase English letters. The lengths of the strings are at most 100.

outputFormat

If the maximum possible length of a palindromic substring in some string of \(S\) can be made arbitrarily large, output Infinity. Otherwise, output a single integer representing the maximum length of the longest palindromic substring among all strings in \(S\).

sample

2
abc
def
1

</p>