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.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;



public class E {
    private static final Scanner sc = new Scanner(System.in);

    static final RMQ<Integer> min = new RMQ<Integer>(Integer.MAX_VALUE);
    static final RMQ<Integer> max = new RMQ<Integer>(Integer.MAX_VALUE);
    
    static int[] range(final int[] sa, final String str, final String pat) {
        int l, h;
        for(l = 0, h = sa.length; l < h; ) {
            final int m = (l + h) / 2;
            final String sub = str.substring(sa[m], Math.min(sa[m] + pat.length(), str.length()));
            if(sub.compareTo(pat) < 0) {
                l = m + 1;
            } else {
                h = m;
            }
        }
        
        final int left = l;
        for(h = sa.length; l < h; ) {
            final int m = (l + h) / 2;
            if(str.regionMatches(sa[m], pat, 0, pat.length())) {
                l = m + 1;
            } else {
                h = m;
            }
        }
        
        final int right = l;
        return new int[] { left, right };
    }
    
    static int left(final int[] sa, final String str, final String pat) {
        final int[] r = range(sa, str, pat);
        final int res = min.Query(r[0], r[1]);
        return res == Integer.MAX_VALUE ? Integer.MAX_VALUE / 2 : res;
    }
    
    static int right(final int[] sa, final String str, final String pat) {
        final int[] r = range(sa, str, pat);
        final int res = max.Query(r[0], r[1]);
        return res == Integer.MAX_VALUE ? Integer.MIN_VALUE / 2 : -res;
    }
    
    static String genString() {
        char[] str = new char[(int)1e5];
        for(int i = 0; i < str.length; i++) {
            str[i] = 'A';
        }
        return new String(str);
    }
    
    static String genString2() {
        char[] str = new char[1000];
        for(int i = 0; i < str.length; i++) {
            str[i] = i == str.length - 1 ? 'B' : 'A';
        }
        return new String(str);
    }
    
    static final boolean DEBUG = false;
    public static void main(String[] args) {
        final String str = DEBUG ? genString() : sc.next();
        int[] input = new int[str.length()+1];
        for(int i = 0; i < str.length(); i++) {
            input[i] = str.charAt(i);
        }
        
        final int[] sa = SuffixArray.constructSA(input, input.length, 256);
        
        min.build(sa.length);
        max.build(sa.length);
        
        for(int i = 0; i < sa.length; i++) {
            min.Update(sa[i], i);
            max.Update(-sa[i], i);
        }
        
        int T = DEBUG ? 100 : sc.nextInt(), res = 0;
        while(T-- != 0) {
            final String pat = DEBUG ? genString2() : sc.next();
            for(int i = 1; i <= pat.length() / 2; i++) {
                {
                    final int l = left(sa, str, pat.substring(0, i));
                    final int r = right(sa, str, pat.substring(i));
                    if(l + i <= r) {
    //                  System.err.println(pat.substring(0, i) + " " + pat.substring(i) + ": " + left(sa, str, pat.substring(0, i)) + " " + right(sa, str, pat.substring(i)));
                        res++;
                        break;
                    } else if(l > str.length()) {
                        break;
                    }
                }
                
                {
                    final int l = left(sa, str, pat.substring(0, pat.length() - i));
                    final int r = right(sa, str, pat.substring(pat.length() - i));
                    if(l + pat.length() - i <= r) {
    //                  System.err.println(pat.substring(0, i) + " " + pat.substring(i) + ": " + left(sa, str, pat.substring(0, i)) + " " + right(sa, str, pat.substring(i)));
                        res++;
                        break;
                    } else if(r < 0) {
//                      System.out.println(i);
                        break;
                    }
                }
            }
        }
        
        System.out.println(res);
    }
    
    public static class RMQ<T> {
        int n;
        List<T> xs;
        final T INF;
        final Comparator<T> cmp;

        public RMQ(T inf) {
            INF = inf;
            cmp = new Comparator<T>() {
                @SuppressWarnings("unchecked")
//              @Override
                public int compare(T o1, T o2) {
                    return ((Comparable<T>)o1).compareTo(o2);
                }
            };
        }
        
        public RMQ(T inf, Comparator<T> comparator) { cmp = comparator; INF = inf; }
        T Min(T a, T b) { return a == INF ? b : (b == INF ? a : (cmp.compare(a,b)<=0?a:b)); }
        
        public void build(int m) {
            for(n = 1; n<m; n<<=1) ;
            xs = new ArrayList<T>(2*n);
            for(int i = 0; i < 2*n; i++) {
                xs.add(INF);
            }
        }

        // idx: [0,n)
        public void Update(T v, int idx) {
            xs.set(idx += n - 1, v);
            while(idx > 0) {
                idx = (idx-1)/2;
                xs.set(idx, Min(xs.get(idx*2+1), xs.get(idx*2+2)));
            }
        }
        
