Note: This is an approximate problem. There is no exact solution. You must find the most optimal solution. Please, take a look at the sample explanation to ensure that you understand the problem correctly.
Problem statement
You are given a string S of N length consisting of lowercase Latin characters (a - z). Your task is to decompose S into K consecutive non-empty substrings such that every character is present in only one substring.
For example, substrings are S[1],S[2],...,S[K]. Select an array B which is a permutation of 1 to K, that is, it is of size K and include every element from 1 to K.
Also, you can choose to keep each substring as it is or in reverse order.
Now, form a new string V=S[B[1]]+S[B[2]]+...+S[B[K]]. Suppose the number of palindromic substrings in V is X (of length greater than 1) and the number of substrings among S[1],S[2],...,S[K] which were not reversed are Y.
The aim is to maximize Z=X×(Y+1).
Input format
Output format
Verdict and scoring
Your score is equal to the sum of the values of all test files. The value of each test file is equal to the value of Z that you found.
If the decomposition of string S is invalid or array B is invalid, then you will receive a wrong answer verdict.
Constraints
N=1000
50≤K≤100
S[1]=ab is reversed so S[1]=ba.
S[2]=ab
V=S[B[1]]+S[B[2]]=S[1]+S[2]=ba+ab=baab
Number of substrings which are palindromic = 2
Number of substrings not reversed = 1
Z=2×(1+1)=4
Sample Test is for understanding purpose. Constraints in test files are as mentioned above.