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.math.BigInteger;
import java.util.*;

public class E implements Runnable{
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		String s = fs.next();
		int n = s.length();
		int m = fs.nextInt();
		int res = 0;

		while(m-->0) {
			String t = fs.next();
			int k = t.length();
			if(k == 1) continue;
			
			int[] prefZ = getZ((t + "#" + s).toCharArray());
			int[] pref = new int[k + 1]; Arrays.fill(pref, n + 1);
			for(int i = k + 1; i < prefZ.length; i++) {
				pref[prefZ[i]] = Math.min(i - (k + 1), pref[prefZ[i]]);
			}
			for(int i = pref.length - 2; i > 0; i--)
				pref[i] = Math.min(pref[i], pref[i + 1]);
			
			int[] suffZ = getZ((rev(t) + "#" + rev(s)).toCharArray());
			suffZ = Arrays.copyOfRange(suffZ, k + 1, suffZ.length);
			for(int i = 0; i < suffZ.length / 2; i++) {
				int ii = suffZ.length - i - 1;
				int j = suffZ[ii];
				suffZ[ii] = suffZ[i];
				suffZ[i] = j;
			}
			int[] suff = new int[k + 1]; Arrays.fill(suff, -1);
			for(int i = 0; i < suffZ.length; i++) {
				suff[suffZ[i]] = Math.max(i, suff[suffZ[i]]);
			}
			for(int i = suff.length - 2; i > 0; i--) {
				suff[i] = Math.max(suff[i], suff[i + 1]);
			}

			if(pref[k] != n + 1) {
				res++;
				continue;
			}

			for(int i = 1; i < k; i++) {
				if(pref[i] == n + 1) continue;
				int left = pref[i];
				int right = suff[k - i];
				if(left + i <= right - (k - i)) {
					res++;
					break;
				}
			}
			
		}
		
		out.println(res);
		out.close();
	}
	
	String rev(String s) { return new StringBuilder(s).reverse().toString(); }

	int[] getZ (char[] a) {
		int[] z = new int[a.length];
		int left = 0, right = 0; //left and right bounds for my z box
		for(int k = 1; k < a.length; k++) {
			if(k > right) {
				//we have to do actual comparisons here
				left = right = k;
				while(right < a.length && a[right] == a[right - left]) {
					//while my right pointer is matching the prefix of the string
					right++;
				}
				z[k] = right - left; //the length that was matched
				right--;
			}
			else {
				//reuse values because k lies inside my z box
				int k1 = k - left; //the position that we can reuse
				if(z[k1] < right - k + 1) {
					//the z value for this previous position can't get any more matches so just copy it.
					z[k] = z[k1];
				}
				else {
					//we have to check to see if there are more matches
					left = k;
					while(right < a.length && a[right] == a[right - left]) {
						right++;
					}
					z[k] = right - left;
					right--;
				}
			}
		}
		return z;
	}
	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}