(RankList for this Question)
Kevin is an enthusiast and likes to explore new things. So, one day he was sitting and thought about what ternary strings are and learnt about them. Then he started exploring many such strings and wondered for any given ternary string K of length N consisting of 0, 1, and 2 Is it possible to determine the number of distinct permutations of K for which satisfies the below condition:
Let R be the permutation of K, R is valid if the count of all palindromic substrings (sizes from 1 to N) does not exceed N
The sum of the length of strings over all test cases does not exceed 200000.
The first line contains an integer denoting the number of test cases T
The first line of each test case contains a ternary string S
Print T lines. For each test case:
Print a single line indicating the number of ways to rearrange S such that the number of palindromes does not exceed N
First test case: All the permutations of this string are different and valid.
"012","021","102","120","210" and "201".
Log In to solve the Question