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
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define MAXN 400001
typedef long long LL;
/*
真正理解Next[]数组的含义
Next[j] = k的含义是
在数组里0-k的前缀和k-j+1-k的后缀相同,k是前j-1个元素里最大的相同前缀后缀长度 那么题目要求求出所有相同前缀后缀长度,显然字符串总长度是一个解
由Next[]数组的定义,Next[len]也是一个解(如果有解)——如果Next[len]==0显然说明无解
那么通过递归的思想继续求更小的解:由于Next[len]==k那么说明 其他解如果存在 只能在[0,k]和
[len-k+1,len]中产生,而由于他们完全相同可以只考虑其中一个,比如[0,k]
此时问题的形式是求一个序列所有前缀后缀 所以可以递归求解
*/
char s[MAXN];
int Next[MAXN];
void kmp_pre(int m)
{
int j,k;
j = ;k = Next[] = -;
while(j<m)
{
if(k==-||s[j]==s[k])
Next[++j] = ++k;
else
k = Next[k];
}
}
void Print(int tmp)
{
if(Next[tmp])
{
Print(Next[tmp]);
printf("%d ",Next[tmp]);
}
}
int main()
{
while(scanf("%s",s)!=EOF)
{
int l = strlen(s);
kmp_pre(l);
int tmp = l;
Print(tmp);
printf("%d\n",l);
}
}

最新文章

  1. Swift开发第十一篇——Designated、Convenience和Required
  2. iOS &#39;The sandbox is not sync with the Podfile.lock错误
  3. IOS第七天(4:UiTableView 数据的显示优化重复实例和tableFooterView和tableHeaderView)
  4. Eclipse快捷键,前几个很实用
  5. 掌握numpy(四)
  6. python 多线程批量传文件
  7. MFC学习问题总结
  8. Jenkins - ERROR: Exception when publishing, exception message [Failure] Build step &#39;Send build artifacts over SSH&#39; changed build result to UNSTABLE
  9. Java基础知识总结--多态
  10. [skill][msgpack] 初试msgpack库以及基本使用
  11. GameObject.Find与Transform.Find的区别
  12. (转载)西门子PLC学习笔记十五-(数据块及数据访问方式)
  13. ArcGIS中的数据连接问题——数据类型不统一
  14. Spring Boot Mvc 单元测试
  15. 【html】优酷视频去广告代码
  16. Java面向对象程序设计
  17. 微信小程序 - 上拉加载下拉刷新
  18. import 如何工作
  19. JAVA学习笔记--匿名内部类
  20. cacti安装和使用

热门文章

  1. Web开发必须知道的知识点
  2. selenium3 + python - 异常处理截图 screenshot
  3. SpringCloud服务组合
  4. 【TIDB】1、TiDb简介
  5. 拼接html 的事件转义
  6. 最少拦截系统------LCS--------动态规划
  7. 涨知识-VI 基于TCP/UDP的应用层协议
  8. [Codeforces]Codeforces Round #490 (Div. 3)
  9. css每次的初始化代码
  10. STL之string篇