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;
using ll = int64_t;
struct suffix_array {
  suffix_array(const string& str) {
    s = str;
    s += '$';
    n = s.size();
  }

 public:
  string s;
  int n;
  vector<int> pos, rank, lcp;
  void count_sort(vector<int>& pos, const vector<int>& rank) {
    vector<int> idx(n + 1);
    for (auto& x : rank) idx[x + 1]++;
    for (int i = 1; i <= n; i++) idx[i] += idx[i - 1];
    vector<int> new_pos(n);
    for (auto& x : pos) new_pos[idx[rank[x]]++] = x;
    pos.swap(new_pos);
  }
  void build() {
    pos.resize(n);
    rank.resize(n);
    iota(pos.begin(), pos.end(), 0);
    sort(pos.begin(), pos.end(), [&](int a, int b) { return s[a] < s[b]; });
    rank[pos[0]] = 0;
    for (int i = 1; i < n; i++)
      rank[pos[i]] = rank[pos[i - 1]] + (s[pos[i]] != s[pos[i - 1]]);
    for (int k = 1; k < n; k *= 2) {
      for (int i = 0; i < n; i++) pos[i] = (pos[i] - k + n) % n;
      count_sort(pos, rank);
      vector<int> new_rank(n);
      new_rank[pos[0]] = 0;
      for (int i = 1; i < n; i++) {
        pair<int, int> prev = {rank[pos[i - 1]], rank[(pos[i - 1] + k) % n]};
        pair<int, int> now = {rank[pos[i]], rank[(pos[i] + k) % n]};
        new_rank[pos[i]] = new_rank[pos[i - 1]] + (prev != now);
      }
      rank.swap(new_rank);
    }
  }
  void build_lcp() {
    lcp.resize(n);
    int k = 0;
    for (int i = 0; i < n - 1; i++) {
      int pi = rank[i];
      int j = pos[pi - 1];
      while (s[i + k] == s[j + k]) k++;
      lcp[pi] = k;
      k = max(0, k - 1);
    }
  }
  void debug() {
    for (int i = 0; i < n; i++)
      cout << pos[i] << " " << s.substr(pos[i], n - pos[i]) << "\n";
  }
};
struct seg_tree {
  seg_tree(vector<int>& v) {
    arr = v;
    n = v.size();
    seg.resize(4 * n);
  }

 public:
  vector<int> arr, seg;
  int n;
  void build() { build(0, n, 0); }
  void build(int l, int r, int x) {
    if (l == r - 1) {
      seg[x] = arr[l];
      return;
    }
    int m = (l + r) / 2;
    build(l, m, 2 * x + 1);
    build(m, r, 2 * x + 2);
    seg[x] = min(seg[2 * x + 1], seg[2 * x + 2]);
  }
  int query(int l, int r) { return query(l, r, 0, 0, n); }
  int query(int l, int r, int x, int lx, int rx) {
    if (lx >= r || rx <= l) return 1e9 + 5;
    if (lx >= l && rx <= r) return seg[x];
    int m = (lx + rx) / 2;
    return min(query(l, r, 2 * x + 1, lx, m), query(l, r, 2 * x + 2, m, rx));
  }
  void modify(int pos, int val) { modify(pos, val, 0, 0, n); }
  void modify(int pos, int val, int x, int lx, int rx) {
    if (lx == rx - 1) {
      seg[x] = val;
      return;
    }
    int m = (lx + rx) / 2;
    if (pos < m)
      modify(pos, val, 2 * x + 1, lx, m);
    else
      modify(pos, val, 2 * x + 2, m, rx);
    seg[x] = min(seg[2 * x + 1], seg[2 * x + 2]);
  }
};
vector<int> getPos(vector<int>& sa, seg_tree& rmq, const string& s,
                   const string& t) {
  int matchLen = t.size(), n = s.size(), from = 1, to = n + 1;
  vector<int> bst(matchLen, -1);
  for (int len = 0; len < matchLen; len++) {
    int lb = -1, ub = -1, l = from, r = to;
    while (l < r) {
      int m = (l + r) / 2;
      int idx = len + sa[m];
      if (idx < n && s[idx] >= t[len])
        r = m;
      else
        l = m + 1;
    }
    lb = l;
    l = from, r = to;
    while (l < r) {
      int m = (l + r) / 2;
      int idx = len + sa[m];
      if (idx < n && s[idx] > t[len])
        r = m;
      else
        l = m + 1;
    }
    ub = l;
    if (lb >= ub) return bst;
    from = lb, to = ub;
    bst[len] = rmq.query(lb, ub);
  }
  return bst;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  string s;
  cin >> s;
  int targetLen = s.size();
  string srev = s;
  reverse(srev.begin(), srev.end());
  suffix_array sa(s);
  sa.build();
  seg_tree p_rmq(sa.pos);
  p_rmq.build();
  suffix_array sa_rev(srev);
  sa_rev.build();
  seg_tree s_rmq(sa_rev.pos);
  s_rmq.build();
  int T;
  cin >> T;
  int ans = 0;
  while (T--) {
    string t;
    cin >> t;
    string trev = t;
    reverse(trev.begin(), trev.end());
    int matchLen = t.size();
    if (matchLen < 2) continue;
    vector<int> prefPos = getPos(sa.pos, p_rmq, s, t);
    vector<int> suffPos = getPos(sa_rev.pos, s_rmq, srev, trev);
    for (int prefLen = 1; prefLen < matchLen; prefLen++) {
      int suffLen = matchLen - prefLen;
      if (prefPos[prefLen - 1] == -1 || suffPos[suffLen - 1] == -1) continue;
      if (prefPos[prefLen - 1] + prefLen - 1 <
          targetLen - suffLen - suffPos[suffLen - 1]) {
        ans++;
        break;
      }
    }
  }
  cout << ans << "\n";
}