Codeforces Global Round 26
D
"a" String Problem
Codeforces
2000
原题
← C2E →
翻译中…

You are given a string $s$ consisting of lowercase Latin characters. Count the number of nonempty strings $t \neq$ "$\texttt{a}$" such that it is possible to partition$^{\dagger}$ $s$ into some substrings satisfying the following conditions:

翻译中…
  • each substring either equals $t$ or "$\texttt{a}$", and
  • at least one substring equals $t$.
翻译中…

$^{\dagger}$ A partition of a string $s$ is an ordered sequence of some $k$ strings $t_1, t_2, \ldots, t_k$ (called substrings) such that $t_1 + t_2 + \ldots + t_k = s$, where $+$ represents the concatenation operation.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

翻译中…

The only line of each test case contains a string $s$ consisting of lowercase Latin characters ($2 \leq |s| \leq 2 \cdot 10^5$).

翻译中…

The sum of $|s|$ over all test cases does not exceed $3 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of nonempty strings $t \neq$ "$\texttt{a}$" that satisfy all constraints.

翻译中…

Note

翻译中…

In the first test case, $t$ can be "$\texttt{aa}$", "$\texttt{aaa}$", "$\texttt{aaaa}$", or the full string.

翻译中…

In the second test case, $t$ can be "$\texttt{b}$", "$\texttt{bab}$", "$\texttt{ba}$", or the full string.

翻译中…

In the third test case, the only such $t$ is the full string.

翻译中…

样例

Input #1
8
aaaaa
baba
cabacb
aaabaaa
bitset
ab
abbaaaabbb
yearnineteeneightyfour
Output #1
4
4
1
16
1
2
3
1
InputCopy OutputCopy
题目信息
题号
1984D
时间限制
2 s
内存限制
256 MB
标签
暴力
哈希
模拟
数学
后缀结构
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。