Problem: G： 検閲により置換 (Censored String)

Problem Statement

You are given the string S, and the set of strings \mathcal P whose size is N. Now we consider applying the following operation to S:

* Choose exactly one character in S, and replace it with '*'.



Let s_i be a i-th character of S, S_{ij} be a consecutive substring in S such that  S = s_i s_{i+1} $\cdots$  s_j, and p_k as the k-th string of P. Your task is to calculate the minimum number of operations for satisfying the following condition.

* For all pairs (S_{ij}, p_k), it is satisfied that S_{ij} \neq p_k.



Input

An input is given in the following format.


S
N
p_1
p_2
$\vdots$
p_N


* In line 1, you are given the string S.
* In line 2, given an integer N. N means the size of P.
* From line 3 to the end, given p_i, the i-th string of P.



Constraints

* 1 \leq |S| \leq 10^5
* 1 \leq N \leq 10^5
* 1 \leq |p_1| + |p_2| +  $\cdots$  + |p_N| \leq 10^5
* If i \neq j, it is guaranteed that p_i \neq p_j
* S, and p_i include lowercase letters only



Output

Print the minimum number of operations in one line.

Sample Input 1


brainfuck
1
fuck


Sample Output 1


1

For example, if you change "brainfuck" into "brainf*ck", you can satisfy the condition. You have to perform operation at least once, and it is the minimum value.

Sample Input 2


aaa
1
a


Sample Output 2


3

You have to operate for all characters.

Sample Input 3


hellshakeyano
3
hell
shake
key


Sample Output 3


2

In this case, for example, if you change "hellshakeyano" into "h*llsha*eyano", you can satisfy the condition. Notice if you replace one character, it might happen that several strings in the set P, which appear as the consecutive substring of S, simultaneously disappear.





Example

Input

brainfuck
1
fuck


Output

1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

template< int char_size >
struct TrieNode {
  int nxt[char_size + 1];

  int exist; // 子ども以下に存在する文字列の数の合計
  vector< int > accept; // その文字列id

  TrieNode() : exist(0) {
    memset(nxt, -1, sizeof(nxt));
  }
};

template< int char_size, int margin >
struct Trie {
  using Node = TrieNode< char_size >;

  vector< Node > nodes;
  int root;

  Trie() : root(0) {
    nodes.push_back(Node());
  }

  virtual void direct_action(int node, int id) {}

  virtual void child_action(int node, int child, int id) {}

  void update_direct(int node, int id) {
    nodes[node].accept.push_back(id);
    direct_action(node, id);
  }

  void update_child(int node, int child, int id) {
    ++nodes[node].exist;
    child_action(node, child, id);
  }

  void add(const string &str, int str_index, int node_index, int id) {
    if(str_index == str.size()) {
      update_direct(node_index, id);
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) {
        nodes[node_index].nxt[c] = (int) nodes.size();
        nodes.push_back(Node());
      }
      add(str, str_index + 1, nodes[node_index].nxt[c], id);
      update_child(node_index, nodes[node_index].nxt[c], id);
    }
  }

  void add(const string &str, int id) {
    add(str, 0, 0, id);
  }

  void add(const string &str) {
    add(str, nodes[0].exist);
  }

  void query(const string &str, const function< void(int) > &f, int str_index, int node_index) {
    for(auto &idx : nodes[node_index].accept) f(idx);
    if(str_index == str.size()) {
      return;
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) return;
      query(str, f, str_index + 1, nodes[node_index].nxt[c]);
    }
  }

  void query(const string &str, const function< void(int) > &f) {
    query(str, f, 0, 0);
  }

  int size() const {
    return (nodes[0].exist);
  }

  int nodesize() const {
    return ((int) nodes.size());
  }
};

template< int char_size, int margin >
struct Aho_Corasick : Trie< char_size, margin > {
  using TRIE = Trie< char_size, margin >;
  static const int FAIL = char_size;
  vector< int > correct;

  Aho_Corasick() : TRIE() {}

  void build(bool heavy = true) {
    correct.resize(TRIE::nodes.size());
    for(int i = 0; i < TRIE::nodes.size(); i++) {
      correct[i] = (int) TRIE::nodes[i].accept.size();
    }

    queue< int > que;
    for(int i = 0; i <= char_size; i++) {
      if(~TRIE::nodes[0].nxt[i]) {
        TRIE::nodes[TRIE::nodes[0].nxt[i]].nxt[FAIL] = 0;
        que.emplace(TRIE::nodes[0].nxt[i]);
      } else {
        TRIE::nodes[0].nxt[i] = 0;
      }
    }
    while(!que.empty()) {
      TrieNode< char_size > &now = TRIE::nodes[que.front()];
      correct[que.front()] += correct[now.nxt[FAIL]];
      que.pop();
      for(int i = 0; i < char_size; i++) {
        if(now.nxt[i] == -1) continue;
        int fail = now.nxt[FAIL];
        while(TRIE::nodes[fail].nxt[i] == -1) fail = TRIE::nodes[fail].nxt[FAIL];
        TRIE::nodes[now.nxt[i]].nxt[FAIL] = TRIE::nodes[fail].nxt[i];
        if(heavy) {
          auto &u = TRIE::nodes[now.nxt[i]].accept;
          auto &v = TRIE::nodes[TRIE::nodes[fail].nxt[i]].accept;
          vector< int > accept;
          set_union(begin(u), end(u), begin(v), end(v), back_inserter(accept));
          u = accept;
        }
        que.emplace(now.nxt[i]);
      }

    }
  }

  int match(const string &str, vector< int > &result, int now = 0) {
    result.assign(TRIE::size(), 0);
    int count = 0;
    for(auto &c : str) {
      while(TRIE::nodes[now].nxt[c - margin] == -1) now = TRIE::nodes[now].nxt[FAIL];
      now = TRIE::nodes[now].nxt[c - margin];
      count += correct[now];
      for(auto &v : TRIE::nodes[now].accept) ++result[v];
    }
    return (count);
  }

  int move(const char &c, int &now) {
    int count = 0;
    while(TRIE::nodes[now].nxt[c - margin] == -1) now = TRIE::nodes[now].nxt[FAIL];
    now = TRIE::nodes[now].nxt[c - margin];
    count += correct[now];
    return (count);
  }
};


int main() {
  string S;
  int N;
  cin >> S;
  cin >> N;
  Aho_Corasick< 26, 'a' > aho;
  for(int i = 0; i < N; i++) {
    string x;
    cin >> x;
    aho.add(x);
  }
  aho.build(false);
  int cur = 0, ret = 0;
  for(int i = 0; i < S.size(); i++) {
    if(aho.move(S[i], cur) > 0) {
      cur = 0;
      ++ret;
    }
  }
  cout << ret << endl;
}