#include <iostream>
#include <string>
using namespace std;
const int maxn=1000005;
char A[maxn],B[maxn]; //main string A & model string B
int next[maxn];
int n,m; //the length of string A & string B
void Get_next(char *B,int next[])
{
next[1]=0;
int j=0;
for(int i=2;i<=m;i++)
{
while((j>0)&&(B[j+1]!=B[i]))
j=next[j];
if(B[j+1]==B[i])
j++;
next[i]=j;
}
}
void KMP()
{
int j=0;
for(int i=1;i<=n;i++)
{
while((j>0)&&(B[j+1]!=A[i]))
j=next[j];
if(B[j+1]==A[i])
j++;
if(j==m)
{
cout<<"match position: "<<i-m<<endl;
j=next[j];
}
}
}
int main()
{
while (cin>>A+1>>B+1)
{
n=strlen(A+1);
m=strlen(B+1);
cout<<"A="<<A+1<<" B="<<B+1<<endl;
Get_next(B,next);
for(int i=1;i<=m;i++)
cout<<"next["<<i<<"]="<<next[i]<<endl;
KMP();
}
}