Palindrome Partition solution codeforces
A substring is a continuous and non-empty segment of letters from a given string, without any reorders.
An even palindrome is a string that reads the same backward as forward and has an even length. For example, strings “zz“, “abba“, “abccba” are even palindromes, but strings “codeforces“, “reality“, “aba“, “c” are not.
A beautiful string is an even palindrome or a string that can be partitioned into some smaller even palindromes.
You are given a string 𝑠�, consisting of 𝑛� lowercase Latin letters. Count the number of beautiful substrings of 𝑠�.
Each test contains multiple test cases. The first line contains the number of test cases 𝑡� (1≤𝑡≤1041≤�≤104). The description of the test cases follows.
The first line of each test case contains a single integer 𝑛� (1≤𝑛≤5⋅1051≤�≤5⋅105).
The second line of each test case contains a string 𝑠�. String 𝑠� consists of only lowercase Latin letters and has a length of 𝑛�.
It is guaranteed that the sum of 𝑛� over all test cases does not exceed 5⋅1055⋅105.
Palindrome Partition solution codeforces
For each test case print the number of beautiful substrings.
input
output
3 0 1 0 14 6
In the first test case, the beautiful substrings are “abaaba“, “baab“, “aa“.
In the last test case, the beautiful substrings are “aa” (counted twice), “abba“, “bb“, “bbaa“, “abbaaa“.