#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) (int)((x).size())
//#define int ll
//#define N
using namespace std;
void BellaKira()
{
string st;
cin>>st;
int n=sz(st);
poly g(n+1,0);
cout<<0<<" ";
for (int i=2,j=0;i<=n;i++)
{
while (j&&st[j]!=st[i-1]) j=g[j];
if (st[j]==st[i-1]) j++;
g[i]=j;
cout<<j<<" ";
}
cout<<'\n';
}
signed main()
{
IOS;
cin.tie(0);
int T=1;
while (T--)
{
BellaKira();
}
}