#include<bits/stdc++.h>
using namespace std;
int n,m;
string p, s;
int mynext[100010] = {0};
void build_mynext()
{
int len = n;
int i = 1, prefix_len = 0;
while(i < len)
{
if(p[i] == p[prefix_len])
{
++prefix_len;
mynext[i++] = prefix_len;
}
else
{
if(prefix_len == 0)
{
mynext[i] = 0;
++i;
}
else
{
prefix_len = mynext[prefix_len - 1];
}
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin>>n>>p>>m>>s;
build_mynext();
int lenp = n, lens = m, i = 0, j = 0;
while(i < lens)
{
if(p[j] == s[i])
{
++i, ++j;
}
else // 若字符串失配
{
if(j == 0) // 若子串第一位就失配
{
++i;
}
else
{
j = mynext[j - 1]; // 跳过前mynext[j-1]个字符
}
}
if(j == lenp) // 输出匹配子串第一位的位置
{
cout<<i-j<<' ';
}
}
return 0;
}