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 int mod = 998244353;
const int maxn = 3e5 + 5;
char s[maxn];
int st[maxn], ed[maxn];
int rk[maxn], tp[maxn], tax[maxn];
int height[maxn], sa[maxn], f[maxn][21], bin[maxn];
int mn[maxn][21], mx[maxn][21];
int M;
void qsort(int n) {
  for (int i = 0; i <= M; i++) tax[i] = 0;
  for (int i = 1; i <= n; i++) tax[rk[i]]++;
  for (int i = 1; i <= M; i++) tax[i] += tax[i - 1];
  for (int i = n; i >= 1; i--) sa[tax[rk[tp[i]]]--] = tp[i];
}
void get_sa(int n) {
  for (int i = 1; i <= n; i++) {
    M = max(M, rk[i] = s[i]);
    tp[i] = i;
  }
  qsort(n);
  for (int w = 1, p = 0; p < n; M = p, w <<= 1) {
    p = 0;
    for (int i = 1; i <= w; i++) tp[++p] = n - w + i;
    for (int i = 1; i <= n; i++) {
      if (sa[i] > w) tp[++p] = sa[i] - w;
    }
    qsort(n);
    for (int i = 0; i <= n; i++) tp[i] = rk[i];
    rk[sa[1]] = p = 1;
    for (int i = 2; i <= n; i++) {
      rk[sa[i]] =
          (tp[sa[i - 1]] == tp[sa[i]] && tp[sa[i - 1] + w] == tp[sa[i] + w])
              ? p
              : ++p;
    }
  }
}
void get_height(int n) {
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (k) k--;
    int j = sa[rk[i] - 1];
    while (j && s[i + k] == s[j + k]) k++;
    height[rk[i]] = k;
  }
}
void build(int n) {
  for (int i = 1; i <= n; i++) {
    f[i][0] = height[i];
    mn[i][0] = sa[i];
    mx[i][0] = sa[i] <= ed[0] ? sa[i] : 0;
  }
  for (int j = 1; j <= bin[n]; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      int t = i + (1 << (j - 1));
      f[i][j] = min(f[i][j - 1], f[t][j - 1]);
      mn[i][j] = min(mn[i][j - 1], mn[t][j - 1]);
      mx[i][j] = max(mx[i][j - 1], mx[t][j - 1]);
    }
  }
}
int query1(int x, int y) {
  if (x == y) return 0;
  x++;
  int j = bin[y - x + 1];
  int k = y - (1 << j) + 1;
  return min(f[x][j], f[k][j]);
}
int query2(int x, int y) {
  int j = bin[y - x + 1];
  int k = y - (1 << j) + 1;
  return min(mn[x][j], mn[k][j]);
}
int query3(int x, int y) {
  int j = bin[y - x + 1];
  int k = y - (1 << j) + 1;
  return max(mx[x][j], mx[k][j]);
}
int main() {
  scanf("%s", s + 1);
  ed[0] = strlen(s + 1);
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    s[ed[i - 1] + 1] = '*';
    st[i] = ed[i - 1] + 2;
    scanf("%s", s + st[i]);
    ed[i] = strlen(s + 1);
  }
  int n = strlen(s + 1);
  bin[0] = -1;
  for (int i = 1; i <= n; i++) bin[i] = bin[i >> 1] + 1;
  get_sa(n);
  get_height(n);
  build(n);
  int ans = 0;
  for (int t = 1; t <= m; t++) {
    int flag = 0;
    for (int i = st[t] + 1; i <= ed[t]; i++) {
      int tmp = rk[st[t]], len = ed[t] - st[t] + 1;
      int L = tmp, R = tmp;
      int l = 1, r = tmp - 1, mid, res = 0;
      while (l <= r) {
        mid = (l + r) >> 1;
        if (query1(mid, tmp) >= i - st[t])
          res = mid, r = mid - 1;
        else
          l = mid + 1;
      }
      if (query1(res, tmp) >= i - st[t]) L = res;
      l = tmp + 1, r = n, res = n;
      while (l <= r) {
        mid = (l + r) >> 1;
        if (query1(tmp, mid) >= i - st[t])
          res = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      if (query1(tmp, res) >= i - st[t]) R = res;
      int mnn = query2(L, R);
      if (mnn > ed[0]) continue;
      tmp = rk[i];
      L = tmp, R = tmp;
      l = 1, r = tmp - 1, mid, res = 0;
      while (l <= r) {
        mid = (l + r) >> 1;
        if (query1(mid, tmp) >= len - i + st[t])
          res = mid, r = mid - 1;
        else
          l = mid + 1;
      }
      if (query1(res, tmp) >= len - i + st[t]) L = res;
      l = tmp + 1, r = n, res = n;
      while (l <= r) {
        mid = (l + r) >> 1;
        if (query1(tmp, mid) >= len - i + st[t])
          res = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      if (query1(tmp, res) >= len - i + st[t]) R = res;
      int mxx = query3(L, R);
      if (mxx <= mnn + i - st[t] - 1)
        continue;
      else
        flag = 1;
      if (flag) break;
    }
    ans += flag;
  }
  printf("%d\n", ans);
  return 0;
}