#include<bits/stdc++.h>
using namespace std;
void getNext(string s,int next[]){
int i=1,j=0;
next[1]=0;
while(i<s.size()){
if(j==0||s[i-1]==s[j-1]){
i++;
j++;
next[i]=j;
}
else j=next[j];
}
}
int kmp(string t,string s,int next[]){
int i=1,j=1;
while(i<=s.size()&&j<=t.size()){
if(j==0||s[i-1]==t[j-1]){
i++;
j++;
}
else j=next[j];
}
if(j>t.size())return i-t.size();
else return 0;
}
int main(){
string s,t;
cin>>s>>t;
int next[t.size()+1];
getNext(t,next);
cout<<kmp(t,s,next);
}

京公网安备 11010502036488号