QOJ.ac

QOJ

Time Limit: 6.5 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#9244. Counting Strings

Statistics

Given a string $s$ of length $n$.

We say that a string $t$ is mentioned in $s$ if and only if there exist integers $l, r$, satisfying $1 \le l \le r \le n$, $\gcd(l, r) = 1$ and $s[l, r] = t$.

Here, $s[l, r]$ is defined as the string that is made by concatenating $s_l, s_{l+1}, \dots, s_r$, and $\gcd(l, r)$ represents the greatest common divisor of $l$ and $r$.

You should calculate the sum of the lengths of all distinct non-empty strings that are mentioned in $s$.

Input

The first line of the input contains the integer $n$ ($1 \le n \le 100000$).

The second line contains the string $s$, consisting of only lowercase English letters.

Output

Print the sum of the lengths of all distinct non-empty strings that are mentioned on a single line.

Examples

Input 1

4
abca

Output 1

14

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.