        // [l,r)
        public T Query(int l, int r) { return Query(l, r, 0, n, 0); }
        T Query(int l, int r, int a, int b, int k) {
            if(l <= a && b <= r) return xs.get(k);
            if(b <= l || r <= a) return INF;
            final int m = (a+b)/2;
            return Min(
                    Query(l, r, a, m, 2*k+1),
                    Query(l, r, m, b, 2*k+2));
        }
    }

    
    public static class SuffixArray {
        private static final char[] mask = new char[] { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
        
        private static boolean tget(final byte[] t, final int i) { return (t[i>>>3]&mask[i&7]) != 0; }
        private static void tset(final byte[] t, final int i, final boolean b) { 
            if(b) {
                t[i>>>3] |= mask[i&7];
            } else {
                t[i>>>3] &= ~mask[i&7];
            }
        }
        
        private static boolean isLMS(final byte[] t, final int i) { return i > 0 && tget(t, i) && !tget(t, i-1); }
        
        private static void getBuckets(final Slice s, int[] bkt, int n, int K, boolean end) {
            Arrays.fill(bkt, 0);
            for(int i = 0; i < n; i++) {
                bkt[s.get(i)]++;
            }
            for(int i = 0, sum = 0; i <= K; i++) {
                sum += bkt[i];
                bkt[i] = end ? sum : sum - bkt[i];
            }
        }
        
        private static void induceSAl(final byte[] t, final Slice SA, final Slice s, int[] bkt, int n, int K, boolean end) {
            getBuckets(s, bkt, n, K, end);
            for(int i = 0; i < n; i++) {
                final int j = SA.get(i) - 1;
                if(j >= 0 && !tget(t, j)) {
                    SA.set(bkt[s.get(j)]++, j);
                }
            }
        }
        
        private static void induceSAs(final byte[] t, final Slice SA, final Slice s, int[] bkt, int n, int K, boolean end) {
            getBuckets(s, bkt, n, K, end);
            for(int i = n - 1; i >= 0; i--) {
                final int j = SA.get(i) - 1;
                if(j >= 0 && tget(t, j)) {
                    SA.set(--bkt[s.get(j)], j);
                }
            }
        }
        
        private static void build(final Slice s, final Slice SA, final int n, final int K) {
            final byte[] t = new byte[n/8+1];
            
            tset(t, n-2, false);
            tset(t, n-1, true);
            
            for(int i = n - 3; i >= 0; i--) {
                tset(t, i, s.get(i) < s.get(i+1) || s.get(i) == s.get(i+1) && tget(t, i+1));
            }
            
            // stage 1
            final int[] bkt = new int[K + 1];
            getBuckets(s, bkt, n, K, true);
            for(int i = 0; i < n; i++) {
                SA.set(i, -1);
            }
            
            for(int i = 1; i < n; i++) {
                if(isLMS(t, i)) {
                    SA.set(--bkt[s.get(i)], i);
                }
            }

            induceSAl(t, SA, s, bkt, n, K, false);
            induceSAs(t, SA, s, bkt, n, K, true);
            
            int n1 = 0;
            for(int i = 0; i < n; i++) {
                if(isLMS(t, SA.get(i))) {
                    SA.set(n1++, SA.get(i));
                }
            }
            
            for(int i = n1; i < n; i++) {
                SA.set(i, -1);
            }
            
            int name = 0, prev = -1;
            for(int i = 0; i < n1; i++) {
                int pos = SA.get(i);
                boolean diff = false;
                for(int d = 0; d < n; d++) {
                    if(prev == -1
                    || s.get(pos+d) != s.get(prev+d)
                    || (tget(t, pos+d) ^ tget(t, prev+d))) {
                        diff = true;
                        break;
                    } else if(d > 0 && (isLMS(t, pos+d) || isLMS(t, prev+d))) {
                        break;
                    }
                }
                if(diff) { name++; prev = pos; }
                pos >>>= 1;
                SA.set(n1+pos, name - 1);
            }
            
            for(int i = n - 1, j = n - 1; i >= n1; i--) {
                if(SA.get(i) >= 0) {
                    SA.set(j--, SA.get(i));
                }
            }
            
            // stage 2
            final Slice SA1 = new Slice(SA, 0);
            final Slice s1 = new Slice(SA, n - n1);
            if(name < n1) {
                build(s1, SA1, n1, name - 1);
            } else {
                for(int i = 0; i < n1; i++) {
                    SA1.set(s1.get(i), i);
                }
            }
            
            // stage 3
//          bkt = new int[K + 1];
            getBuckets(s, bkt, n, K, true);
            for(int i = 1, j = 0; i < n; i++) {
                if(isLMS(t, i)) {
                    s1.set(j++, i);
                }
            }
            
            for(int i = 0; i < n1; i++) {
                SA1.set(i, s1.get(SA1.get(i)));
            }
            
            for(int i = n1; i < n; i++) {
                SA.set(i, -1);
            }
            for(int i = n1 - 1, j; i >= 0; i--) {
                j = SA.get(i);
                SA.set(i, -1);
                SA.set(--bkt[s.get(j)], j);
            }
            induceSAl(t, SA, s, bkt, n, K, false);
            induceSAs(t, SA, s, bkt, n, K, true);
        }
        
        /*
         * n: 文字数+1 (sentinel)
         * K: 文字種+1 (sentinel)
         */
        public static int[] constructSA(final int[] s_, final int n, final int K) {
            final Slice s = new Slice(s_, 0);
            final Slice SA = new Slice(new int[n], 0);
            build(s, SA, n, K);
            return Arrays.copyOfRange(SA.ary, 1, SA.ary.length);
        }
        
        
        
        
        
        
        private static class Slice {
            private final int shift;
            private final int[] ary;
            
            public int get(final int idx) { return ary[shift + idx]; }
            public void set(final int idx, final int val) { ary[shift + idx] = val; }
            
            public Slice(final int[] ary, final int shift) {
                this.ary = ary;
                this.shift = shift;
            }
            
            public Slice(final Slice s, final int shift) {
                this.ary = s.ary;
                this.shift = s.shift + shift;
            }
        }
    }
}