Problem: During the study of the Martians Petya clearly understood that the Martians are absolutely lazy. They like to sleep and don't like to wake up. 

Imagine a Martian who has exactly n eyes located in a row and numbered from the left to the right from 1 to n. When a Martian sleeps, he puts a patch on each eye (so that the Martian morning doesn't wake him up). The inner side of each patch has an uppercase Latin letter. So, when a Martian wakes up and opens all his eyes he sees a string s consisting of uppercase Latin letters. The string's length is n. 

"Ding dong!" — the alarm goes off. A Martian has already woken up but he hasn't opened any of his eyes. He feels that today is going to be a hard day, so he wants to open his eyes and see something good. The Martian considers only m Martian words beautiful. Besides, it is hard for him to open all eyes at once so early in the morning. So he opens two non-overlapping segments of consecutive eyes. More formally, the Martian chooses four numbers a, b, c, d, (1 ≤ a ≤ b < c ≤ d ≤ n) and opens all eyes with numbers i such that a ≤ i ≤ b or c ≤ i ≤ d. After the Martian opens the eyes he needs, he reads all the visible characters from the left to the right and thus, he sees some word.

Let's consider all different words the Martian can see in the morning. Your task is to find out how many beautiful words are among them.

Input

The first line contains a non-empty string s consisting of uppercase Latin letters. The strings' length is n (2 ≤ n ≤ 105). The second line contains an integer m (1 ≤ m ≤ 100) — the number of beautiful words. Next m lines contain the beautiful words pi, consisting of uppercase Latin letters. Their length is from 1 to 1000. All beautiful strings are pairwise different.

Output

Print the single integer — the number of different beautiful strings the Martian can see this morning.

Examples

Input

ABCBABA
2
BAAB
ABBA


Output

1

Note

Let's consider the sample test. There the Martian can get only the second beautiful string if he opens segments of eyes a = 1, b = 2 and c = 4, d = 5 or of he opens segments of eyes a = 1, b = 2 and c = 6, d = 7. 

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
public class Main{
	static int[][] suffixArrayRecursive(char[]in) {//has a terminating character (e.g. '$')
		int n=in.length;
		//O(n*log(n))
		int k=0;
		while((1<<k)<n) {
			k++;
		}
		return solve(k, in, n);
	}
	static int[][] solve(int k,char[]in,int n){
		if(k==0) {
			int[][]a=new int[n][2];
			for(int i=0;i<in.length;i++) {
				a[i]=new int[] {in[i]-'a',i};
			}
			Arrays.sort(a,(x,y)->x[0]-y[0]);
			int[]p=new int[n],c=new int[n];
			for(int i=0;i<n;i++) {
				p[i]=a[i][1];
			}
			c[a[0][1]]=0;
			for(int i=1;i<n;i++) {
				c[a[i][1]]=(a[i][0]==a[i-1][0])?c[a[i-1][1]]:(c[a[i-1][1]]+1);
			}
			return new int[][] {p,c};
		}
		k--;
		int[][]prev=solve(k, in, n);
		int[]p=prev[0],c=prev[1];
		
		for(int i=0;i<n;i++) {
			p[i]=(p[i]+n-(1<<k))%n;
		}
		p=countingSort(p, c);
		
		int[]newc=new int[n];
		newc[p[0]]=0;
		for(int i=1;i<n;i++) {
			int[]curPair=new int[] {c[p[i]],c[(p[i]+(1<<k))%n]};
			int[]prevPair=new int[] {c[p[i-1]],c[(p[i-1]+(1<<k))%n]};
			newc[p[i]]=(compare(prevPair, curPair)==0)?newc[p[i-1]]:(newc[p[i-1]]+1);
		}
		return new int[][] {p,newc};
	}
	
	static int compare(int[]x,int[]y) {
		return x[0]!=y[0]?x[0]-y[0]:x[1]-y[1];
	}
	static int[] countingSort(int[]p,int[]c) {
		int n=p.length;
		int[]cnt=new int[n];
		for(int i:p) {
			cnt[c[i]]++;
		}
		int[]pointers=new int[n];
		pointers[0]=0;
		for(int i=1;i<n;i++) {
			pointers[i]=pointers[i-1]+cnt[i-1];
		}
		int[]newP=new int[n];
		for(int i:p) {
			newP[pointers[c[i]]++]=i;
		}
		return newP;
	}
	static int[]log,min[],min2[],arr,arr2;
	static int inf=(int)1e9;
	static int query(int l,int r) {
		int len = r - l + 1;
		int lg = log[len];
		int u = min[l][lg];
		int v = min[r - (1 << lg) + 1][lg];
		int bestIdx = arr[u] < arr[v] ? u : v;
		return arr[bestIdx];
	}
	static int query2(int l,int r) {
		int len = r - l + 1;
		int lg = log[len];
		int u = min2[l][lg];
		int v = min2[r - (1 << lg) + 1][lg];
		int bestIdx = arr2[u] < arr2[v] ? u : v;
		return arr2[bestIdx];
	}
	static void preProcess(int n) {
		log = new int[n+1];
		for (int i = 2; i <= n; i++)
			log[i] = log[i / 2] + 1;
		
		min=new int[n][22];
		for(int i=0;i<n;i++) {
			min[i][0]=i;
		}
		for(int i=1,len=2;len<=n;i++,len<<=1) {
			for(int j=0;j<n;j++) {
				int u=min[j][i-1],v=j+(len>>1)>=n?inf:min[j+(len>>1)][i-1];
				if(v==inf) {
					min[j][i]=u;
				}
				else
					min[j][i]=(arr[u]<arr[v]?u:v);
			}
		}
		
		min2=new int[n][22];
		for(int i=0;i<n;i++) {
			min2[i][0]=i;
		}
		for(int i=1,len=2;len<=n;i++,len<<=1) {
			for(int j=0;j<n;j++) {
				int u=min2[j][i-1],v=j+(len>>1)>=n?inf:min2[j+(len>>1)][i-1];
				if(v==inf) {
					min2[j][i]=u;
				}
				else
					min2[j][i]=(arr2[u]<arr2[v]?u:v);
			}
		}
	}
	static char[] rev(String s) {
		char[]ans=new char[s.length()];
		for(int i=0;i<s.length();i++) {
			ans[s.length()-i-1]=s.charAt(i);
		}
		return ans;
	}
	static int[] firstOcc(char[]cur,int[]sa,char[]in,boolean rev) {
		int len=cur.length;
		int[]ans=new int[len];
		Arrays.fill(ans, -1);
		int lo=0,hi=in.length-1;
		for(int i=0;i<len;i++) {
			int firstMatch=-1,lastMatch=-1;
			int curLo=lo,curHi=hi;
			while(curLo<=curHi) {
				int mid=(curLo+curHi)>>1;
				if(sa[mid]+i<in.length && in[sa[mid]+i]==cur[i]) {
					firstMatch=mid;
					curHi=mid-1;
				}
				else {
					if(sa[mid]+i<in.length && in[sa[mid]+i]<cur[i]) {
						curLo=mid+1;
					}
					else {
						curHi=mid-1;
					}
				}
			}
			if(firstMatch==-1)break;
			
			curLo=lo;curHi=hi;
			while(curLo<=curHi) {
				int mid=(curLo+curHi)>>1;
				if(sa[mid]+i<in.length && in[sa[mid]+i]==cur[i]) {
					lastMatch=mid;
					curLo=mid+1;
				}
				else {
					if(sa[mid]+i<in.length && in[sa[mid]+i]<cur[i]) {
						curLo=mid+1;
					}
					else {
						curHi=mid-1;
					}
				}
			}
			lo=firstMatch;
			hi=lastMatch;
			ans[i]=rev?query2(firstMatch, lastMatch):query(firstMatch, lastMatch);
		}
		return ans;
	}
	static void main() throws Exception{
		String s=sc.nextLine();
		char[]in=(s+'$').toCharArray(),inRev=rev('$'+s);
		int[][]arrs=suffixArrayRecursive(in),arrsRev=suffixArrayRecursive(inRev);
		int[]sa=arrs[0],saRev=arrsRev[0];
		arr=sa.clone();
		arr2=saRev.clone();
		preProcess(arr.length);
		int m=sc.nextInt();
		int ans=0;
		while(m-->0) {
			String cur=sc.nextLine();
			int[]firstOccOfPref=firstOcc(cur.toCharArray(), sa, in,false);
			int[]lastOccOfSuff=firstOcc(rev(cur), saRev, inRev,true);
			for(int i=0;i<cur.length();i++) {
				if(lastOccOfSuff[i]!=-1) {
					lastOccOfSuff[i]=s.length()-lastOccOfSuff[i]-1;
				}
			}
//			System.out.println(Arrays.toString(firstOccOfPref)+" "+Arrays.toString(lastOccOfSuff));
			boolean canBeSeen=false;
			for(int prefLen=1;prefLen<cur.length() && firstOccOfPref[prefLen-1]!=-1;prefLen++) {
				int suffLen=cur.length()-prefLen;
				canBeSeen|=(firstOccOfPref[prefLen-1]+prefLen-1<lastOccOfSuff[suffLen-1]-(suffLen-1));
			}
			ans+=canBeSeen?1:0;
		}
		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=Integer.valueOf(nextInt());
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=Long.valueOf(nextLong());
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}