rt
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 5;
char s1[N], s2[N];//s1是母串 s2是模式串
ll nxt[N];
void build_nxt()
{
ll len = 0;
for (int i = 2; i <= strlen(s2 + 1); i++)
{
while (len and s2[i] != s2[len + 1])
len = nxt[len];
if (s2[len + 1] == s2[i])
len++;
nxt[i] = len;
}
return;
}
void KMP()
{
ll len = 0;
for (int i = 1; i <= strlen(s1 + 1); i++)
{
while (len > 0 and nxt[len + 1] != s1[i])
len = nxt[len];
if (s2[len + 1] == s1[i])
len++;
if (len == strlen(s2 + 1))
{
cout << i - strlen(s2 + 1) + 1 << '\n';
len = nxt[len];
}
}
for (int i = 1; i <= strlen(s2); i++)
cout << nxt[i] << ' ';
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> (s1 + 1);
cin >> (s2 + 1);
build_nxt();
KMP();
return 0;
}
/*
ABCABABCA
ABCABABCA
*/