#include<bits/stdc++.h> usingnamespace std; #define maxn 100005 #define maxm 1005 #define ll long long ll ans=0; char S[maxn],S2[maxn],s[maxn+maxm],t[maxn+maxm]; char t1[maxm],t2[maxm]; int z1[maxn+maxm],z2[maxn+maxm]; inlinevoidgetz(int *z,int sz) { z[0]=sz; int j=1,k; for (int i=1;i<sz;i=k) { if (j<i) j=i; while (s[j-i]==s[j] && j<sz) j++; z[i]=j-i; k=i+1; while (k+z[k-i]<j) k++; }
} intmain() { cin>>S; int N=strlen(S); for (int j=0,cnt=N-1;cnt>=0;j++,cnt--) S2[j]=S[cnt]; int T; cin>>T; while (T--) { memset(z1,0,sizeof(z1));memset(z2,0,sizeof(z2)); cin>>t1; int M=strlen(t1); if (M<2 || M>N) continue; for (int j=0,cnt=M-1;cnt>=0;j++,cnt--) t2[j]=t1[cnt]; for (int i=0;i<M;i++) s[i]=t1[i]; s[M]='$'; for (int i=M+1,j=0;j<N;j++,i++) s[i]=S[j]; getz(z1,N+M+1); for (int i=0;i<M;i++) s[i]=t2[i]; s[M]='$'; for (int i=M+1,j=0;j<N;j++,i++) s[i]=S2[j]; getz(z2,N+M+1); for (int i=1;i<=N;i++) z1[i]=z1[i+M]; for (int i=1;i<=N;i++) z2[i]=z2[i+M]; z2[0]=0; for (int i=1;i<=N;i++) z2[i]=max(z2[i],z2[i-1]); for (int i=1;i<=N;i++){ if (z1[i]!=0) {int pos=z1[i]+i-1+(M-z1[i]); pos=N-pos+1; if (pos<1 || pos>N) continue; if (z2[pos]+z1[i]>=M) {ans++;break;} }}} cout<<ans<<endl; }