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 maxn = 100005;
char s[maxn];
int sa[maxn], t[maxn], t2[maxn], c[maxn];
int N;
void build_sa(int n, int m) {
  int i, *x = t, *y = t2;
  for (i = 0; i < m; i++) c[i] = 0;
  for (i = 0; i < n; i++) c[x[i] = s[i]]++;
  for (i = 1; i < m; i++) c[i] += c[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;
  int p;
  for (int k = 1; k <= n; k <<= 1) {
    p = 0;
    for (i = n - k; i < n; i++) y[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= k) y[p++] = sa[i] - k;
    for (i = 0; i < m; i++) c[i] = 0;
    for (i = 0; i < n; i++) c[x[y[i]]]++;
    for (i = 0; i < m; i++) c[i] += c[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];
    swap(x, y);
    p = 1;
    x[sa[0]] = 0;
    for (i = 1; i < n; i++)
      x[sa[i]] = y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k]
                     ? p - 1
                     : p++;
    if (p >= n) break;
    m = p;
  }
}
int dp[maxn << 1][20];
int dp2[maxn << 1][20];
void makermq() {
  int i, j;
  for (i = 1; i <= N; i++) dp[i][0] = dp2[i][0] = sa[i];
  for (j = 1; (1 << j) <= N; j++)
    for (i = 1; i + (1 << j) - 1 <= N; i++) {
      dp[i][j] = max(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
      dp2[i][j] = min(dp2[i][j - 1], dp2[i + (1 << (j - 1))][j - 1]);
    }
}
int rmq1(int l, int r) {
  int k = (int)(log((r - l + 1) * 1.0) / log(2.0));
  return max(dp[l][k], dp[r - (1 << k) + 1][k]);
}
int rmq2(int l, int r) {
  int k = (int)(log((r - l + 1) * 1.0) / log(2.0));
  return min(dp2[l][k], dp2[r - (1 << k) + 1][k]);
}
char wt[1005];
int p1, p2;
int cmp(int len, char *s1, char *s2) { return strncmp(s1, s2, len); }
int cal(char *s1, int len, int flag) {
  int i, j;
  int l = 1, r = N;
  int mid, d, k = -1;
  int ans;
  if (cmp(len, s1, s + sa[1]) < 0 || cmp(len, s1, s + sa[N]) > 0) {
    return -1;
  }
  while (l <= r) {
    mid = (l + r) >> 1;
    d = cmp(len, s1, s + sa[mid]);
    if (d > 0)
      l = mid + 1;
    else if (d < 0)
      r = mid - 1;
    else {
      k = mid;
      break;
    }
  }
  if (k == -1) return -1;
  int ka, kb;
  if (flag == 1) {
    ans = sa[k];
    l = k, r = N;
    while (l <= r) {
      mid = (l + r) >> 1;
      d = cmp(len, s1, s + sa[mid]);
      if (d != 0)
        r = mid - 1;
      else {
        kb = mid;
        l = mid + 1;
      }
    }
    l = 1, r = k;
    while (l <= r) {
      mid = (l + r) >> 1;
      d = cmp(len, s1, s + sa[mid]);
      if (d != 0)
        l = mid + 1;
      else {
        ka = mid;
        r = mid - 1;
      }
    }
    ans = rmq2(ka, kb);
  } else {
    l = k, r = N;
    ans = sa[k];
    while (l <= r) {
      mid = (l + r) >> 1;
      d = cmp(len, s1, s + sa[mid]);
      if (d != 0)
        r = mid - 1;
      else {
        kb = mid;
        l = mid + 1;
      }
    }
    l = 1, r = k;
    while (l <= r) {
      mid = (l + r) >> 1;
      d = cmp(len, s1, s + sa[mid]);
      if (d != 0)
        l = mid + 1;
      else {
        ka = mid;
        r = mid - 1;
      }
    }
    ans = rmq1(ka, kb);
  }
  return ans;
}
bool find(char *s1) {
  int i, j, k;
  int tp = 0;
  int len = strlen(s1);
  for (i = 0; i < len - 1; i++) {
    wt[tp++] = s1[i];
    wt[tp] = '\0';
    p1 = cal(wt, tp, 1);
    if (p1 == -1) return false;
    p2 = cal(s1 + i + 1, len - tp, 2);
    if (p1 + tp <= p2) {
      return true;
    }
  }
  return false;
}
char w[1005];
int main() {
  int i, m, res;
  while (scanf("%s", s) != EOF) {
    scanf("%d", &m);
    N = strlen(s);
    build_sa(N + 1, 'Z' + 1);
    makermq();
    res = 0;
    while (m--) {
      scanf("%s", w);
      if (find(w)) {
        res++;
      }
    }
    printf("%d\n", res);
  }
  return 0;
}