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.util.*;
import java.io.*;
/*

BA
10
ABA
BABB
BAAB
AABBAA
B
BAA
AABBB
AAAAABBAA
ABBABA
AABB
0


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

 */
public class a 
{
	public static void main(String[] arg) throws IOException
	{
		new a();
	}
	public a() throws IOException
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		char[] t = in.next().toCharArray();
		char[] rt = new StringBuilder(new String(t)).reverse().toString().toCharArray();
		int n = t.length;
		int m = in.nextInt();
		int ret = 0;
		for(int ii = 0; ii < m; ii++)
		{
			char[] p = in.next().toCharArray();
			if(p.length == 1) continue;
			if(p.length > t.length) continue;
			//System.out.println("what");
			char[] rp = new StringBuilder(new String(p)).reverse().toString().toCharArray();
			// Longest prefix match at each index
			int[] pre = new ZValue(fuse(p, t)).z;
			
			// Longest suffix match that ends at each index
			int[] suff = new ZValue(fuse(rp, rt)).z;
			int[] bp = new int[p.length+1];
			int[] bs = new int[p.length+1];
			Arrays.fill(bp, oo);
			Arrays.fill(bs, -1);
			boolean flag = false;
			for(int i = p.length+1; i < pre.length; i++)
			{
				bp[pre[i]] = Math.min(bp[pre[i]], (i-(p.length+1)));
			}
			for(int i = bp.length-2; i >= 0; i--)
			{
				bp[i] = Math.min(bp[i], bp[i+1]);
			}
			for(int i = p.length+1; i < suff.length; i++)
			{
				bs[suff[i]] = Math.max(bs[suff[i]], (t.length-1-(i-p.length-1)));
			}
			for(int i = bs.length-2; i >= 0; i--)
			{
				bs[i] = Math.max(bs[i], bs[i+1]);
			}
			//System.out.println(Arrays.toString(pre));
			//System.out.println(Arrays.toString(suff));
			//System.out.println(Arrays.toString(bp));
			//System.out.println(Arrays.toString(bs));
			for(int i = 1; i < p.length; i++)
			{
				if(bp[i] == oo) continue;
				if(bs[p.length-i] == -1) continue;
				if(bp[i]+i-1 < bs[p.length-i]-(p.length-i)+1) flag = true;
			}
			if(flag)
			{
				ret++;
			}
		}
		out.println(ret);
		in.close(); out.close();
	}
	
	
	int oo = 1_000_000;
	char[] fuse(char[] p, char[] s)
	{
		char[] ret = new char[p.length+s.length+1];
		for(int i = 0; i < p.length; i++) ret[i] = p[i];
		ret[p.length] = '$';
		for(int i = 0; i < s.length; i++) ret[i+p.length+1] = s[i];
		return ret;
	}
	int[] get(int[] s)
	{
		int[] ret = new int[s.length-1];
		for(int i = 0; i < s.length-1; i++) ret[i] = s[i]-s[i+1];
		return ret;
	}
	class ZValue 
	{
		int[] z;
		public ZValue(char[] s)
		{
			int n = s.length;
			z = new int[n];
			int L = 0, R = 0;
			for (int i = 1; i < n; i++) {
			  if (i > R) {
			    L = R = i;
			    while (R < n && s[R-L] == s[R]) R++;
			    z[i] = R-L; R--;
			  } else {
			    int k = i-L;
			    if (z[k] < R-i+1) z[i] = z[k];
			    else {
			      L = i;
			      while (R < n && s[R-L] == s[R]) R++;
			      z[i] = R-L; R--;
			    }
			  }
			}
		}
	}
	class AhoCorasick 
	{
		public final int ALPHA = 26;
		public int nodeCount;
		public int[][] transition;
		public boolean[] term;
		public AhoCorasick(String[] strs)
		{
			int maxNodes = 1;
			for(String s : strs) maxNodes += s.length();
			int[][] children = new int[ALPHA][maxNodes];
			boolean[] leaf = new boolean[maxNodes];
			nodeCount = 1;
			for(String s : strs)
			{
				int node = 0;
				for(char ch : s.toCharArray())
				{
					int c = ch - 'a';
					if(children[c][node] == 0)
					{
						children[c][node] = nodeCount;
						nodeCount++;
					}
					node = children[c][node];
				}
				leaf[node] = true;
			}
			transition = new int[ALPHA][nodeCount];
			term = new boolean[nodeCount];
			ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
			queue.add(0); queue.add(0);
			while(queue.size() > 0)
			{
				int node = queue.remove();
				int suffLink = queue.remove();
				term[node] = leaf[node] || term[suffLink];
				for(int ch = 0; ch < ALPHA; ch++)
				{
					if(children[ch][node] != 0)
					{
						transition[ch][node] = children[ch][node];
						queue.add(children[ch][node]);
						queue.add(node == 0 ? 0 : transition[ch][suffLink]);
					}
					else
					{
						transition[ch][node] = transition[ch][suffLink];
					}
				}
			}
		}
	}
	class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}
		public String next() throws IOException
		{
			while(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
		public void close() throws IOException
		{
			br.close();
		}
	}
}