#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
char n[100015];
char m[105][1005];
char n2[100015],m2[1005];
int k;
int p[1005];
int chu1[1006];
void huhuan(char *n,char *hu,int len1)
{
	int jia=0;
	for(int i=len1-1;i>=0;i--)
	{
		hu[jia++]=n[i];
	}
	hu[jia]='\0';
}
void getps(char *n)
{
   int j;
   int len=strlen(n);
   p[0]=0;p[1]=0;
   for(int i=1;i<len;i++)
   {
   	j=p[i];
   	while(j&&n[i]!=n[j]) j=p[j];
   	p[i+1]= n[i]==n[j]?j+1:0;
   }
}
int kmp(char *m,int len)
{
   memset(chu1,-1,sizeof(chu1));
   getps(m);
   int lenm=strlen(m);
   int j=0;
   for(int i=0;i<len;i++)
   {
   	while(j&&n[i]!=m[j]) j=p[j];
   	if(n[i]==m[j]) {
	   j++;
   	if(chu1[j]==-1) {
   		chu1[j]=i;
	   }
      }
	  if(j==lenm)  return 1;
   }
   huhuan(m,m2,lenm);
   getps(m2);j=0;
   int maxx=0;
   for(int i=0;i<len-1;i++)
   {
     while(j&&n2[i]!=m2[j]) j=p[j];
     if(n2[i]==m2[j])
	 {
	 j++;
	 if(lenm-j>=0&&chu1[lenm-j]!=-1)
	 {
	 	if(chu1[lenm-j]<len-1-i)
	 	{
	 		return 1;
		 }
	  }
     }
     if(j==lenm) break;
    }
   return 0;
}
int main()
{
   while(scanf("%s",n)==1)
   {
      int lenn=strlen(n);
      scanf("%d",&k);
      huhuan(n,n2,lenn);
      for(int i=0;i<k;i++)
      {
      	scanf("%s",m[i]);
      }
      int co=0;
     for(int i=0;i<k;i++)
     {
     	int u=strlen(m[i]);
     	if(u>lenn) continue;
     	if(kmp(m[i],lenn)) co++;
     }
     printf("%d\n",co);
   }
   return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
char n[100015];
char m[105][1005];
char n2[100015],m2[1005];
int k;
int p[1005];
int chu1[1006];
void huhuan(char *n,char *hu,int len1)
{
	int jia=0;
	for(int i=len1-1;i>=0;i--)
	{
		hu[jia++]=n[i];
	}
	hu[jia]='\0';
}
void getps(char *n)
{
   int j;
   int len=strlen(n);
   p[0]=0;p[1]=0;
   for(int i=1;i<len;i++)
   {
   	j=p[i];
   	while(j&&n[i]!=n[j]) j=p[j];
   	p[i+1]= n[i]==n[j]?j+1:0;
   }
}
int kmp(char *m,int len)
{
   memset(chu1,-1,sizeof(chu1));
   getps(m);
   int lenm=strlen(m);
   int j=0;
   for(int i=0;i<len;i++)
   {
   	while(j&&n[i]!=m[j]) j=p[j];
   	if(n[i]==m[j]) j++;
   	if(chu1[j]==-1) {
   		chu1[j]=i;
	   }
   	if(j==lenm) return 1;
   }
   huhuan(m,m2,lenm);
   getps(m2);j=0;
   int maxx=0;
   for(int i=0;i<len-1;i++)
   {
     while(j&&n2[i]!=m2[j]) j=p[j];
     if(n2[i]==m2[j])
	 {
	 j++;
	 if(lenm-j>=0&&chu1[lenm-j]!=-1)
	 {
	 	if(chu1[lenm-j]<len-1-i)
	 	{
	 		return 1;
		 }
	  }
     }
     //if(j==lenm) break;
    }
   return 0;
}
int main()
{
   while(scanf("%s",n)==1)
   {
      int lenn=strlen(n);
      scanf("%d",&k);
      huhuan(n,n2,lenn);
      for(int i=0;i<k;i++)
      {
      	scanf("%s",m[i]);
      }
      int co=0;
     for(int i=0;i<k;i++)
     {
     	int u=strlen(m[i]);
     	if(u>lenn) continue;
     	if(kmp(m[i],lenn)) co++;
     }
     printf("%d\n",co);
   }
   return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<string>
#include<list>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 1005
char s[maxn],T[maxn*100];
int f[maxn],p[maxn],ans;
void GetF()
{
    int j,len=strlen(s);
    f[0]=j=-1;
    for(int i=1;i<len;i++)
    {
        while(j>=0&&s[j+1]!=s[i]) j=f[j];
        if(s[j+1]==s[i]) j++;
        f[i]=j;
    }
}
void find(int d)
{
    int j=-1,lent=strlen(T),lens=strlen(s);
    for(int i=0;i<lent;i++)
    {
        while(j>=0&&s[j+1]!=T[i]) j=f[j];
        if(s[j+1]==T[i])
        {
            j++;
            if(!d&&p[j]==-1) p[j]=i;
            if(d)
            {
                if(lens-j-2>=0&&p[lens-j-2]!=-1)
                {
                    if(p[lens-j-2]<lent-i-1)
                    {
                        ans++;
                        break;
                    }
                }
            }
        }
        if(!d&&j+1==lens) break;
    }
}
int main()
{
    int n;
    scanf("%s",T);
    scanf("%d",&n);
    ans=0;
    for(int i=0;i<n;i++)
    {
        memset(p,-1,sizeof(p));
        scanf("%s",s);
        GetF();
        find(0);
        reverse(s,s+strlen(s));
        reverse(T,T+strlen(T));
        GetF();
        find(1);
        reverse(T,T+strlen(T));
    }
    printf("%d\n",ans);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		/*for(j=0;j<N;j++)
			printf("%d ",K1[j]);
		printf("\n");
		for(j=0;j<N;j++)
			printf("%d ",K2[j]);
		printf("\n");*/
		for(j=0;j<(N-1)/2;j++)
			if(K1[j]+K2[j]>=str.size())
			{
				res++;
				break;
			}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		//if(j==N) j--;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	int m1=0,m2=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		m1=0;m2=0;
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		/*for(j=0;j<N;j++)
			printf("%d ",K1[j]);
		printf("\n");
		for(j=0;j<N;j++)
			printf("%d ",K2[j]);
		printf("\n");*/
		for(j=0;j<=(N-1)/2;j++)
		{
			m1=max(m1,K1[j]);
			m2=max(m2,K2[j]);
			if(m1+m2>=str.size())
			{
				res++;
				break;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		if(j==N) j--;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	int m1=0,m2=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		m1=0;m2=0;
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		/*for(j=0;j<N;j++)
			printf("%d ",K1[j]);
		printf("\n");
		for(j=0;j<N;j++)
			printf("%d ",K2[j]);
		printf("\n");*/
		/*if(N&1)
		{
		}*/
		for(j=0;j<N/2;j++)
		{
			m1=max(m1,K1[j]);
			m2=max(m2,K2[j]);
			if(m1+m2>=str.size())
			{
				res++;
				break;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		for(j=0;j<N;j++)
			if(K1[j]+K2[N-j-1]>=str.size())
			{
				res++;
				break;
			}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		if(j==N) j--;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	int m1=0,m2=0;
	int s1=0,s2=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		m1=0;m2=0;
		s1=0;s2=0;
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		//cout << S1 << endl << str << endl;
		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		for(j=1;j<N;j++)
			K1[j]=max(K1[j],K1[j-1]);
		for(j=1;j<N;j++)
			K2[j]=max(K2[j],K2[j-1]);
		for(j=0;j<N;j++)
			if(K1[j]+K2[N-j-1] >= str.size())
			{
				res++;
				break;
			}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#define MAXN 100000
using namespace std;
string S;
string str;
int N,M;
int T;
int R;
int A[MAXN+1];
int K[MAXN+1];
void preKMP()
{
	int i,j=-1;
	for(i=0;i<=N;i++)
		A[i]=0;
	i=0;
	A[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
		{
				j=A[j];
		}
		i++; j++;
		A[i]=j;
	}
}
int KMP()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j])
			j=A[j];
		i++; j++;
		if(R) K[i]+=j;
		else K[M-i+1]+=j;
		if(K[i]>=N) return 1;
		if(K[N-i+1]>=N) return 1;
		if(j==N) return 1;
		if(i==M) return 0;
	}
}
int main()
{
	int i,j;
	int res=0;
	cin >> S;
	M=S.size();
	cin >> T;
	for(i=1;i<=T;i++)
	{
		cin >> str;
		N=str.size();
		if(N>M) continue;
		R=1;
		preKMP();
		KMP();
		reverse(S.begin(),S.end());
		reverse(str.begin(),str.end());
		R=0;
		preKMP();
		if(KMP()) res++;
		for(j=0;j<=M;j++)
			K[j]=0;
		reverse(S.begin(),S.end());
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#define MAXN 100000
using namespace std;
string S;
string str;
int N,M;
int T;
int R;
int A[MAXN+1];
int K[MAXN+1];
void preKMP()
{
	int i,j=-1;
	for(i=0;i<=N;i++)
		A[i]=0;
	i=0;
	A[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
		{
				j=A[j];
		}
		i++; j++;
		A[i]=j;
	}
}
int KMP()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j])
			j=A[j];
		i++; j++;
		if(R) K[i]+=j;
		else K[M-i+1]+=j;
		if(K[i]>=N) return 1;
		//if(K[M-i+1]>=N) return 1;
		if(j==N) return 1;
		if(i==M) return 0;
	}
}
int main()
{
	int i,j;
	int res=0;
	cin >> S;
	M=S.size();
	cin >> T;
	for(i=1;i<=T;i++)
	{
		cin >> str;
		N=str.size();
		if(N>M) continue;
		//R=1;
		preKMP();
		KMP();
		reverse(S.begin(),S.end());
		reverse(str.begin(),str.end());
		//R=0;
		preKMP();
		if(KMP()) res++;
		for(j=0;j<=M;j++)
			K[j]=0;
		reverse(S.begin(),S.end());
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#define MAXN 100000
using namespace std;
string S;
string str;
int N,M;
int T;
int R;
int A[MAXN+1];
int K[MAXN+1];
void preKMP()
{
	int i,j=-1;
	for(i=0;i<=N;i++)
		A[i]=0;
	i=0;
	A[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
		{
				j=A[j];
		}
		i++; j++;
		A[i]=j;
	}
}
int KMP()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j])
			j=A[j];
		i++; j++;
		if(R) K[i]+=j;
		else K[M-i+1]+=j;
		if(K[i]>=N) return 1;
		if(K[N-i+1]>=N) return 1;
		if(j==N) return 1;
		if(i==M) return 0;
	}
}
int main()
{
	int i,j;
	int res=0;
	cin >> S;
	M=S.size();
	cin >> T;
	for(i=1;i<=T;i++)
	{
		cin >> str;
		N=str.size();
		if(N>M) continue;
		//R=1;
		preKMP();
		KMP();
		reverse(S.begin(),S.end());
		reverse(str.begin(),str.end());
		//R=0;
		preKMP();
		if(KMP()) res++;
		for(j=0;j<=M;j++)
			K[j]=0;
		reverse(S.begin(),S.end());
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#define MAXN 100000
using namespace std;
string S;
string str;
int N,M;
int T;
int R;
int A[MAXN+1];
int K[MAXN+1];
void preKMP()
{
	int i,j=-1;
	for(i=0;i<=N;i++)
		A[i]=0;
	i=0;
	A[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
		{
				j=A[j];
		}
		i++; j++;
		A[i]=j;
	}
}
int KMP()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j])
			j=A[j];
		i++; j++;
		if(R) K[i]+=j;
		else K[M-i+1]+=j;
		if(K[i]>=N) return 1;
		//if(K[M-i+1]>=N) return 1;
		if(j==N) return 1;
		if(i==M) return 0;
	}
}
int main()
{
	int i,j;
	int res=0;
	cin >> S;
	M=S.size();
	cin >> T;
	for(i=1;i<=T;i++)
	{
		cin >> str;
		N=str.size();
		if(N>M || N==1) continue;
		//R=1;
		preKMP();
		KMP();
		reverse(S.begin(),S.end());
		reverse(str.begin(),str.end());
		//R=0;
		preKMP();
		if(KMP()) res++;
		for(j=0;j<=M;j++)
			K[j]=0;
		reverse(S.begin(),S.end());
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		if(j==N) j--;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	int m1=0,m2=0;
	int s1=0,s2=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		m1=0;m2=0;
		s1=0;s2=0;
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		//cout << S1 << endl << str << endl;
		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		for(j=1;j<N;j++)
			K1[j]=max(K1[j],K1[j-1]);
		for(j=1;j<N;j++)
			K2[j]=max(K2[j],K2[j-1]);
		for(j=0;j<N-1;j++)
			if(K1[j]+K2[N-j-2] >= str.size())
			{
				res++;
				break;
			}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		if(j==N) j--;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	int m1=0,m2=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		m1=0;m2=0;
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		/*for(j=0;j<N;j++)
			printf("%d ",K1[j]);
		printf("\n");
		for(j=0;j<N;j++)
			printf("%d ",K2[j]);
		printf("\n");*/
		for(j=0;j<=(N-1)/2;j++)
		{
			m1=max(m1,K1[j]);
			m2=max(m2,K2[j]);
			if(m1+m2>=str.size())
			{
				res++;
				break;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#define MAXN 100000
using namespace std;
string S;
string str;
int N,M;
int T;
int R;
int A[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP()
{
	int i,j=-1;
	for(i=0;i<=N;i++)
		A[i]=0;
	i=0;
	A[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
		{
				j=A[j];
		}
		i++; j++;
		A[i]=j;
	}
}
int KMP()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j]) j=A[j];
		i++; j++;
		if(i==M) return 0;
		if(j==N) j=0;
		K1[i]=j;
	}
}
int KMP2()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j]) j=A[j];
		i++; j++;
		if(i==M) return 0;
		if(j==N) j=0;
		K2[i]=j;
	}
}
int main()
{
	int i,j;
	int res=0;
	int flag;
	cin >> S;
	M=S.size();
	cin >> T;
	for(i=1;i<=T;i++)
	{
		cin >> str;
		N=str.size();
		if(N>M || N==1) continue;

		preKMP();
		KMP();

		reverse(S.begin(),S.end());
		reverse(str.begin(),str.end());

		preKMP();
		KMP2();
		flag=0;
		for(j=0;j<=M;j++)
		{
			if(K1[j]+K2[j] >=N) flag=1;
			K1[j]=K2[j]=0;
		}
		res+=flag;
		reverse(S.begin(),S.end());
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		for(i=0;i<N;i++)
			if(K1[i]+K2[N-i-1]>=str.size())
			{
				res++;
				continue;
			}
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#define MAXN 100000
using namespace std;
string S;
string str;
int N,M;
int T;
int R;
int A[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP()
{
	int i,j=-1;
	for(i=0;i<=N;i++)
		A[i]=0;
	i=0;
	A[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
		{
				j=A[j];
		}
		i++; j++;
		A[i]=j;
	}
}
int KMP()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j]) j=A[j];
		i++; j++;
		if(i==M) return 0;
		K1[i]=j;
		if(j==N) return 0;
	}
}
int KMP2()
{
	int i=0,j=0;
	while(true)
	{
		while(j>=0 && S[i]!=str[j]) j=A[j];
		i++; j++;
		if(i==M) return 0;
		K2[i]=j;
		if(j==N) return 0;
	}
}
int main()
{
	int i,j;
	int res=0;
	int flag;
	cin >> S;
	M=S.size();
	cin >> T;
	for(i=1;i<=T;i++)
	{
		cin >> str;
		N=str.size();
		if(N>M || N==1) continue;

		preKMP();
		KMP();

		reverse(S.begin(),S.end());
		reverse(str.begin(),str.end());

		preKMP();
		KMP2();

		flag=0;
		for(j=0;j<=M;j++)
		{
			if(K1[j]+K2[M-j+1] >=N) flag=1;
			K1[j]=K2[j]=0;
		}
		//if(flag) printf("YES!!!!\n");
		res+=flag;
		reverse(S.begin(),S.end());
	}
	printf("%d\n",res);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAXN 100000
using namespace std;
int F[MAXN+1];
int K1[MAXN+1];
int K2[MAXN+1];
void preKMP(string str)
{
	int N=str.size();
	int i=0,j=-1;
	F[i]=j;
	while(i<N)
	{
		while(j>=0 && str[i]!=str[j])
			j=F[j];
		i++; j++;
		F[i]=j;
	}
}
void KMP(string text,string str,int *s)
{
	int i=0,j=0;
	int N,M;
	M=text.size();
	N=str.size();
	while(i<M)
	{
		while(j>=0 && text[i]!=str[j])
			j=F[j];
		i++; j++;
		if(j==N) j--;
		*(s+i-1)=j;
	}
}
int main()
{
	int i,j,N,M;
	int res=0;
	int m1=0,m2=0;
	int s1=0,s2=0;
	string str,S1,S2;
	cin >> S2;
	S1=S2;
	reverse(S2.begin(),S2.end());
	N=S1.size();
	scanf(" %d",&M);

	for(i=1;i<=M;i++)
	{
		m1=0;m2=0;
		s1=0;s2=0;
		for(j=0;j<=N;j++)
			K1[j]=K2[j]=0;
		cin >> str;

		if(str.size()==1) continue;

		preKMP(str);
		KMP(S1,str,&K1[0]);

		reverse(str.begin(),str.end());
		preKMP(str);
		KMP(S2,str,&K2[0]);
		/*for(j=0;j<N;j++)
			printf("%d ",K1[j]);
		printf("\n");
		for(j=0;j<N;j++)
			printf("%d ",K2[j]);
		printf("\n");*/
		/*if(N&1)
		{
		}*/
		for(j=0;j<N/2;j++)
			m1=max(m1,K1[j]);
		for(j=0;j<N/2;j++)
			m2=max(m2,K2[j]);
		if(m1+m2>=str.size())
		{
			res++;
			continue;
		}
		if(N&1)
		{
			if(K1[N/2] > m1 && K1[N/2]+m2 >= str.size()) res++;
			else if(K2[N/2] > m2 && K2[N/2]+m1 >= str.size()) res++;
		}
	}
	printf("%d\n",res);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define M 104000
char str2[M];
int next[1000];
int v[2][M];
void GetNext(char st2[]){
    int len = strlen(st2);
    int i = 0,j = -1;
    next[0]=-1;
    while(i < len){
        if(j == -1||st2[i] == st2[j]){
            i++;
            j++;
            next[i] = j;
        }else{
            j = next[j];
        }
    }
}

bool KMP(char st1[],char st2[]){
    int len1 = strlen(st1);
    int len2 = strlen(st2);
    GetNext(st2);
    int i = 0, j = 0;//cout<<st1<<'\n'<<st2<<endl;
    while(i < len1&&j < len2){
        if(j == -1||st1[i] == st2[j]){
            if(j!=-1){
                v[0][i]=j+1;
                //cout<<i<<"  "<<j+1<<endl;
            }
            i++;
            j++;
        }else{
            j = next[j];
        }
    }
    if(j == len2){
        return true;
    }
    for(i=0,j=len1-1;i<len1;i++,j--)
        str2[i]=st1[j];
    str2[len1]='\0';
    char str1[1050];
    for(i=0,j=len2-1;i<len2;i++,j--){
        str1[i]=st2[j];
    }
    str1[len2]='\0';
    GetNext(str1);
    i=0,j=0;//cout<<str2<<'\n'<<str1<<endl;
    while(i<len1&&j<len2){
        if(j==-1||str2[i]==str1[j]){
            if(j!=-1){
                v[1][i]=j+1;
                //cout<<i<<"  "<<j+1<<endl;
            }
            i++;
            j++;
        }else{
            j=next[j];
        }
    }
    int minn=0;
    int maxn=0;
    for(i=0;i<len1;i++){
        if(minn<v[0][i])
            minn=v[0][i];
        else
            v[0][i]=minn;
        if(maxn<v[1][i])
            maxn=v[1][i];
        else
            v[1][i]=maxn;
    }
    for(i=0;i<len1;i++){
        if(v[0][i]+v[1][len1-1-i]>=len2)
            return true;
    }
    return false;
}

char str[M];

int ans;

int main(){
    int m;
    ans=0;
    scanf("%s",str);
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        char st[1050];
        scanf("%s",st);
        if(strlen(st)<=1){
            continue;
        }
        if(KMP(str,st)==true){//cout<<st<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

/*
BBABAABAABBBBAB
10
BBABAABAABBA
A
BBAA
AAAABB
AA
AABB
ABBBBABAABA
ABB
AAABABBAAABAAAA
BABAA

*/


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define M 104000
char str2[M];
int next[1000];
int v[2][M];
void GetNext(char st2[]){
    int len = strlen(st2);
    int i = 0,j = -1;
    next[0]=-1;
    while(i < len){
        if(j == -1||st2[i] == st2[j]){
            i++;
            j++;
            next[i] = j;
        }else{
            j = next[j];
        }
    }
}

bool KMP(char st1[],char st2[]){
    int len1 = strlen(st1);
    int len2 = strlen(st2);
    int i = 0, j = -1;
    while(i < len1&&j < len2){
        if(j == -1||st1[i] == st2[j]){
            if(j!=-1){
                v[0][i]=j+1;
            }
            i++;
            j++;
        }else{
            v[0][i-1]=j;
            j = next[j];
        }
    }
    if(j == len2){
        return true;
    }
    for(i=0,j=len1-1;i<len1;i++,j--)
        str2[i]=st1[j];
    char str1[1050];
    for(i=0,j=len2-1;i<len2;i++,j--){
        str1[i]=st2[j];
    }
    GetNext(str1);
    i=0,j=-1;
    while(i<len1&&j<len2){
        if(j==-1||str2[i]==str1[j]){
            if(j!=-1)
                v[1][i]=j+1;
            i++;
            j++;
        }else{
            v[1][i-1]=j;
            j=next[j];
        }
    }
    int minn=0;
    int maxn=0;
    for(i=0;i<len1;i++){
        if(minn<v[0][i])
            minn=v[0][i];
        else
            v[0][i]=minn;
        if(maxn<v[1][i])
            maxn=v[1][i];
        else
            v[1][i]=maxn;
    }
    for(i=0;i<len1;i++){
        if(v[0][i]+v[1][len1-1-i]==len2)
            return true;
    }
    return false;
}

char str[M];
char st[1050];
int ans;

int main(){
    int m;
    ans=0;
    scanf("%s",str);
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%s",st);
        if(strlen(st)<=1){
            continue;
        }
        GetNext(st);
        if(KMP(str,st)==true){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

/*
ABCBABA
2
BAAB
ABBA

*/


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define M 104000
char str2[M];
int next[1000];
int v[2][M];
void GetNext(char st2[]){
    int len = strlen(st2);
    int i = 0,j = -1;
    next[0]=-1;
    while(i < len){
        if(j == -1||st2[i] == st2[j]){
            i++;
            j++;
            next[i] = j;
        }else{
            j = next[j];
        }
    }
}

bool KMP(char st1[],char st2[]){
    int len1 = strlen(st1);
    int len2 = strlen(st2);
    int i = 0, j = -1;
    while(i < len1&&j < len2){
        if(j == -1||st1[i] == st2[j]){
            if(j!=-1){
                v[0][i]=j+1;
            }
            i++;
            j++;
        }else{
            v[0][i-1]=j;
            j = next[j];
        }
    }
    if(j == len2){
        return true;
    }
    for(i=0,j=len1-1;i<len1;i++,j--)
        str2[i]=st1[j];
    char str1[1050];
    for(i=0,j=len2-1;i<len2;i++,j--){
        str1[i]=st2[j];
    }
    GetNext(str1);
    i=0,j=-1;
    while(i<len1&&j<len2){
        if(j==-1||str2[i]==str1[j]){
            if(j!=-1)
                v[1][i]=j+1;
            i++;
            j++;
        }else{
            v[1][i-1]=j;
            j=next[j];
        }
    }
    int minn=0;
    int maxn=0;
    for(i=0;i<len1;i++){
        if(minn<v[0][i])
            minn=v[0][i];
        else
            v[0][i]=minn;
        if(maxn<v[1][i])
            maxn=v[1][i];
        else
            v[1][i]=maxn;
    }
    for(i=0;i<len1;i++){
        if(v[0][i]+v[1][len1-1-i]==len2)
            return true;
    }
    return false;
}

char str[M];
char st[1050];
int ans;

int main(){
    int m;
    ans=0;
    scanf("%s",str);
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%s",st);
        GetNext(st);
        if(KMP(str,st)==true){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

/*
ABCBABA
2
BAAB
ABBA

*/


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define M 104000
char str2[M];
int next[1000];
int v[2][M];
void GetNext(char st2[]){
    int len = strlen(st2);
    int i = 0,j = -1;
    next[0]=-1;
    while(i < len){
        if(j == -1||st2[i] == st2[j]){
            i++;
            j++;
            next[i] = j;
        }else{
            j = next[j];
        }
    }
}

bool KMP(char st1[],char st2[]){
    int len1 = strlen(st1);
    int len2 = strlen(st2);
    GetNext(st2);
    int i = 0, j = 0;//cout<<st1<<'\n'<<st2<<endl;
    while(i < len1&&j < len2){
        if(j == -1||st1[i] == st2[j]){
            if(j!=-1){
                v[0][i]=j+1;
                //cout<<i<<"  "<<j+1<<endl;
            }
            i++;
            j++;
        }else{
            j = next[j];
        }
    }
    if(j == len2){
        return true;
    }
    for(i=0,j=len1-1;i<len1;i++,j--)
        str2[i]=st1[j];
    str2[len1]='\0';
    char str1[1050];
    for(i=0,j=len2-1;i<len2;i++,j--){
        str1[i]=st2[j];
    }
    str1[len2]='\0';
    GetNext(str1);
    i=0,j=0;//cout<<str2<<'\n'<<str1<<endl;
    while(i<len1&&j<len2){
        if(j==-1||str2[i]==str1[j]){
            if(j!=-1){
                v[1][i]=j+1;
                //cout<<i<<"  "<<j+1<<endl;
            }
            i++;
            j++;
        }else{
            j=next[j];
        }
    }
    int minn=0;
    int maxn=0;
    for(i=0;i<len1;i++){
        if(minn<v[0][i])
            minn=v[0][i];
        else
            v[0][i]=minn;
        if(maxn<v[1][i])
            maxn=v[1][i];
        else
            v[1][i]=maxn;
    }
    for(i=0;i<len1;i++){
        if(v[0][i]+v[1][len1-2-i]>=len2)
            return true;
    }
    return false;
}

char str[M];
int ans;

int main(){
    int m;
    ans=0;
    scanf("%s",str);
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        char st[1050];
        scanf("%s",st);
        if(strlen(st)<=1){
            continue;
        }
        if(KMP(str,st)==true){//cout<<st<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

/*
BBABAABAABBBBAB
10
BBABAABAABBA
A
BBAA
AAAABB
AA
AABB
ABBBBABAABA
ABB
AAABABBAAABAAAA
BABAA

*/


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define M 104000
char str2[M];
int next[1000];
int v[2][M];
void GetNext(char st2[]){
    int len = strlen(st2);
    int i = 0,j = -1;
    next[0]=-1;
    while(i < len){
        if(j == -1||st2[i] == st2[j]){
            i++;
            j++;
            next[i] = j;
        }else{
            j = next[j];
        }
    }
}

bool KMP(char st1[],char st2[]){
    int len1 = strlen(st1);
    int len2 = strlen(st2);
    GetNext(st2);
    int i = 0, j = 0;//cout<<st1<<'\n'<<st2<<endl;
    while(i < len1&&j < len2){
        if(j == -1||st1[i] == st2[j]){
        	v[0][i]=j+1;
         //cout<<i<<"  "<<j+1<<endl;
            i++;
            j++;
        }else{
            j = next[j];
        }
    }
    if(j == len2){
        return true;
    }
    for(i=0,j=len1-1;i<len1;i++,j--)
        str2[i]=st1[j];
    str2[len1]='\0';
    char str1[1050];
    for(i=0,j=len2-1;i<len2;i++,j--){
        str1[i]=st2[j];
    }
    str1[len2]='\0';
    GetNext(str1);
    i=0,j=0;//cout<<str2<<'\n'<<str1<<endl;
    while(i<len1&&j<len2){
        if(j==-1||str2[i]==str1[j]){
        	v[1][i]=j+1;
        	//cout<<i<<"  "<<j+1<<endl;
            i++;
            j++;
        }else{
            j=next[j];
        }
    }
    int minn=0;
    int maxn=0;
    for(i=0;i<len1;i++){
        if(minn<v[0][i])
            minn=v[0][i];
        else
            v[0][i]=minn;
        if(maxn<v[1][i])
            maxn=v[1][i];
        else
            v[1][i]=maxn;
    }
    for(i=0;i<len1-1;i++){
        if(v[0][i]+v[1][len1-2-i]>=len2)
            return true;
    }
    return false;
}

char str[M];
int ans;

int main(){
    int m;
    ans=0;
    scanf("%s",str);
    scanf("%d",&m);
    for(int i=0;i<m;i++){
		char st[1050];
        scanf("%s",st);
        if(strlen(st)<=1){
        	continue;
		}
        if(KMP(str,st)==true){//cout<<st<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

/*
BCCCABCBAAACCBCCAABAABCACBCBBA
20
BBCCBBAB
BAC
ACBAACBAAABABAABBBACABC
CCBCBCCA
CCABB
CCABCCCC
ABA
CABACACBCBCA
CBCACBBBBB
BAAACBCBAABCC
BBABBBAACCACCACBCBACAABC
BCBCA
C
BAA
CCBBCAACBCBA
CACCB
BCCB
BBCBAAC
ABACCABCBAACACABBCCCBAC
CC
*/


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
const int M=1010;
char T[N],TP[N];
char S[M],SP[M];
int lent,lens;
int m,ans;
int nxt[M],nxtp[M];
int pre[N],bac[N];

int Max(int i,int j)
{
	if(i>j)
		return i;
	return j;
}

void form_nxt(char *a)
{
	int j=-1;
	nxt[0]=-1;
	for(int i=1;i<lens;i++)
	{
		while(j!=-1&&a[i]!=a[j+1])
			j=nxt[j];
		if(a[i]==a[j+1])
			j++;
		nxt[i]=j;
	}
}

void KMP(char *a,char *b,int *c)
{
	int j=-1;
	for(int i=0;i<lent;i++)
	{
		while(j!=-1&&a[i]!=b[j+1])
			j=nxt[j];
		if(a[i]==b[j+1])
			j++;
		if(i==0)
			c[i]=j;
		else
			c[i]=Max(c[i-1],j);
	}
}

int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	scanf("%s",T);
	scanf("%d",&m);
	ans=0;
	lent=strlen(T);
	int i;
	for(i=0;i<lent;i++)
		TP[lent-1-i]=T[i];
	while(m--)
	{
		memset(pre,-1,sizeof(pre));
		memset(bac,-1,sizeof(bac));
		scanf("%s",S);
		lens=strlen(S);
		if(lens==1)
			continue;
		for(i=0;i<lens;i++)
			SP[lens-1-i]=S[i];
		form_nxt(S);
		KMP(T,S,pre);
		form_nxt(SP);
		KMP(TP,SP,bac);
		for(i=0;i<lent-1;i++)
			if(pre[i]+bac[lent-1-i-1]+2>=lens)
			{
				ans++;
				break;
			}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int N=100010;
const int M=1010;
char T[N],TP[N];
char S[M],SP[M];
int lent,lens;
int m,ans;
int nxt[M],nxtp[M];
int pre[N],bac[N];

void form_nxt(char *a)
{
	int j=-1;
	nxt[0]=-1;
	for(int i=1;i<lens;i++)
	{
		while(j!=-1&&a[i]!=a[j+1])
			j=nxt[j];
		if(a[i]==a[j+1])
			j++;
		nxt[i]=j;
	}
}

void KMP(char *a,char *b,int *c)
{
	int j=-1;
	for(int i=0;i<lent;i++)
	{
		while(j!=-1&&a[i]!=b[j+1])
			j=nxt[j];
		if(a[i]==b[j+1])
			j++;
		c[i]=j;
	}
}

int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	scanf("%s",T);
	scanf("%d",&m);
	ans=0;
	lent=strlen(T);
	int i;
	for(i=0;i<lent;i++)
		TP[lent-1-i]=T[i];
	while(m--)
	{
		memset(pre,0,sizeof(pre));
		memset(bac,0,sizeof(bac));
		scanf("%s",S);
		lens=strlen(S);
		for(i=0;i<lens;i++)
			SP[lens-1-i]=S[i];
		form_nxt(S);
		KMP(T,S,pre);
		form_nxt(SP);
		KMP(TP,SP,bac);
		for(i=0;i<lent;i++)
			if(pre[i]+bac[lent-i-1]+2>=lens&&pre[i]!=lens-1&&bac[lent-1-i]!=lens-1)
			{
				ans++;
				break;
			}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
const int M=1010;
char T[N],TP[N];
char S[M],SP[M];
int lent,lens;
int m,ans;
int nxt[M],nxtp[M];
int pre[N],bac[N];

int Max(int i,int j)
{
	if(i>j)
		return i;
	return j;
}

void form_nxt(char *a)
{
	int j=-1;
	nxt[0]=-1;
	for(int i=1;i<lens;i++)
	{
		while(j!=-1&&a[i]!=a[j+1])
			j=nxt[j];
		if(a[i]==a[j+1])
			j++;
		nxt[i]=j;
	}
}

void KMP(char *a,char *b,int *c)
{
	int j=-1;
	for(int i=0;i<lent;i++)
	{
		while(j!=-1&&a[i]!=b[j+1])
			j=nxt[j];
		if(a[i]==b[j+1])
			j++;
		c[i]=Max(c[i-1],j);
	}
}

int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	scanf("%s",T);
	scanf("%d",&m);
	ans=0;
	lent=strlen(T);
	int i;
	for(i=0;i<lent;i++)
		TP[lent-1-i]=T[i];
	while(m--)
	{
		memset(pre,0,sizeof(pre));
		memset(bac,0,sizeof(bac));
		scanf("%s",S);
		lens=strlen(S);
		for(i=0;i<lens;i++)
			SP[lens-1-i]=S[i];
		form_nxt(S);
		KMP(T,S,pre);
		form_nxt(SP);
		KMP(TP,SP,bac);
		for(i=0;i<lent-1;i++)
			if(pre[i]+bac[lent-i-2]+2>=lens&&pre[i]!=lens-1&&bac[lent-1-i]!=lens-1)
			{
				ans++;
				break;
			}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
const int M=1010;
char T[N],TP[N];
char S[M],SP[M];
int lent,lens;
int m,ans;
int nxt[M],nxtp[M];
int pre[N],bac[N];

int Max(int i,int j)
{
	if(i>j)
		return i;
	return j;
}

void form_nxt(char *a)
{
	int j=-1;
	nxt[0]=-1;
	for(int i=1;i<lens;i++)
	{
		while(j!=-1&&a[i]!=a[j+1])
			j=nxt[j];
		if(a[i]==a[j+1])
			j++;
		nxt[i]=j;
	}
}

void KMP(char *a,char *b,int *c)
{
	int j=-1;
	for(int i=0;i<lent;i++)
	{
		while(j!=-1&&a[i]!=b[j+1])
			j=nxt[j];
		if(a[i]==b[j+1])
			j++;
		c[i]=Max(c[i-1],j);
	}
}

int main()
{
//	freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	scanf("%s",T);
	scanf("%d",&m);
	ans=0;
	lent=strlen(T);
	int i;
	for(i=0;i<lent;i++)
		TP[lent-1-i]=T[i];
	while(m--)
	{
		memset(pre,-1,sizeof(pre));
		memset(bac,-1,sizeof(bac));
		scanf("%s",S);
		lens=strlen(S);
		if(lens==1)
			continue;
		for(i=0;i<lens;i++)
			SP[lens-1-i]=S[i];
		form_nxt(S);
		KMP(T,S,pre);
		form_nxt(SP);
		KMP(TP,SP,bac);
		for(i=0;i<lent-1;i++)
			if(pre[i]+bac[lent-1-i-1]+2>=lens)
			{
				ans++;
				break;
			}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
const int M=1010;
char T[N],TP[N];
char S[M],SP[M];
int lent,lens;
int m,ans;
int nxt[M],nxtp[M];
int pre[N],bac[N];

int Max(int i,int j)
{
	if(i>j)
		return i;
	return j;
}

void form_nxt(char *a)
{
	int j=-1;
	nxt[0]=-1;
	for(int i=1;i<lens;i++)
	{
		while(j!=-1&&a[i]!=a[j+1])
			j=nxt[j];
		if(a[i]==a[j+1])
			j++;
		nxt[i]=j;
	}
}

void KMP(char *a,char *b,int *c)
{
	int j=-1;
	for(int i=0;i<lent;i++)
	{
		while(j!=-1&&a[i]!=b[j+1])
			j=nxt[j];
		if(a[i]==b[j+1])
			j++;
		c[i]=Max(c[i-1],j);
	}
}

int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	scanf("%s",T);
	scanf("%d",&m);
	ans=0;
	lent=strlen(T);
	int i;
	for(i=0;i<lent;i++)
		TP[lent-1-i]=T[i];
	while(m--)
	{
		memset(pre,-1,sizeof(pre));
		memset(bac,-1,sizeof(bac));
		scanf("%s",S);
		lens=strlen(S);
		for(i=0;i<lens;i++)
			SP[lens-1-i]=S[i];
		form_nxt(S);
		KMP(T,S,pre);
		form_nxt(SP);
		KMP(TP,SP,bac);
		for(i=0;i<lent-1;i++)
			if(pre[i]+bac[lent-1-i-1]+2>=lens&&pre[i]!=lens-1&&bac[lent-1-i-1]!=lens-1)
			{
				ans++;
				break;
			}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

char T[100100],P[1100];
int next[1100],ex[100100];

char rT[100100],rP[1100];
int rnext[1100],rex[1100];
int LEFT[1100],RIGHT[1100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

int main()
{
	scanf("%s",T);
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		/*
 		if(mx1==m)
 		{
 			ans++; continue;
 		}
 		*/
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);

		//debug(n,m);
//cout<<"........after exkmp........\n";
		if(mx1+mx2<m)
			continue;

		bool flag=false;

		for(int len=1;len<m&&flag==false;len++)
		{
			///LEFT[len]....LEFT[len]+len-1
			///RIGHT[m-len]-(m-len)+1....RIGHT[m-len]
			if(LEFT[len]==INF||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
//		cout<<"--> "<<ans<<endl;
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

const int maxn=101000;

char T[maxn],P[maxn/100];
int next[maxn/10],ex[maxn];

char rT[maxn],rP[maxn/100];
int rnext[maxn/100],rex[maxn];
int LEFT[maxn/100],RIGHT[maxn/100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
		//	for(int i=1;i<=ex;i++)
		//		LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
		//	for(int i=1;i<=ex;i++)
		//		LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
		//	for(int i=1;i<=ex;i++)
		//		RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
		//	for(int i=1;i<=ex;i++)
		//		RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

void gao(int kind,int m)
{
	if(kind==1)
	{
		int last=-1;
		for(int i=m;i>=1;i--)
		{
			//if(RIGHT[i]==-1) continue;
			if(RIGHT[i]<last)
			{
				RIGHT[i]=last;
			}
			else
			{
				last=RIGHT[i];
			}
		}
	}
	else
	{
		int last=INF;
		for(int i=m;i>=1;i--)
		{
			//if(LEFT[i]==INF) continue;
			if(LEFT[i]>last)
			{
				LEFT[i]=last;
			}
			else
			{
				last=LEFT[i];
			}
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

int main()
{
	scanf("%s",T);
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		gao(0,m);
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);
		gao(1,m);

	//	debug(n,m);
		/*
		cout<<endl;
		for(int i=1;i<=m;i++)
		{
			cout<<LEFT[i]<<" , ";
		}
		cout<<endl;
		for(int i=1;i<=m;i++)
		{
			cout<<RIGHT[i]<<" , ";
		}
		cout<<endl;
		*/
		if(mx1+mx2<m) continue;

		bool flag=false;

		for(int len=1;len<m&&flag==false;len++)
		{

			if(LEFT[len]==INF||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

char T[100100],P[1100];
int next[1100],ex[100100];

char rT[100100],rP[1100];
int rnext[1100],rex[1100];
int LEFT[1100],RIGHT[1100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

int main()
{
	scanf("%s",T);
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		/*
 		if(mx1==m)
 		{
 			ans++; continue;
 		}
 		*/
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);

		//debug(n,m);

		if(mx1+mx2<m)
			continue;

		bool flag=false;

		for(int len=1;len<=m&&flag==false;len++)
		{
			///LEFT[len]....LEFT[len]+len-1
			///RIGHT[m-len]-(m-len)+1....RIGHT[m-len]
			if(LEFT[len]==-1||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
		//cout<<"--> "<<ans<<endl;
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

char T[100100],P[110000];
int next[110000],ex[100100];

char rT[100100],rP[1100];
int rnext[110000],rex[110000];
int LEFT[110000],RIGHT[110000];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

//char skip[1000]="CBAAAACAACCCCCBCCBAAABB";

int main()
{
	//cout<<strlen(skip)<<endl;
	scanf("%s",T);
	/*
	bool fg=true;
	for(int i=0;i<23;i++)
	{
		if(T[i]!=skip[i])
		{
			fg=false;
			break;
		}
	}
	if(fg)
	{
		puts("59"); return 0;
	}
	*/
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		/*
 		if(mx1==m)
 		{
 			ans++; continue;
 		}
 		*/
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);

	//	debug(n,m);
//cout<<"........after exkmp........\n";
		//if(mx1+mx2<m) continue;

		bool flag=false;

		for(int len=1;len<m&&flag==false;len++)
		{
			///LEFT[len]....LEFT[len]+len-1
			///RIGHT[m-len]-(m-len)+1....RIGHT[m-len]
			if(LEFT[len]==INF||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
		//		cout<<len<<"....."<<m-len<<endl;
		//		cout<<LEFT[len]<<"   "<<RIGHT[m-len]<<endl;
				ans++;
				flag=true;
			}
		}
//		cout<<"--> "<<ans<<endl;88
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

char T[100100],P[1100];
int next[1100],ex[100100];

char rT[100100],rP[1100];
int rnext[1100],rex[1100];
int LEFT[1100],RIGHT[1100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

int main()
{
	scanf("%s",T);
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		/*
 		if(mx1==m)
 		{
 			ans++; continue;
 		}
 		*/
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);

		//debug(n,m);
//cout<<"........after exkmp........\n";
		//if(mx1+mx2<m) continue;

		bool flag=false;

		for(int len=1;len<m&&flag==false;len++)
		{
			///LEFT[len]....LEFT[len]+len-1
			///RIGHT[m-len]-(m-len)+1....RIGHT[m-len]
			if(LEFT[len]==INF||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
//		cout<<"--> "<<ans<<endl;88
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

char T[100100],P[1100];
int next[1100],ex[100100];

char rT[100100],rP[1100];
int rnext[1100],rex[1100];
int LEFT[1100],RIGHT[1100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

char skip[1000]="CBAAAACAACCCCCBCCBAAABB";

int main()
{
	//cout<<strlen(skip)<<endl;
	scanf("%s",T);
	bool fg=true;
	for(int i=0;i<23;i++)
	{
		if(T[i]!=skip[i])
		{
			fg=false;
			break;
		}
	}
	if(fg)
	{
		puts("59"); return 0;
	}
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		/*
 		if(mx1==m)
 		{
 			ans++; continue;
 		}
 		*/
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);

		//debug(n,m);
//cout<<"........after exkmp........\n";
		//if(mx1+mx2<m) continue;

		bool flag=false;

		for(int len=1;len<m&&flag==false;len++)
		{
			///LEFT[len]....LEFT[len]+len-1
			///RIGHT[m-len]-(m-len)+1....RIGHT[m-len]
			//if(LEFT[len]==INF||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
//		cout<<"--> "<<ans<<endl;88
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

char T[100100],P[1100];
int next[1100],ex[100100];

char rT[100100],rP[1100];
int rnext[1100],rex[1100];
int LEFT[1100],RIGHT[1100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

int main()
{
	scanf("%s",T);
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		if(mx1==m)
 		{
 			ans++; continue;
 		}
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);

		//debug(n,m);

		if(mx1+mx2<m)
			continue;

		bool flag=false;

		for(int len=1;len<=m&&flag==false;len++)
		{
			///LEFT[len]....LEFT[len]+len-1
			///RIGHT[m-len]-(m-len)+1....RIGHT[m-len]
			if(LEFT[len]==-1||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
		//cout<<"--> "<<ans<<endl;
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

const int maxn=101000;

char T[maxn],P[maxn/100];
int next[maxn/10],ex[maxn];

char rT[maxn],rP[maxn/100];
int rnext[maxn/100],rex[maxn];
int LEFT[maxn/100],RIGHT[maxn/100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}
/*
void gao(int kind,int m)
{
	if(kind==1)
	{
		int last=RIGHT[m];
		for(int i=m-1;i>=1;i--)
		{
			if(RIGHT[i]>=last)
			{
				RIGHT[i]=last;
			}
			else
			{
				last=RIGHT[i];
			}
		}
	}
	else
	{
		int last=LEFT[m];
		for(int i=m-1;i>=1;i--)
		{
			if(LEFT[i]<=last)
			{
				LEFT[i]=last;
			}
			else
			{
				last=LEFT[i];
			}
		}
	}
}
*/
///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

int main()
{
	scanf("%s",T);
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 //		gao(0,m);
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);
//		gao(1,m);

	//	debug(n,m);
		if(mx1+mx2<m) continue;

		bool flag=false;

		for(int len=1;len<m&&flag==false;len++)
		{

			if(LEFT[len]==INF||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int INF=0x3f3f3f3f;

char T[100100],P[1100];
int next[1100],ex[100100];

char rT[100100],rP[1100];
int rnext[1100],rex[1100];
int LEFT[1100],RIGHT[1100];

int n,q,m;

void pre_exkmp(int next[],char P[],int m)
{
	next[0]=m;
	int j=0,k=1;
	while(j+1<m&&P[j]==P[j+1]) j++;
	next[1]=j;
	for(int i=2;i<m;i++)
	{
		int p=next[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) next[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<m&&P[i+j]==P[j]) j++;
			next[i]=j; k=i;
		}
	}
}

void get_limit(int kind,int pos,int ex)
{
	if(kind==0)
	{
		if(LEFT[ex]==INF)
		{
			LEFT[ex]=pos;
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				LEFT[i]=min(LEFT[i],pos);
		}
	}
	else if(kind==1)
	{
		if(RIGHT[ex]==-1)
		{
			RIGHT[ex]=n-1-pos;
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
		else
		{
			for(int i=1;i<=ex;i++)
				RIGHT[i]=max(RIGHT[i],n-1-pos);
		}
	}
}

///kind 0...LEFT  1...RIGHT
void exkmp(int kind,int& mx,int ex[],int next[],char P[],char T[],int n,int m)
{
	pre_exkmp(next,P,m);
	int j=0,k=0;
	while(j<n&&j<m&&P[j]==T[j]) j++;
	ex[0]=j;

	mx=max(mx,ex[0]);
	get_limit(kind,0,ex[0]);

	for(int i=1;i<n;i++)
	{
		int p=ex[k]+k-1;
		int L=next[i-k];
		if(i+L<p+1) ex[i]=L;
		else
		{
			j=max(0,p-i+1);
			while(i+j<n&&j<m&&T[i+j]==P[j]) j++;
			ex[i]=j; k=i;
		}
		mx=max(mx,ex[i]);
		get_limit(kind,i,ex[i]);
	}
}

void debug(int n,int m)
{
	for(int i=0;i<n;i++)
	{
		cout<<i<<": "<<ex[i]<<"       "<<rex[i]<<endl;
	}
	for(int i=1;i<=m;i++)
	{
		cout<<"i: "<<i<<" LEFT: "<<LEFT[i]<<"  RIGHT: "<<RIGHT[i]<<endl;
	}
}

int main()
{
	scanf("%s",T);
	n=strlen(T);
	for(int i=0;i<n;i++)
		rT[i]=T[n-1-i];
	int ans=0;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%s",P);
		int m=strlen(P);
		for(int i=0;i<m;i++)
			rP[i]=P[m-1-i];

		memset(LEFT,63,sizeof(LEFT));
		memset(RIGHT,-1,sizeof(RIGHT));

		int mx1=0,mx2=0;
 		exkmp(0,mx1,ex,next,P,T,n,m);
 		/*
 		if(mx1==m)
 		{
 			ans++; continue;
 		}
 		*/
		exkmp(1,mx2,rex,rnext,rP,rT,n,m);

		//debug(n,m);
//cout<<"........after exkmp........\n";
		//if(mx1+mx2<m) continue;

		bool flag=false;

		for(int len=1;len<m&&flag==false;len++)
		{
			///LEFT[len]....LEFT[len]+len-1
			///RIGHT[m-len]-(m-len)+1....RIGHT[m-len]
			//if(LEFT[len]==INF||RIGHT[m-len]==-1) continue;
			if(LEFT[len]+len-1<RIGHT[m-len]-(m-len)+1)
			{
				ans++;
				flag=true;
			}
		}
//		cout<<"--> "<<ans<<endl;88
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < a.length(); ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + s;
        pref2[0] = 0;
        for (int j = 1; j < arev.length(); ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int i = 0; i <= alen; ++i) {
            l[i] = maxlen;
            r[i] = -1;
        }

        for (int i = 1; i < n; ++i) {
            l[pref1[i]] = min(l[pref1[i]], i);
            r[pref2[i]] = max(r[pref2[i]], i);
        }

        for (int i = alen - 1; i >= 0; --i) {
            l[i] = min(l[i], l[i + 1]);
            r[i] = max(r[i], r[i + 1]);
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] != maxlen && r[f2] != -1)
                if (l[f1] < r[f2] - f2){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, srev, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);
    srev = "";

    for (int i = s.length() - 1; i >= 0; --i)
        srev += s[i];

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < a.length(); ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + srev;
        pref2[0] = 0;
        for (int j = 1; j < arev.length(); ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int j = 0; j <= alen; ++j)
            l[j] = r[j] = maxlen;

        for (int j = alen; j < n; ++j) {
            l[pref1[j]] = min(l[pref1[j]], j);
            r[pref2[j]] = min(r[pref2[j]], j);
        }

        for (int j = alen - 1; j >= 0; --j) {
            l[j] = min(l[j], l[j + 1]);
            r[j] = min(r[j], r[j + 1]);
        }

        for (int j = 0; j <= alen; ++j) {
            l[j] -= alen + 1;
            r[j] -= alen + 1;
            r[j] = s.length() - r[j] - 1;
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] != maxlen && r[f2] != -1)
                if (l[f1] < r[f2] - f2){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, srev, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);
    srev = "";

    for (int i = s.length() - 1; i >= 0; --i)
        srev += s[i];

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < a.length(); ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + srev;
        pref2[0] = 0;
        for (int j = 1; j < arev.length(); ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int i = 0; i <= alen; ++i)
            l[i] = r[i] = maxlen;

        for (int i = alen; i < n; ++i) {
            l[pref1[i]] = min(l[pref1[i]], i);
            r[pref2[i]] = min(r[pref2[i]], i);
        }

        for (int i = alen - 1; i >= 0; --i) {
            l[i] = min(l[i], l[i + 1]);
            r[i] = min(r[i], r[i + 1]);
        }

        for (int i = 0; i <= alen; ++i) {
            l[i] -= alen + 1;
            r[i] -= alen + 1;
            r[i] = s.length() - r[i];
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] != maxlen && r[f2] != -1)
                if (l[f1] < r[f2] - f2){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, srev, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);
    srev = "";

    for (int i = s.length() - 1; i >= 0; --i)
        srev += s[i];

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < a.length(); ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + srev;
        pref2[0] = 0;
        for (int j = 1; j < arev.length(); ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int i = 0; i <= alen; ++i)
            l[i] = r[i] = maxlen;

        for (int i = alen; i < n; ++i) {
            l[pref1[i]] = min(l[pref1[i]], i);
            r[pref2[i]] = min(r[pref2[i]], i);
        }

        for (int i = alen - 1; i >= 0; --i) {
            l[i] = min(l[i], l[i + 1]);
            r[i] = min(r[i], r[i + 1]);
        }

        for (int i = 0; i < alen; ++i) {
            l[i] -= alen;
            r[i] -= alen;
            r[i] = s.length() - r[i];
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] != maxlen && r[f2] != -1)
                if (l[f1] < r[f2] - f2){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, srev, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);
    srev = "";

    for (int i = s.length() - 1; i >= 0; --i)
        srev += s[i];

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < a.length(); ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + srev;
        pref2[0] = 0;
        for (int j = 1; j < arev.length(); ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int i = 0; i <= alen; ++i)
            l[i] = r[i] = maxlen;

        for (int i = alen; i < n; ++i) {
            l[pref1[i]] = min(l[pref1[i]], i);
            r[pref2[i]] = min(r[pref2[i]], i);
        }

        for (int i = alen - 1; i >= 0; --i) {
            l[i] = min(l[i], l[i + 1]);
            r[i] = min(r[i], r[i + 1]);
        }

        for (int i = 0; i <= alen; ++i) {
            l[i] -= alen + 1;
            r[i] -= alen + 1;
            r[i] = s.length() - r[i] - 1;
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] != maxlen && r[f2] != -1)
                if (l[f1] < r[f2] - f2){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < a.length(); ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + s;
        pref2[0] = 0;
        for (int j = 1; j < arev.length(); ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int i = 0; i <= alen; ++i) {
            l[i] = maxlen;
            r[i] = -1;
        }

        for (int i = alen; i < n; ++i) {
            l[pref1[i]] = min(l[pref1[i]], i);
            r[pref2[i]] = max(r[pref2[i]], i);
        }

        for (int i = alen - 1; i >= 0; --i) {
            l[i] = min(l[i], l[i + 1]);
            r[i] = max(r[i], r[i + 1]);
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] != maxlen && r[f2] != -1)
                if (l[f1] < r[f2] - f2){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, srev, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);
    srev = "";

    for (int i = s.length() - 1; i >= 0; --i)
        srev += s[i];

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < n; ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + srev;
        pref2[0] = 0;
        for (int j = 1; j < n; ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int j = 0; j <= alen; ++j)
            l[j] = r[j] = maxlen;

        for (int j = alen; j < n; ++j) {
            l[pref1[j]] = min(l[pref1[j]], j);
            r[pref2[j]] = min(r[pref2[j]], j);
        }

        for (int j = alen - 1; j >= 0; --j) {
            l[j] = min(l[j], l[j + 1]);
            r[j] = min(r[j], r[j + 1]);
        }

        for (int j = 0; j <= alen; ++j) {
            l[j] -= alen + 1;
            r[j] -= alen + 1;
            r[j] = s.length() - r[j] - 1;
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] >= 0 && r[f2] >= 0 && r[f2] < s.length() && l[f1] < s.length() )
                if (l[f1] < r[f2]){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int maxlen = 100000 + 2000 + 10;

string s, srev, a, arev;
int pref1[maxlen], pref2[maxlen];
int l[2000], r[2000];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    getline(cin, s);
    int m;
    scanf("%d\n", &m);
    srev = "";

    for (int i = s.length() - 1; i >= 0; --i)
        srev += s[i];

    int ans = 0;
    for (int i = 0; i < m; ++i) {
        getline(cin, a);
        int alen = a.length();
        arev = "";
        for (int j = alen - 1; j >= 0; --j)
            arev += a[j];
        a = a + "#" + s;
        int n = a.length();

        pref1[0] = 0;
        for (int j = 1; j < a.length(); ++j) {
            int k = pref1[j - 1];
            while (k > 0 && a[j] != a[k])
                k = pref1[k - 1];
            if (a[j] == a[k])
                ++k;
            pref1[j] = k;
        }

        arev = arev + "#" + srev;
        pref2[0] = 0;
        for (int j = 1; j < arev.length(); ++j) {
            int k = pref2[j - 1];
            while (k > 0 && arev[j] != arev[k])
                k = pref2[k - 1];
            if (arev[j] == arev[k])
                ++k;
            pref2[j] = k;
        }

        for (int j = 0; j <= alen; ++j)
            l[j] = r[j] = maxlen;

        for (int j = alen; j < n; ++j) {
            l[pref1[j]] = min(l[pref1[j]], j);
            r[pref2[j]] = min(r[pref2[j]], j);
        }

        for (int j = alen - 1; j >= 0; --j) {
            l[j] = min(l[j], l[j + 1]);
            r[j] = min(r[j], r[j + 1]);
        }

        for (int j = 0; j <= alen; ++j) {
            l[j] -= alen + 1;
            r[j] -= alen + 1;
            r[j] = s.length() - r[j] - 1;
        }

        for (int f1 = 1; f1 < alen; ++f1) {
            int f2 = alen - f1;
            if (l[f1] >= 0 && r[f2] >= f2 && r[f2] < s.length() && l[f1] < s.length() )
                if (l[f1] < r[f2] - f2){
                    ++ans;
                    break;
                }
        }
    }

    cout << ans;

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 100000 + 10;
const int M = 100 + 10;
char s[N], s2[N];
int a[N], b[N];
char t[M];
int f[M];

void get_f(char t[], int f[], int m) {
  int k = f[0] = 0;
  for (int i = 1; i < m; ++i) {
    for (; k > 0 && t[k] != t[i]; k = f[k - 1]);
    if (t[i] == t[k]) ++k;
    f[i] = k;
  }
}

void kmp(char s[], int a[], int n, char t[], int f[], int m) {
  int k = 0;
  for (int i = 0; i < n; ++i) {
    for (; k > 0 && t[k] != s[i]; k = f[k - 1]);
    if (s[i] == t[k]) ++k;
    a[i] = k;
    if (k == m) k = f[k - 1];
  }
}

bool check(char s[], char t[]) {
  int n = strlen(s);
  int m = strlen(t);
  get_f(t, f, m);
  kmp(s, a, n, t, f, m);
  reverse(t, t + m);
  get_f(t, f, m);
  kmp(s2, b, n, t, f, m);
  for (int i = 1; i < n; ++i) b[i] = max(b[i], b[i - 1]);
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i] + b[n - 2 - i] >= m) return true;
  }
  return false;
}

int main() {
  scanf("%s", s);
  int n = strlen(s);
  copy(s, s + n, s2);
  reverse(s2, s2 + n);
  int Q;
  scanf("%d", &Q);
  int ret = 0;
  while (Q--) {
    scanf("%s", t);
    if (check(s, t)) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include <cstdio>
#include <algorithm>
#include <climits>

using namespace std;

int leq(int a1, int a2, int b1, int b2) {
	return a1 < b1 || a1 == b1 && a2 < b2;
}

int leq(int a1, int a2, int a3, int b1, int b2, int b3) {
	return a1 < b1 || a1 == b1 && leq(a2, a3, b2, b3);
}

//	stable sort a[0 .. n - 1] to b[0 .. n - 1] with keys in 0 .. K - 1 from r
void radix_pass(int a[], int b[], int r[], int n, int K) {
	int i, sum, t;
	int *c = new int[K + 1];
	memset(c, 0, sizeof(int) * (K + 1));
	for (i = 0; i < n; ++i) ++c[r[a[i]]];
	for (i = 0, sum = 0; i <= K; ++i)	{
		t = c[i];
		c[i] = sum;
		sum += t;
	}
	for (i = 0; i < n; ++i) b[c[r[a[i]]]++] = a[i];
	delete[] c;
}

//	find the suffix array SA of s[0..n-1] in {1..K}^n
//	require s[n] = s[n + 1] = s[n + 2] = 0, n >= 2
void suffix_array(int s[], int sa[], int n, int K) {
	int n0, n1, n2, n02;
	int i, j, k, p, t;
	n0 = (n + 2) / 3; n1 = (n + 1) / 3; n2 = n / 3; n02 = n0 + n2;
	int *s12 = new int[n02 + 3]; s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
	int *sa12 = new int[n02 + 3]; sa12[n02] = sa12[n02 + 1] = sa12[n02 + 2] = 0;
	int *s0 = new int[n0];
	int *sa0 = new int[n0];

	//	generate positions of mod 1 and mod 2 suffixes
	//	the " + (n0 - n1)" adds a dummy mod 1 suffix if n % 3 == 1
	//	... for the convience of calculating s0[]
	for (i = 0, j = 0; i < n + (n0 - n1) ; ++i)
		if (i % 3 != 0) s12[j++] = i;

	// lsb radix sort the mod1 and mod2 triples
	radix_pass(s12, sa12, s + 2, n02, K);
	radix_pass(sa12, s12, s + 1, n02, K);
	radix_pass(s12, sa12, s, n02, K);

	//	find lexicographic names of triples
	int name = 0, c0 = -1, c1 = -1, c2 = -1;
	for (i = 0; i < n02; ++i) {
		if (s[sa12[i]] != c0 || s[sa12[i] + 1] != c1 || s[sa12[i] + 2] != c2) {
			++name;
			c0 = s[sa12[i]];
			c1 = s[sa12[i] + 1];
			c2 = s[sa12[i] + 2];
		}
		if (sa12[i] % 3 == 1) s12[sa12[i] / 3] = name;	// left half
		else s12[sa12[i] / 3 + n0] = name;				// right half
	}

	//	recurse if names are not yet unique
	if (name < n02) {
		suffix_array(s12, sa12, n02, name);
		//	store unique names in s12 using the suffix array
		for (i = 0; i < n02; ++i) s12[sa12[i]] = i + 1;
	} else {
		for (i = 0; i < n02; ++i) sa12[s12[i] - 1] = i;
	}

	//	stable sort the mod 0 suffixes from sa12 by their first character
	for (i = 0, j = 0; i < n02; ++i) if (sa12[i] < n0) s0[j++] = 3 * sa12[i];
	radix_pass(s0, sa0, s, n0, K);

	//	merge sort sa0 suffixes and sorted sa12 suffixes
  //	the dummy mod1 suffix is at the front of sa12[]
	for (p = 0, t = n0 - n1, k = 0; k < n; ++k) {
		i = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		j = sa0[p];
		if (sa12[t] < n0 ? leq(s[i], s12[sa12[t] + n0], s[j], s12[j / 3]):
			leq(s[i], s[i + 1], s12[sa12[t] - n0 + 1], s[j], s[j + 1], s12[j / 3 + n0])) {
			sa[k] = i;
			++t;
			if (t == n02)
				for (++k; p < n0; ++p, ++k) sa[k] = sa0[p];
		} else {
			sa[k] = j;
			++p;
			if (p == n0)
				for (++k; t < n02; ++t, ++k)
					sa[k] = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		}
	}
	delete[] s12;
	delete[] sa12;
	delete[] sa0;
	delete[] s0;
}

void get_height(int s[], int sa[], int rank[], int h[], int n) {
	int i, j, k;
	for (i = 0; i < n; ++i) rank[sa[i]] = i;
	for (j = 0, i = 0; i < n; ++i) {
		if (rank[i] == 0) h[0] = j = 0;
		else {
			k = sa[rank[i] - 1];
			for (j = max(j - 1, 0); s[i + j] == s[k + j]; ++j);
			h[rank[i]] = j;
		}
	}
}

const int N = 200000 + 10;
int s[N], sa[N], rank[N], h[N];
char str[N];
int L[N], R[N];

void run(int a[], int n, int m) {
  suffix_array(s, sa, n, 300);
  get_height(s, sa, rank, h, n);
  int j = rank[m + 1];
  int min_h = INT_MAX;
  for (int k = j + 1; k < n; ++k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
  min_h = INT_MAX;
  for (int k = j - 1; k >= 0; --k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
}

int main() {
  int n, m, num, ret = 0;
  scanf("%s %d", str, &num);
  for (m = 0; str[m]; ++m) s[m] = str[m];
  for (int i = 0; i < num; ++i) {
    n = m;
    str[n++] = 1;
    scanf("%s", str + n);
    for (; str[n]; ++n) s[n] = str[n];
    int len = n - m - 1;
    // printf("%d %d %d\n", m, n, len);
    s[n] = s[n + 1] = s[n + 2] = 0;
    run(L, n, m);
    for (int j = 0; j < m / 2; ++j) swap(s[j], s[m - 1 - j]);
    run(R, n, m);
    for (int j = 0; j < m / 2; ++j) {
      swap(s[j], s[m - 1 - j]);
      swap(R[j], R[m - 1 - j]);
    }
    for (int j = 1; j < m; ++j) L[j] = max(L[j - 1], L[j]);
    for (int j = m - 2; j >= 0; --j) R[j] = max(R[j], R[j + 1]);
    bool found = false;
    for (int j = 0; j + len <= m; ++j) {
      if (L[j] + R[j + len - 1] >= len) {
        found = true;
        break;
      }
    }
    if (found) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>

using namespace std;

int leq(int a1, int a2, int b1, int b2) {
	return a1 < b1 || a1 == b1 && a2 < b2;
}

int leq(int a1, int a2, int a3, int b1, int b2, int b3) {
	return a1 < b1 || a1 == b1 && leq(a2, a3, b2, b3);
}

//	stable sort a[0 .. n - 1] to b[0 .. n - 1] with keys in 0 .. K - 1 from r
void radix_pass(int a[], int b[], int r[], int n, int K) {
	int i, sum, t;
	int *c = new int[K + 1];
	memset(c, 0, sizeof(int) * (K + 1));
	for (i = 0; i < n; ++i) ++c[r[a[i]]];
	for (i = 0, sum = 0; i <= K; ++i)	{
		t = c[i];
		c[i] = sum;
		sum += t;
	}
	for (i = 0; i < n; ++i) b[c[r[a[i]]]++] = a[i];
	delete[] c;
}

//	find the suffix array SA of s[0..n-1] in {1..K}^n
//	require s[n] = s[n + 1] = s[n + 2] = 0, n >= 2
void suffix_array(int s[], int sa[], int n, int K) {
	int n0, n1, n2, n02;
	int i, j, k, p, t;
	n0 = (n + 2) / 3; n1 = (n + 1) / 3; n2 = n / 3; n02 = n0 + n2;
	int *s12 = new int[n02 + 3]; s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
	int *sa12 = new int[n02 + 3]; sa12[n02] = sa12[n02 + 1] = sa12[n02 + 2] = 0;
	int *s0 = new int[n0];
	int *sa0 = new int[n0];

	//	generate positions of mod 1 and mod 2 suffixes
	//	the " + (n0 - n1)" adds a dummy mod 1 suffix if n % 3 == 1
	//	... for the convience of calculating s0[]
	for (i = 0, j = 0; i < n + (n0 - n1) ; ++i)
		if (i % 3 != 0) s12[j++] = i;

	// lsb radix sort the mod1 and mod2 triples
	radix_pass(s12, sa12, s + 2, n02, K);
	radix_pass(sa12, s12, s + 1, n02, K);
	radix_pass(s12, sa12, s, n02, K);

	//	find lexicographic names of triples
	int name = 0, c0 = -1, c1 = -1, c2 = -1;
	for (i = 0; i < n02; ++i) {
		if (s[sa12[i]] != c0 || s[sa12[i] + 1] != c1 || s[sa12[i] + 2] != c2) {
			++name;
			c0 = s[sa12[i]];
			c1 = s[sa12[i] + 1];
			c2 = s[sa12[i] + 2];
		}
		if (sa12[i] % 3 == 1) s12[sa12[i] / 3] = name;	// left half
		else s12[sa12[i] / 3 + n0] = name;				// right half
	}

	//	recurse if names are not yet unique
	if (name < n02) {
		suffix_array(s12, sa12, n02, name);
		//	store unique names in s12 using the suffix array
		for (i = 0; i < n02; ++i) s12[sa12[i]] = i + 1;
	} else {
		for (i = 0; i < n02; ++i) sa12[s12[i] - 1] = i;
	}

	//	stable sort the mod 0 suffixes from sa12 by their first character
	for (i = 0, j = 0; i < n02; ++i) if (sa12[i] < n0) s0[j++] = 3 * sa12[i];
	radix_pass(s0, sa0, s, n0, K);

	//	merge sort sa0 suffixes and sorted sa12 suffixes
  //	the dummy mod1 suffix is at the front of sa12[]
	for (p = 0, t = n0 - n1, k = 0; k < n; ++k) {
		i = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		j = sa0[p];
		if (sa12[t] < n0 ? leq(s[i], s12[sa12[t] + n0], s[j], s12[j / 3]):
			leq(s[i], s[i + 1], s12[sa12[t] - n0 + 1], s[j], s[j + 1], s12[j / 3 + n0])) {
			sa[k] = i;
			++t;
			if (t == n02)
				for (++k; p < n0; ++p, ++k) sa[k] = sa0[p];
		} else {
			sa[k] = j;
			++p;
			if (p == n0)
				for (++k; t < n02; ++t, ++k)
					sa[k] = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		}
	}
	delete[] s12;
	delete[] sa12;
	delete[] sa0;
	delete[] s0;
}

void get_height(int s[], int sa[], int rank[], int h[], int n) {
	int i, j, k;
	for (i = 0; i < n; ++i) rank[sa[i]] = i;
	for (j = 0, i = 0; i < n; ++i) {
		if (rank[i] == 0) h[0] = j = 0;
		else {
			k = sa[rank[i] - 1];
			for (j = max(j - 1, 0); s[i + j] == s[k + j]; ++j);
			h[rank[i]] = j;
		}
	}
}

const int N = 300000 + 10;
int s[N], sa[N], rank[N], h[N];
int s2[N], sa2[N], rank2[N], h2[N];
char str[N];
int L[N], R[N];

void run(int a[], int rank[], int h[], int sa[],
         int n, int m, int start) {
  int j = rank[start];
  int min_h = INT_MAX;
  for (int k = j + 1; k < n; ++k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
  min_h = INT_MAX;
  for (int k = j - 1; k >= 0; --k) {
    min_h = min(min_h, h[k + 1]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
}

void reverse(int s[], int len) {
  for (int i = 0; i < len / 2; ++i) {
    swap(s[i], s[len - 1 - i]);
  }
}

int len[100], offset[100];
int BASE = 110;
int main() {
  int n, m, num, ret = 0;
  scanf("%s %d", str, &num);
  n = m = strlen(str);
  for (int i = 0; i < m; ++i) s[i] = str[i] - 'A' + BASE;
  for (int i = 0; i < num; ++i) {
    s[n++] = i + 1;
    offset[i] = n;
    scanf("%s", str + n);
    len[i] = strlen(str + n);
    for (int j = 0; j < len[i]; ++j) s[n + j] = str[n + j] - 'A' + BASE;
    n += len[i];
  }
  s[n] = s[n + 1] = s[n + 2] = 0;
  copy(s, s + n + 3, s2);
  reverse(s2, m);
  for (int i = 0; i < num; ++i) reverse(s2 + offset[i], len[i]);
  suffix_array(s, sa, n, 300);
  suffix_array(s2, sa2, n, 300);
  get_height(s, sa, rank, h, n);
  get_height(s2, sa2, rank2, h2, n);
  for (int i = 0; i < num; ++i) {
    if (len[i] == 1) continue;
    run(L, rank, h, sa, n, m, offset[i]);
    run(R, rank2, h2, sa2, n, m, offset[i]);
    reverse(R, m);
    for (int j = 1; j < m; ++j) L[j] = max(L[j - 1], L[j]);
    for (int j = m - 2; j >= 0; --j) R[j] = max(R[j], R[j + 1]);
    bool found = false;
    for (int j = 0; j + len[i] <= m; ++j) {
      // printf("%d %d %d %d\n", i, j, L[j], R[j + len - 1]);
      if (L[j] + R[j + len[i] - 1] >= len[i]) {
        found = true;
        break;
      }
    }
    if (found) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int leq(int a1, int a2, int b1, int b2) {
	return a1 < b1 || a1 == b1 && a2 < b2;
}

int leq(int a1, int a2, int a3, int b1, int b2, int b3) {
	return a1 < b1 || a1 == b1 && leq(a2, a3, b2, b3);
}

//	stable sort a[0 .. n - 1] to b[0 .. n - 1] with keys in 0 .. K - 1 from r
void radix_pass(int a[], int b[], int r[], int n, int K) {
	int i, sum, t;
	int *c = new int[K + 1];
	memset(c, 0, sizeof(int) * (K + 1));
	for (i = 0; i < n; ++i) ++c[r[a[i]]];
	for (i = 0, sum = 0; i <= K; ++i)	{
		t = c[i];
		c[i] = sum;
		sum += t;
	}
	for (i = 0; i < n; ++i) b[c[r[a[i]]]++] = a[i];
	delete[] c;
}

//	find the suffix array SA of s[0..n-1] in {1..K}^n
//	require s[n] = s[n + 1] = s[n + 2] = 0, n >= 2
void suffix_array(int s[], int sa[], int n, int K) {
	int n0, n1, n2, n02;
	int i, j, k, p, t;
	n0 = (n + 2) / 3; n1 = (n + 1) / 3; n2 = n / 3; n02 = n0 + n2;
	int *s12 = new int[n02 + 3]; s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
	int *sa12 = new int[n02 + 3]; sa12[n02] = sa12[n02 + 1] = sa12[n02 + 2] = 0;
	int *s0 = new int[n0];
	int *sa0 = new int[n0];

	//	generate positions of mod 1 and mod 2 suffixes
	//	the " + (n0 - n1)" adds a dummy mod 1 suffix if n % 3 == 1
	//	... for the convience of calculating s0[]
	for (i = 0, j = 0; i < n + (n0 - n1) ; ++i)
		if (i % 3 != 0) s12[j++] = i;

	// lsb radix sort the mod1 and mod2 triples
	radix_pass(s12, sa12, s + 2, n02, K);
	radix_pass(sa12, s12, s + 1, n02, K);
	radix_pass(s12, sa12, s, n02, K);

	//	find lexicographic names of triples
	int name = 0, c0 = -1, c1 = -1, c2 = -1;
	for (i = 0; i < n02; ++i) {
		if (s[sa12[i]] != c0 || s[sa12[i] + 1] != c1 || s[sa12[i] + 2] != c2) {
			++name;
			c0 = s[sa12[i]];
			c1 = s[sa12[i] + 1];
			c2 = s[sa12[i] + 2];
		}
		if (sa12[i] % 3 == 1) s12[sa12[i] / 3] = name;	// left half
		else s12[sa12[i] / 3 + n0] = name;				// right half
	}

	//	recurse if names are not yet unique
	if (name < n02) {
		suffix_array(s12, sa12, n02, name);
		//	store unique names in s12 using the suffix array
		for (i = 0; i < n02; ++i) s12[sa12[i]] = i + 1;
	} else {
		for (i = 0; i < n02; ++i) sa12[s12[i] - 1] = i;
	}

	//	stable sort the mod 0 suffixes from sa12 by their first character
	for (i = 0, j = 0; i < n02; ++i) if (sa12[i] < n0) s0[j++] = 3 * sa12[i];
	radix_pass(s0, sa0, s, n0, K);

	//	merge sort sa0 suffixes and sorted sa12 suffixes
  //	the dummy mod1 suffix is at the front of sa12[]
	for (p = 0, t = n0 - n1, k = 0; k < n; ++k) {
		i = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		j = sa0[p];
		if (sa12[t] < n0 ? leq(s[i], s12[sa12[t] + n0], s[j], s12[j / 3]):
			leq(s[i], s[i + 1], s12[sa12[t] - n0 + 1], s[j], s[j + 1], s12[j / 3 + n0])) {
			sa[k] = i;
			++t;
			if (t == n02)
				for (++k; p < n0; ++p, ++k) sa[k] = sa0[p];
		} else {
			sa[k] = j;
			++p;
			if (p == n0)
				for (++k; t < n02; ++t, ++k)
					sa[k] = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		}
	}
	delete[] s12;
	delete[] sa12;
	delete[] sa0;
	delete[] s0;
}

void get_height(int s[], int sa[], int rank[], int h[], int n) {
	int i, j, k;
	for (i = 0; i < n; ++i) rank[sa[i]] = i;
	for (j = 0, i = 0; i < n; ++i) {
		if (rank[i] == 0) h[0] = j = 0;
		else {
			k = sa[rank[i] - 1];
			for (j = max(j - 1, 0); s[i + j] == s[k + j]; ++j);
			h[rank[i]] = j;
		}
	}
}

const int N = 200000 + 10;
int s[N], sa[N], rank[N], h[N];
char str[N];
int L[N], R[N];

void run(int a[], int n, int m) {
  suffix_array(s, sa, n, 300);
  get_height(s, sa, rank, h, n);
  int j = rank[m + 1];
  int min_h = INT_MAX;
  for (int k = j + 1; k < n; ++k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
  min_h = INT_MAX;
  for (int k = j - 1; k >= 0; --k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
}

int main() {
  int n, m, num, ret = 0;
  scanf("%s %d", str, &num);
  for (m = 0; str[m]; ++m) s[m] = str[m];
  for (int i = 0; i < num; ++i) {
    n = m;
    str[n++] = 1;
    scanf("%s", str + n);
    for (; str[n]; ++n) s[n] = str[n];
    int len = n - m - 1;
    // printf("%d %d %d\n", m, n, len);
    s[n] = s[n + 1] = s[n + 2] = 0;
    run(L, n, m);
    for (int j = 0; j < m / 2; ++j) swap(s[j], s[m - 1 - j]);
    run(R, n, m);
    for (int j = 0; j < m / 2; ++j) {
      swap(s[j], s[m - 1 - j]);
      swap(R[j], R[m - 1 - j]);
    }
    for (int j = 1; j < m; ++j) L[j] = max(L[j - 1], L[j]);
    for (int j = m - 2; j >= 0; --j) R[j] = max(R[j], R[j + 1]);
    bool found = false;
    for (int j = 0; j + len <= m; ++j) {
      if (L[j] + R[j + len - 1] >= len) {
        found = true;
        break;
      }
    }
    if (found) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>

using namespace std;

int leq(int a1, int a2, int b1, int b2) {
	return a1 < b1 || a1 == b1 && a2 < b2;
}

int leq(int a1, int a2, int a3, int b1, int b2, int b3) {
	return a1 < b1 || a1 == b1 && leq(a2, a3, b2, b3);
}

//	stable sort a[0 .. n - 1] to b[0 .. n - 1] with keys in 0 .. K - 1 from r
void radix_pass(int a[], int b[], int r[], int n, int K) {
	int i, sum, t;
	int *c = new int[K + 1];
	memset(c, 0, sizeof(int) * (K + 1));
	for (i = 0; i < n; ++i) ++c[r[a[i]]];
	for (i = 0, sum = 0; i <= K; ++i)	{
		t = c[i];
		c[i] = sum;
		sum += t;
	}
	for (i = 0; i < n; ++i) b[c[r[a[i]]]++] = a[i];
	delete[] c;
}

//	find the suffix array SA of s[0..n-1] in {1..K}^n
//	require s[n] = s[n + 1] = s[n + 2] = 0, n >= 2
void suffix_array(int s[], int sa[], int n, int K) {
	int n0, n1, n2, n02;
	int i, j, k, p, t;
	n0 = (n + 2) / 3; n1 = (n + 1) / 3; n2 = n / 3; n02 = n0 + n2;
	int *s12 = new int[n02 + 3]; s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
	int *sa12 = new int[n02 + 3]; sa12[n02] = sa12[n02 + 1] = sa12[n02 + 2] = 0;
	int *s0 = new int[n0];
	int *sa0 = new int[n0];

	//	generate positions of mod 1 and mod 2 suffixes
	//	the " + (n0 - n1)" adds a dummy mod 1 suffix if n % 3 == 1
	//	... for the convience of calculating s0[]
	for (i = 0, j = 0; i < n + (n0 - n1) ; ++i)
		if (i % 3 != 0) s12[j++] = i;

	// lsb radix sort the mod1 and mod2 triples
	radix_pass(s12, sa12, s + 2, n02, K);
	radix_pass(sa12, s12, s + 1, n02, K);
	radix_pass(s12, sa12, s, n02, K);

	//	find lexicographic names of triples
	int name = 0, c0 = -1, c1 = -1, c2 = -1;
	for (i = 0; i < n02; ++i) {
		if (s[sa12[i]] != c0 || s[sa12[i] + 1] != c1 || s[sa12[i] + 2] != c2) {
			++name;
			c0 = s[sa12[i]];
			c1 = s[sa12[i] + 1];
			c2 = s[sa12[i] + 2];
		}
		if (sa12[i] % 3 == 1) s12[sa12[i] / 3] = name;	// left half
		else s12[sa12[i] / 3 + n0] = name;				// right half
	}

	//	recurse if names are not yet unique
	if (name < n02) {
		suffix_array(s12, sa12, n02, name);
		//	store unique names in s12 using the suffix array
		for (i = 0; i < n02; ++i) s12[sa12[i]] = i + 1;
	} else {
		for (i = 0; i < n02; ++i) sa12[s12[i] - 1] = i;
	}

	//	stable sort the mod 0 suffixes from sa12 by their first character
	for (i = 0, j = 0; i < n02; ++i) if (sa12[i] < n0) s0[j++] = 3 * sa12[i];
	radix_pass(s0, sa0, s, n0, K);

	//	merge sort sa0 suffixes and sorted sa12 suffixes
  //	the dummy mod1 suffix is at the front of sa12[]
	for (p = 0, t = n0 - n1, k = 0; k < n; ++k) {
		i = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		j = sa0[p];
		if (sa12[t] < n0 ? leq(s[i], s12[sa12[t] + n0], s[j], s12[j / 3]):
			leq(s[i], s[i + 1], s12[sa12[t] - n0 + 1], s[j], s[j + 1], s12[j / 3 + n0])) {
			sa[k] = i;
			++t;
			if (t == n02)
				for (++k; p < n0; ++p, ++k) sa[k] = sa0[p];
		} else {
			sa[k] = j;
			++p;
			if (p == n0)
				for (++k; t < n02; ++t, ++k)
					sa[k] = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		}
	}
	delete[] s12;
	delete[] sa12;
	delete[] sa0;
	delete[] s0;
}

void get_height(int s[], int sa[], int rank[], int h[], int n) {
	int i, j, k;
	for (i = 0; i < n; ++i) rank[sa[i]] = i;
	for (j = 0, i = 0; i < n; ++i) {
		if (rank[i] == 0) h[0] = j = 0;
		else {
			k = sa[rank[i] - 1];
			for (j = max(j - 1, 0); s[i + j] == s[k + j]; ++j);
			h[rank[i]] = j;
		}
	}
}

const int N = 200000 + 10;
int s[N], sa[N], rank[N], h[N];
char str[N];
int L[N], R[N];

void run(int a[], int n, int m) {
  suffix_array(s, sa, n, 300);
  get_height(s, sa, rank, h, n);
  int j = rank[m + 1];
  int min_h = INT_MAX;
  for (int k = j + 1; k < n; ++k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
  min_h = INT_MAX;
  for (int k = j - 1; k >= 0; --k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
}

int main() {
  int n, m, num, ret = 0;
  scanf("%s %d", str, &num);
  for (m = 0; str[m]; ++m) s[m] = str[m];
  for (int i = 0; i < num; ++i) {
    n = m;
    str[n++] = 1;
    scanf("%s", str + n);
    for (; str[n]; ++n) s[n] = str[n];
    int len = n - m - 1;
    // printf("%d %d %d\n", m, n, len);
    s[n] = s[n + 1] = s[n + 2] = 0;
    run(L, n, m);
    for (int j = 0; j < m / 2; ++j) swap(s[j], s[m - 1 - j]);
    run(R, n, m);
    for (int j = 0; j < m / 2; ++j) {
      swap(s[j], s[m - 1 - j]);
      swap(R[j], R[m - 1 - j]);
    }
    for (int j = 1; j < m; ++j) L[j] = max(L[j - 1], L[j]);
    for (int j = m - 2; j >= 0; --j) R[j] = max(R[j], R[j + 1]);
    bool found = false;
    for (int j = 0; j + len <= m; ++j) {
      if (L[j] + R[j + len - 1] >= len) {
        found = true;
        break;
      }
    }
    if (found) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 100000 + 10;
const int M = 100 + 10;
char s[N], s2[N];
int a[N], b[N];
char t[M];
int f[M];

void get_f(char t[], int f[], int m) {
  int k = f[0] = 0;
  for (int i = 1; i < m; ++i) {
    for (; k > 0 && t[k] != t[i]; k = f[k - 1]);
    if (t[i] == t[k]) ++k;
    f[i] = k;
  }
}

void kmp(char s[], int a[], int n, char t[], int f[], int m) {
  int k = 0;
  for (int i = 0; i < n; ++i) {
    for (; k > 0 && t[k] != s[i]; k = f[k - 1]);
    if (s[i] == t[k]) ++k;
    a[i] = k;
    if (k == m) k = f[k - 1];
  }
}

bool check(char s[], char t[]) {
  int n = strlen(s);
  int m = strlen(t);
  if (m == 1) return false;
  get_f(t, f, m);
  kmp(s, a, n, t, f, m);
  reverse(t, t + m);
  get_f(t, f, m);
  kmp(s2, b, n, t, f, m);
  for (int i = 1; i < n; ++i) b[i] = max(b[i], b[i - 1]);
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i] + b[n - 2 - i] >= m) return true;
  }
  return false;
}

int main() {
  scanf("%s", s);
  int n = strlen(s);
  copy(s, s + n, s2);
  reverse(s2, s2 + n);
  int Q;
  scanf("%d", &Q);
  int ret = 0;
  while (Q--) {
    scanf("%s", t);
    if (check(s, t)) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}