String Strange Sum
Time limit4sMemory limit1024 MB
Given a lowercase string s, sum over all segments [l, r] with 2 <= l <= r <= |s| the longest suffix of s[1, l-1] that splits into prefixes of s[l, r].
- Level
Hard8 of 10
- Topics
- String matching, String, Dynamic programming
- Solved
- No attempts yet
Problem
You are given a string consisting of lowercase English letters.
Consider a segment such that . Let be the length of the longest suffix of that can be divided into prefixes of . If there is no such suffix, then .
Find the value of
Input
The first line contains a single integer (), the number of test cases. Each of the next lines contains a string () made of lowercase English letters. The sum of over all test cases does not exceed .
Output
For each test case, print a single integer, the answer to the problem.
Hint
Consider the third test case. Here , , , , , , , , , and . The answer is .