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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EMartianStrings solver = new EMartianStrings();
        solver.solve(1, in, out);
        out.close();
    }

    static class EMartianStrings {
        char[] part;
        char[] s;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {


            String string = in.scanString();
            s = string.toCharArray();
            int m = in.scanInt();
            int n = string.length();




        /*


            1660964.04744
            100 * 100


            KAB
            ABCABFF
            01234


            BAK#FFBAC
            suf[2] = 7 - 1 -  4



         */

            long ans = 0;
            while (m-- > 0) {
                part = in.scanString().toCharArray();
                StringBuilder sb = new StringBuilder(String.valueOf(part));
                sb.append('#');
                sb.append(string);


                int pre[] = new int[part.length];
                Arrays.fill(pre, Integer.MAX_VALUE / 2);
                int zz[] = CodeX.zfunc(sb.toString());
                for (int i = part.length + 1; i < zz.length; i++)
                    if (zz[i] - 1 >= 0) pre[zz[i] - 1] = Math.min(pre[zz[i] - 1], i - (part.length + 1));

                int index = Integer.MAX_VALUE / 2;
                for (int i = pre.length - 1; i >= 0; i--) {
                    index = Math.min(index, pre[i]);
                    pre[i] = index;
                }


                int suff[] = new int[part.length];
                Arrays.fill(suff, Integer.MAX_VALUE / 2);

                sb = new StringBuilder();
                for (int i = part.length - 1; i >= 0; i--) sb.append(part[i]);
                sb.append('#');
                for (int i = s.length - 1; i >= 0; i--) sb.append(s[i]);

                zz = CodeX.zfunc(sb.toString());


                for (int i = part.length + 1; i < zz.length; i++) {
                    if (zz[i] - 1 >= 0) suff[zz[i] - 1] = Math.min(suff[zz[i] - 1], i - (part.length + 1));
                }


                index = Integer.MAX_VALUE / 2;
                for (int i = pre.length - 1; i >= 0; i--) {
                    index = Math.min(index, suff[i]);
                    suff[i] = index;
                }


                for (int i = 0; i < suff.length; i++) {
                    if (suff[i] != Integer.MAX_VALUE / 2) suff[i] = s.length - suff[i] - 1;
                }

                for (int i = 0; i < suff.length; i++) {
                    if (suff[i] != Integer.MAX_VALUE / 2) suff[i] = suff[i] - (i + 1) + 1;
                }


                boolean f = false;
                for (int i = 1; i <= part.length - 1; i++) {
                    int ll = pre[i - 1];
                    int rr = suff[part.length - i - 1];
                    if (ll != Integer.MAX_VALUE / 2 && rr != Integer.MAX_VALUE / 2) {
                        if (rr > ll + (i) - 1) f = true;
                    }
                }
                if (f) ans++;


            }

            out.println(ans);
            /*

            ABCBABA

            0A
            1ABA
            2ABCBABA
            3BA
            4BABA
            5BCBABA
            6CBABA



            AB   BA
             */
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        public String scanString() {
            int c = scan();
            while (isWhiteSpace(c)) c = scan();
            StringBuilder RESULT = new StringBuilder();
            do {
                RESULT.appendCodePoint(c);
                c = scan();
            } while (!isWhiteSpace(c));
            return RESULT.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }

    static class CodeX {
        public static int[] zfunc(String s) {
            int n = s.length();
            int z[] = new int[n];

            for (int i = 1, l = 0, r = 0; i < n; i++) {
                if (i <= r) z[i] = Math.min(r - i + 1, z[i - l]);
                else z[i] = 0;

                while (i + z[i] < n && s.charAt(z[i]) == s.charAt(i + z[i])) ++z[i];

                if (i + z[i] - 1 > r) {
                    l = i;
                    r = i + z[i] - 1;
                }
            }

            return z;
        }

    }
}