Ensure that you are logged in and have the required permissions to access the test.
You are given a ternary string of length consisting of 0, 1, and 2. Your task is to determine the number of distinct permutations of for which satisfies the below condition:
Let be the permutation of , is valid if the count of all palindromic substrings (sizes from 1 to ) does not exceed .
Input format
Output format
Print lines. For each test case:
Constraints
The sum of the length of strings over all test cases does not exceed 200000.
First test case: All the permutations of this string are different and valid.
"012","021","102","120","210" and "201".
Second test case: Two permutations are valid.
"12012" and "21021"
In each of the above strings there are only 1 length palindromes, which is equal to length of string.