| Game of Coders 5.0 | Finals Round |
|---|
| Finished |
Brook is trying to write a beautiful, soulful new song using a long string of lyrics $$$s$$$.
Robin reads over his sheet music and suggests cutting the lyric string into three specific non-empty parts A, B, and C such that $$$A + B + C = s$$$ to create an echoing effect so that:
A and B can overlap inside C. Different cuts are counted as completely different musical arrangements. Help Robin find the number of ways to cut the string so Brook can sing his song.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$) — the number of test cases.
Each test case has one line with a string $$$s$$$ ($$$3 \le |s| \le 2 \times 10^{5}$$$). It has lowercase letters.
It is guaranteed that the sum of the lengths of $$$s$$$ over all test cases does not exceed $$$2 \times 10^{5}$$$.
For each test case, output one integer — the number of ways to cut the string.
3aaaaaaaaaaabc
410
For $$$s = \texttt{aaaaaa}$$$, the valid splits are:
For $$$s = \texttt{aaaa}$$$, the valid split is $$$A = \texttt{a}$$$, $$$B = \texttt{a}$$$, and $$$C = \texttt{aa}$$$.
For $$$s = \texttt{abc}$$$, no split satisfies both conditions.
| Name |
|---|


