| NUS CS3233 Final Team Contest 2025 |
|---|
| Finished |
SoCCat has a string $$$S$$$ consisting of lowercase English letters a to z. For their Final Year Project, SoCCat is interested in the so-called double string.
Formally, a string $$$T$$$ is a double string if and only if:
Help SoCCat count the number of pairs of indices $$$(i, j)$$$ such that $$$1 \leq i \lt j \leq |S|$$$ and the substring $$$S[i, j] = S_i S_{i+1} \dots S_{j}$$$ is a double string!
The input contains a string $$$S$$$ ($$$1 \leq |S| \leq 200\,000$$$) consisting of lowercase English letters a to z.
Output a single integer denoting the number of pairs of indices $$$(i, j)$$$ such that $$$1 \leq i \lt j \leq |S|$$$ and the substring $$$S[i, j]$$$ is a double string.
mississippi
5
aaaaa
6
soc
0
In the first sample, $$$S = \texttt{mississippi}$$$. All the substrings that are double strings are:
Thus, the answer is $$$5$$$.
In the second sample, $$$S = \texttt{aaaaa}$$$. All pairs of indices $$$(i, j)$$$ such that $$$j-i+1$$$ is even are double strings. Thus, the answer is $$$6$$$.
In the third sample, $$$S = \texttt{soc}$$$. There are no double strings in this case, so the answer is $$$0$$$.
| Name |
|---|


