/*
Copyright 2012 Marek "p2004a" Rusinowski
Knuth-Morris-Pratt algorithm
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 1000000
int tab[MAXN], n, m;
char str[MAXN], pat[MAXN];
void kmp(const char *str, const char *pat, int str_len, int pat_len, bool (*callback)(int idx, void *data), void *data = NULL) {
int a, i, *tab = (int *) malloc(str_len * sizeof(int));
tab[0] = 0;
for (i = 1; i < pat_len; ++i) {
tab[i] = tab[i - 1];
while (tab[i] > 0 && pat[tab[i]] != pat[i]) {
tab[i] = tab[tab[i] - 1];
}
if (pat[tab[i]] == pat[i]) {
++tab[i];
}
}
for (a = 0, i = 0; i < str_len; ++i) {
while (a > 0 && pat[a] != str[i]) {
a = tab[a - 1];
}
if (pat[a] == str[i]) {
++a;
}
if (a == pat_len) {
a = tab[a - 1];
if (!callback(i - pat_len + 1, data)) {
break;
}
}
}
free(tab);
}
bool func(int a, void *) {
printf("%d\n", a);
return true;
}
int main() {
scanf("%d%d%s%s", &n, &m, str, pat);
kmp(str, pat, n, m, func);
return 0;
}
LyoKICBDb3B5cmlnaHQgMjAxMiBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgS251dGgtTW9ycmlzLVByYXR0IGFsZ29yaXRobQoqLyAKI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RyaW5nPgoKI2RlZmluZSBNQVhOIDEwMDAwMDAKCmludCB0YWJbTUFYTl0sIG4sIG07CmNoYXIgc3RyW01BWE5dLCBwYXRbTUFYTl07Cgp2b2lkIGttcChjb25zdCBjaGFyICpzdHIsIGNvbnN0IGNoYXIgKnBhdCwgaW50IHN0cl9sZW4sIGludCBwYXRfbGVuLCBib29sICgqY2FsbGJhY2spKGludCBpZHgsIHZvaWQgKmRhdGEpLCB2b2lkICpkYXRhID0gTlVMTCkgewogIGludCBhLCBpLCAqdGFiID0gKGludCAqKSBtYWxsb2Moc3RyX2xlbiAqIHNp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