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;

const int segN = (1<<17);

struct segtree{
  int t[segN*2];
  void init(){
    for(int i=0;i<segN*2;i++){
      t[i]=1e9;
    }
  }
  
  int Get(int i){
    i+=(segN-1);
    int res=t[i];
    while(i){
      i=(i-1)/2;
      res=min(res,t[i]);
    }
  }
  
  void Update(int a,int b,int x,int k=0,int l=0,int r=segN){
    if(b<=l || r<=a)return;
    if(a<=l && r<=b){
      t[k]=min(t[k],x);
      return;
    }
    int m=(l+r)/2;
    Update(a,b,x,k*2+1,l,m);
    Update(a,b,x,k*2+2,m,r);
  }
};

segtree T;
int Rank[1000005];
int Tmp[1000005];
int kc,len;
 
bool compare_sa(int i,int j){
  return
    Rank[i]!=Rank[j]?
    Rank[i]<Rank[j]:
    (i+kc<=len?Rank[i+kc]:-1)<(j+kc<=len?Rank[j+kc]:-1);
}
 
void construct_sa(char* S,int *sa){
  len=strlen(S);
  for(int i=0;i<=len;i++){
    sa[i]=i;
    Rank[i]=i<len?S[i]:-1;
  }
  for(kc=1;kc<=len;kc*=2){
    sort(sa,sa+len+1,compare_sa);
    Tmp[sa[0]]=0;
    for(int i=1;i<=len;i++){
      Tmp[sa[i]]=Tmp[sa[i-1]]+compare_sa(sa[i-1],sa[i]);
    }
    for(int i=0;i<=len;i++)Rank[i]=Tmp[i];
  }
}
 


int n,m;
char str[1000005];
char t[1000005];
int sa[1000005];

int Search(char u[1000005]){
  int k=strlen(u);
  int l=0,r=n+1,m;
  
  while(l<r){
    m=(l+r)/2;
    if(strncmp(str+sa[m],u,k)<0)l=m+1;
    else r=m;
  }

  //   printf("%s %d\n",u,l);
  //   cout<< strncmp(str+sa[l], u,k) <<endl;
  
  return l;
}


string G[100005];

int main(){
  T.init();
  scanf("%s",str);
  n=strlen(str);
  construct_sa(str,sa);
  /*
  for(int p=0;p<=n;p++){
    cout<<sa[p]<<' ';
    for(int i=sa[p];i<n;i++)cout<<str[i];
    cout<<endl;
  }
  */
  scanf("%d",&m);

  set<int> st;
  for(int i=1;i<=n;i++)st.insert(i);
  
  typedef pair<int,int> P;
  vector<P> w,v;
  
  for(int i=0;i<m;i++){
    scanf("%s",t);
    int len=strlen(t);
    for(int j=0;j<len;j++)G[i].push_back( t[j] );
    w.push_back( P(len,i) );
  }
  sort(w.begin(),w.end());

  for(int i=0;i<m;i++){
    int id=w[i].second;
    int len=G[id].size();
    for(int j=0;j<len;j++)t[j]=G[id][j];
    t[len]='\0';
    int L=Search(t);
    t[len]='z'+1;
    t[len+1]='\0';
    int R=Search(t);
    while(1){
      set<int> :: iterator it;
      it=st.lower_bound(L);
      if(it==st.end() || *it >=R)break;
      
      v.push_back(P( sa[*it], sa[*it]+len-1) );
      //      cout<<L<<' '<<R<<endl;
      //      cout<<*it<<' '<< sa[*it] <<' '<< sa[*it]+len-1 <<endl;
      //      cout<<endl;
      st.erase(it);
    }
  }

  for(int i=0;i<(int)v.size();i++)swap(v[i].first,v[i].second);
  sort(v.begin(),v.end());
  for(int i=0;i<(int)v.size();i++)swap(v[i].first,v[i].second);
  
  int ans=0;
  int last=-1;
  for(int i=0;i<(int)v.size();i++){
    if( v[i].first<=last && last<=v[i].second)continue;
    last=v[i].second;
    ans++;
  }
  
  cout<<ans<<endl;
  return 0;
}