Power Strings
 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 48867 Accepted: 20366

Description

Given two strings a and b we define a*b to be their concatenation. For example, if a = “abc” and b = “def” then a*b = “abcdef”. If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = “” (the empty string) and a^(n+1) = a*(a^n).

Input

Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.

Output

For each s you should print the largest n such that s = a^n for some string a.

Sample Input

Sample Output

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

kmp：给定两个字符串如T,S求 S在T 中能否匹配能的话返回匹配的位置

• A段字符串是T的一个前缀。
• B段字符串是T的一个后缀。
• A段字符串和B段字符串相等。

### next数组计算

ababab  next[6] = 4; 即

ababab
ababab
1~4位  与2~6位是相同的

3、4位就等于5、6位
……