注:nextval[0] = -1
#include<iostream>
using namespace std;
void GetNextval(string &str, int nextval[]){
nextval[0]=-1;
int i = 0, j = -1;
while(i < str.size()-1){
if (j == -1 || str[i] == str[j]){
++i;
++j;
if(str[i]!=str[j]) nextval[i] = j;
else nextval[i] = nextval[j];
}
else j = nextval[j];
}
}
int main()
{
string str;
int nextval[100];
cin >> str;
GetNextval(str, nextval);
for(int i=0;i<str.size();i++){
cout<<nextval[i]<<" ";
}
return 0;
}