Codeforces Round 846 (Div. 2)
G
Delicious Dessert
Codeforces
2400
原题
← F→
翻译中…

Today is an important day for chef Tonio — an auditor has arrived in his hometown of Morioh. He has also arrived at Tonio's restaurant and ordered dessert. Tonio has not been prepared for this turn of events.

翻译中…

As you know, dessert is a string of lowercase English letters. Tonio remembered the rule of desserts — a string $s$ of length $n$. Any dessert $t$ is delicious if the number of occurrences of $t$ in $s$ as a substring is divisible by the length of $t$.

翻译中…

Now Tonio wants to know the number of delicious substrings of $s$. If the substring occurs several times in the string $s$, then all occurrences must be taken into account.

翻译中…

Input

翻译中…

The first line contains an integer $n$ ($1 \leq n \leq 10^6$) — the length of the rule $s$.

翻译中…

The second line contains the string $s$ of length $n$ — the rule. The rule consists only of lowercase English letters.

翻译中…

Output

翻译中…

In a single line print the number of delicious substrings of $s$.

翻译中…

Note

翻译中…

In the first sample, there are many delicious substrings. $7$ of them are substrings of length $1$ (because any number is divisible by $1$). Consider other delicious substrings:

翻译中…
  • "ab" occurs in $s$ $2$ times, which is divisible by the length of the substring.
  • "ba" also occurs $2$ times.
翻译中…

Therefore, the answer is $7 + 2 + 2 = 11$.

翻译中…

Note that the answer includes both occurrences of "ab" and "ba".

翻译中…

样例

Input #1
7
abacaba
Output #1
11
InputCopy OutputCopy
Input #2
8
abaababa
Output #2
11
InputCopy OutputCopy
Input #3
10
deadinside
Output #3
12
InputCopy OutputCopy
Input #4
5
aaaaa
Output #4
12
InputCopy OutputCopy
题目信息
题号
1780G
时间限制
3 s
内存限制
512 MB
标签
二分
并查集
哈希
数学
数论
后缀结构

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