Description

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm:

Step1. Connect the father's name and the mother's name, to a new string S.
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).

Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:)

Input

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above.

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.

Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.

Sample Input

ababcababababcabab aaaaa

Sample Output

2 4 9 18 1 2 3 4 5

给你一个串T,找出串T的子串,该串既是T的前缀也是T的后缀。从小到大输出所有符合要求的串的长度。

看第一组样例,符合的串分别是  ab   abab   ababcabab ababcababababcabab

还是考察对next数组的理解,

首先要知道KMP的next[i]数组求得的数值就是串T中的[1,i-1]的后缀与串T中的[0,i-2]前缀的最大匹配长度。所以next[m](m为串长且串从0到m-1下标)的值就是与后缀匹配的最大前缀长度。

next[next[m]]也是一个与后缀匹配的前缀长度,,,依次类推即可。

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;
typedef long long ll;
typedef double ld;
const int MAXN=400000+1000;
char P[MAXN];
int len,next[MAXN];
void getFail()
{
next[0]=next[1]=0;
for(int i=1; i<len; i++)
{
int j=next[i];
while(j&&P[i]!=P[j])
j=next[j];
next[i+1] = (P[i]==P[j])?j+1:0;
}
}
int main()
{
while(scanf("%s",P)==1)
{
vector<int> ans;
len=strlen(P);
getFail();
ans.push_back(len);
int i=len;
while(next[i])
{
i=next[i];
ans.push_back(i);
}
for(int i=ans.size()-1; i>0; i--)
printf("%d ",ans[i]);
printf("%d\n",ans[0]);
}
return 0;
}