You'll be given an array of strings containing lowercase English letters only and queries. In each query, you have to find the length of the longest palindromic substring which appears in at least strings and at most strings. If there is no such palindromic substring, print 0.
A palindrome is a word which reads the same backward and forward, such as “madam”, “abba” etc. A substring is a string of character(s) that is contained in another string. For example, “abc” has 6 substrings: “a”, “ab”, “abc”, “b”, “bc”, “c”.
A palindromic substring is a substring which reads the same backward and forward. For example, “taka” has 4 unique palindromic substrings: “t”, “a”, “k”, “aka”.
There will be multiple testcases. The first line of the input will contain an integer (), the number of testcases. The first line of each case will contain two integers () and (). Then each of the next lines will contain a string, -th line will contain the string (). Then the following lines will contain two integers each and (), as described in the statement.
Sum of length over all strings per case will be .
For each query, print 1 line, -th line is the answer to the -th query.
Input | Output |
---|---|
1 3 6 aaac aaabbbbbb abbaaa 1 1 1 2 1 3 2 2 2 3 3 3 | 6 6 6 2 3 3 |
Data set is huge, use faster I/O methods.