#Q48. 「一本通 2.2 练习 2」OKR-Periods of Words

「一本通 2.2 练习 2」OKR-Periods of Words

Description

Original source: POI 2006

A string is a finite sequence of lowercase letters. Specifically, an empty sequence can also be considered a string. A string PP is a prefix of string AA if and only if there exists a string BB such that A=PBA = PB. If PAP \not = A and PP is not an empty string, then we say PP is a proper prefix of AA.

We define QQ as a period of AA if and only if QQ is a proper prefix of AA and AA is a prefix of QQQQ (not necessarily a proper prefix). For example, the strings abab and ababab are both periods of the string abababa. The maximum period of string AA is its longest period or an empty string (when AA has no periods). For instance, the maximum period of ababab is abab, and the maximum period of abc is an empty string.

Given a string, calculate the sum of the lengths of the maximum periods for all its prefixes.

Input Format

The first line contains an integer kk, the length of the string.

The next line contains the given string.

Output Format

Output an integer representing the sum of the lengths of the maximum periods for all prefixes of the string.

Sample 1

8
babababa

24

Data Range and Hint

For all data, 1<k<1061 < k < 10^6.