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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const double INF = 1e9;
struct SuffixArray {
  int n, h;
  vector<int> lcp, sa, invsa;
  string ori;
  vector<vector<int> > rmq;
  bool cmp(int a, int b) { return invsa[a + h] < invsa[b + h]; }
  void ternary_sort(int a, int b) {
    if (a == b) return;
    int pivot = sa[a + rand() % (b - a)];
    int left = a, right = b;
    for (int i = a; i < b; i++)
      if (cmp(sa[i], pivot)) swap(sa[i], sa[left++]);
    for (int i = b - 1; i >= left; --i)
      if (cmp(pivot, sa[i])) swap(sa[i], sa[--right]);
    ternary_sort(a, left);
    for (int i = left; i < right; i++) invsa[sa[i]] = right - 1;
    if (right - left == 1) sa[left] = -1;
    ternary_sort(right, b);
  }
  SuffixArray() {}
  SuffixArray(string s) : n(s.size()), sa(n) {
    ori = s;
    vector<int> v(n);
    for (int i = 0; i < n; i++) v[i] = (int)s[i];
    ini(v);
  }
  SuffixArray(vector<int> v) : n(v.size()), sa(n) { ini(v); }
  void ini(vector<int>& v) {
    v.push_back(INT_MIN);
    for (int i = 0; i < n; i++) sa[i] = i;
    invsa = v;
    h = 0;
    ternary_sort(0, n);
    for (h = 1; h <= n; h *= 2)
      for (int j = 0, i = j; i != n; i = j)
        if (sa[i] < 0) {
          while (j < n && sa[j] < 0) j += -sa[j];
          sa[i] = -(j - i);
        } else {
          j = invsa[sa[i]] + 1;
          ternary_sort(i, j);
        }
    for (int i = 0; i < n; i++) sa[invsa[i]] = i;
    lcp.resize(n);
    int res = 0;
    for (int i = 0; i < n; i++) {
      if (invsa[i] > 0)
        while (v[i + res] == v[sa[invsa[i] - 1] + res]) res++;
      lcp[invsa[i]] = res;
      res = max(res - 1, 0);
    }
    int logn = __builtin_clz(1) - __builtin_clz(n);
    rmq.resize(n, vector<int>(logn + 1));
    for (int i = 0; i < n; i++) rmq[i][0] = sa[i];
    for (int l = 1; l <= logn; l++)
      for (int i = 0; i + (1 << l) <= n; i++)
        rmq[i][l] = min(rmq[i][l - 1], rmq[i + (1 << (l - 1))][l - 1]);
  }
  int operator[](int id) { return sa[id]; }
  int rmq_query(int a, int b) {
    int l = __builtin_clz(1) - __builtin_clz(b - a + 1);
    return min(rmq[a][l], rmq[b - (1 << l) + 1][l]);
  }
  inline char get(int mm, int i) {
    int p = sa[mm] + i;
    if (p >= n) return 0;
    return ori[p];
  }
  void busca(int& l, int& r, int i, const string& s) {
    int ini, fim, meio, best = n;
    ini = l, fim = r;
    while (ini <= fim) {
      int meio = (ini + fim) >> 1;
      if (get(meio, i) >= s[i])
        best = meio, fim = meio - 1;
      else
        ini = meio + 1;
    }
    ini = l, fim = r;
    l = best;
    best = -1;
    while (ini <= fim) {
      int meio = (ini + fim) >> 1;
      if (get(meio, i) <= s[i])
        best = meio, ini = meio + 1;
      else
        fim = meio - 1;
    }
    r = best;
  }
  void acha(const string& s, vector<int>& vet) {
    vet.resize(((int)(s).size()));
    int l = 0, r = n - 1;
    for (int(i) = (0); (i) < (((int)(s).size())); (i)++) {
      busca(l, r, i, s);
      if (l > r)
        vet[i] = n + 1;
      else
        vet[i] = rmq_query(l, r);
    }
  }
};
string s, sr, cur, curr;
int m, ans;
vector<int> vet, vetr;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s >> m;
  sr = s;
  reverse((sr).begin(), (sr).end());
  SuffixArray suf(s), sufr(sr);
  while (m--) {
    cin >> cur;
    curr = cur;
    reverse((curr).begin(), (curr).end());
    suf.acha(cur, vet);
    sufr.acha(curr, vetr);
    for (int(i) = (0); (i) < (((int)(cur).size())); (i)++) {
      int j = ((int)(cur).size()) - 2 - i;
      if (j >= 0 && vet[i] + i < ((int)(s).size()) - 1 - vetr[j] - j) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}