#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>

using namespace std;

int leq(int a1, int a2, int b1, int b2) {
	return a1 < b1 || a1 == b1 && a2 < b2;
}

int leq(int a1, int a2, int a3, int b1, int b2, int b3) {
	return a1 < b1 || a1 == b1 && leq(a2, a3, b2, b3);
}

//	stable sort a[0 .. n - 1] to b[0 .. n - 1] with keys in 0 .. K - 1 from r
void radix_pass(int a[], int b[], int r[], int n, int K) {
	int i, sum, t;
	int *c = new int[K + 1];
	memset(c, 0, sizeof(int) * (K + 1));
	for (i = 0; i < n; ++i) ++c[r[a[i]]];
	for (i = 0, sum = 0; i <= K; ++i)	{
		t = c[i];
		c[i] = sum;
		sum += t;
	}
	for (i = 0; i < n; ++i) b[c[r[a[i]]]++] = a[i];
	delete[] c;
}

//	find the suffix array SA of s[0..n-1] in {1..K}^n
//	require s[n] = s[n + 1] = s[n + 2] = 0, n >= 2
void suffix_array(int s[], int sa[], int n, int K) {
	int n0, n1, n2, n02;
	int i, j, k, p, t;
	n0 = (n + 2) / 3; n1 = (n + 1) / 3; n2 = n / 3; n02 = n0 + n2;
	int *s12 = new int[n02 + 3]; s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
	int *sa12 = new int[n02 + 3]; sa12[n02] = sa12[n02 + 1] = sa12[n02 + 2] = 0;
	int *s0 = new int[n0];
	int *sa0 = new int[n0];

	//	generate positions of mod 1 and mod 2 suffixes
	//	the " + (n0 - n1)" adds a dummy mod 1 suffix if n % 3 == 1
	//	... for the convience of calculating s0[]
	for (i = 0, j = 0; i < n + (n0 - n1) ; ++i)
		if (i % 3 != 0) s12[j++] = i;

	// lsb radix sort the mod1 and mod2 triples
	radix_pass(s12, sa12, s + 2, n02, K);
	radix_pass(sa12, s12, s + 1, n02, K);
	radix_pass(s12, sa12, s, n02, K);

	//	find lexicographic names of triples
	int name = 0, c0 = -1, c1 = -1, c2 = -1;
	for (i = 0; i < n02; ++i) {
		if (s[sa12[i]] != c0 || s[sa12[i] + 1] != c1 || s[sa12[i] + 2] != c2) {
			++name;
			c0 = s[sa12[i]];
			c1 = s[sa12[i] + 1];
			c2 = s[sa12[i] + 2];
		}
		if (sa12[i] % 3 == 1) s12[sa12[i] / 3] = name;	// left half
		else s12[sa12[i] / 3 + n0] = name;				// right half
	}

	//	recurse if names are not yet unique
	if (name < n02) {
		suffix_array(s12, sa12, n02, name);
		//	store unique names in s12 using the suffix array
		for (i = 0; i < n02; ++i) s12[sa12[i]] = i + 1;
	} else {
		for (i = 0; i < n02; ++i) sa12[s12[i] - 1] = i;
	}

	//	stable sort the mod 0 suffixes from sa12 by their first character
	for (i = 0, j = 0; i < n02; ++i) if (sa12[i] < n0) s0[j++] = 3 * sa12[i];
	radix_pass(s0, sa0, s, n0, K);

	//	merge sort sa0 suffixes and sorted sa12 suffixes
  //	the dummy mod1 suffix is at the front of sa12[]
	for (p = 0, t = n0 - n1, k = 0; k < n; ++k) {
		i = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		j = sa0[p];
		if (sa12[t] < n0 ? leq(s[i], s12[sa12[t] + n0], s[j], s12[j / 3]):
			leq(s[i], s[i + 1], s12[sa12[t] - n0 + 1], s[j], s[j + 1], s12[j / 3 + n0])) {
			sa[k] = i;
			++t;
			if (t == n02)
				for (++k; p < n0; ++p, ++k) sa[k] = sa0[p];
		} else {
			sa[k] = j;
			++p;
			if (p == n0)
				for (++k; t < n02; ++t, ++k)
					sa[k] = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		}
	}
	delete[] s12;
	delete[] sa12;
	delete[] sa0;
	delete[] s0;
}

void get_height(int s[], int sa[], int rank[], int h[], int n) {
	int i, j, k;
	for (i = 0; i < n; ++i) rank[sa[i]] = i;
	for (j = 0, i = 0; i < n; ++i) {
		if (rank[i] == 0) h[0] = j = 0;
		else {
			k = sa[rank[i] - 1];
			for (j = max(j - 1, 0); s[i + j] == s[k + j]; ++j);
			h[rank[i]] = j;
		}
	}
}

const int N = 200000 + 10;
int s[N], sa[N], rank[N], h[N];
char str[N];
int L[N], R[N];

void run(int a[], int n, int m) {
  suffix_array(s, sa, n, 300);
  get_height(s, sa, rank, h, n);
  int j = rank[m + 1];
  int min_h = INT_MAX;
  for (int k = j + 1; k < n; ++k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
  min_h = INT_MAX;
  for (int k = j - 1; k >= 0; --k) {
    min_h = min(min_h, h[k + 1]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
}

int main() {
  int n, m, num, ret = 0;
  scanf("%s %d", str, &num);
  for (m = 0; str[m]; ++m) s[m] = str[m];
  for (int i = 0; i < num; ++i) {
    n = m;
    s[n++] = 1;
    scanf("%s", str + n);
    for (; str[n]; ++n) s[n] = str[n];
    s[n] = s[n + 1] = s[n + 2] = 0;
    int len = n - m - 1;
    // printf("%d %d %d\n", m, n, len);
    if (len == 1) continue;
    run(L, n, m);
    for (int j = 0; j < m / 2; ++j) swap(s[j], s[m - 1 - j]);
    for (int j = 0; j < len / 2; ++j)
      swap(s[m + 1 + j], s[m + 1 + len - 1 - j]);
    run(R, n, m);
    for (int j = 0; j < m / 2; ++j) {
      swap(s[j], s[m - 1 - j]);
      swap(R[j], R[m - 1 - j]);
    }
    // for (int j = 0; j < m; ++j) {
    //   printf("%d ", L[j]);
    // } puts("");
    // for (int j = 0; j < m; ++j) {
    //   printf("%d ", R[j]);
    // } puts("");
    for (int j = 1; j < m; ++j) L[j] = max(L[j - 1], L[j]);
    for (int j = m - 2; j >= 0; --j) R[j] = max(R[j], R[j + 1]);
    bool found = false;
    for (int j = 0; j + len <= m; ++j) {
      // printf("%d %d %d %d\n", i, j, L[j], R[j + len - 1]);
      if (L[j] + R[j + len - 1] >= len) {
        found = true;
        break;
      }
    }
    if (found) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 100000 + 10;
const int M = 1000 + 10;
char s[N], s2[N];
int a[N], b[N];
char t[M];
int f[M];

void get_f(char t[], int f[], int m) {
  int k = f[0] = 0;
  for (int i = 1; i < m; ++i) {
    for (; k > 0 && t[k] != t[i]; k = f[k - 1]);
    if (t[i] == t[k]) ++k;
    f[i] = k;
  }
}

void kmp(char s[], int a[], int n, char t[], int f[], int m) {
  int k = 0;
  for (int i = 0; i < n; ++i) {
    for (; k > 0 && t[k] != s[i]; k = f[k - 1]);
    if (s[i] == t[k]) ++k;
    a[i] = k;
    if (k == m) k = f[k - 1];
  }
}

bool check(char s[], char s2[], char t[]) {
  int n = strlen(s);
  int m = strlen(t);
  if (m == 1) return false;
  get_f(t, f, m);
  kmp(s, a, n, t, f, m);
  reverse(t, t + m);
  get_f(t, f, m);
  kmp(s2, b, n, t, f, m);
  for (int i = 1; i < n; ++i) b[i] = max(b[i], b[i - 1]);
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i] + b[n - 2 - i] >= m) return true;
  }
  return false;
}

int main() {
  scanf("%s", s);
  int n = strlen(s);
  copy(s, s + n, s2);
  reverse(s2, s2 + n);
  int Q;
  scanf("%d", &Q);
  int ret = 0;
  while (Q--) {
    scanf("%s", t);
    if (check(s, s2, t)) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>

using namespace std;

int leq(int a1, int a2, int b1, int b2) {
	return a1 < b1 || a1 == b1 && a2 < b2;
}

int leq(int a1, int a2, int a3, int b1, int b2, int b3) {
	return a1 < b1 || a1 == b1 && leq(a2, a3, b2, b3);
}

//	stable sort a[0 .. n - 1] to b[0 .. n - 1] with keys in 0 .. K - 1 from r
void radix_pass(int a[], int b[], int r[], int n, int K) {
	int i, sum, t;
	int *c = new int[K + 1];
	memset(c, 0, sizeof(int) * (K + 1));
	for (i = 0; i < n; ++i) ++c[r[a[i]]];
	for (i = 0, sum = 0; i <= K; ++i)	{
		t = c[i];
		c[i] = sum;
		sum += t;
	}
	for (i = 0; i < n; ++i) b[c[r[a[i]]]++] = a[i];
	delete[] c;
}

//	find the suffix array SA of s[0..n-1] in {1..K}^n
//	require s[n] = s[n + 1] = s[n + 2] = 0, n >= 2
void suffix_array(int s[], int sa[], int n, int K) {
	int n0, n1, n2, n02;
	int i, j, k, p, t;
	n0 = (n + 2) / 3; n1 = (n + 1) / 3; n2 = n / 3; n02 = n0 + n2;
	int *s12 = new int[n02 + 3]; s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
	int *sa12 = new int[n02 + 3]; sa12[n02] = sa12[n02 + 1] = sa12[n02 + 2] = 0;
	int *s0 = new int[n0];
	int *sa0 = new int[n0];

	//	generate positions of mod 1 and mod 2 suffixes
	//	the " + (n0 - n1)" adds a dummy mod 1 suffix if n % 3 == 1
	//	... for the convience of calculating s0[]
	for (i = 0, j = 0; i < n + (n0 - n1) ; ++i)
		if (i % 3 != 0) s12[j++] = i;

	// lsb radix sort the mod1 and mod2 triples
	radix_pass(s12, sa12, s + 2, n02, K);
	radix_pass(sa12, s12, s + 1, n02, K);
	radix_pass(s12, sa12, s, n02, K);

	//	find lexicographic names of triples
	int name = 0, c0 = -1, c1 = -1, c2 = -1;
	for (i = 0; i < n02; ++i) {
		if (s[sa12[i]] != c0 || s[sa12[i] + 1] != c1 || s[sa12[i] + 2] != c2) {
			++name;
			c0 = s[sa12[i]];
			c1 = s[sa12[i] + 1];
			c2 = s[sa12[i] + 2];
		}
		if (sa12[i] % 3 == 1) s12[sa12[i] / 3] = name;	// left half
		else s12[sa12[i] / 3 + n0] = name;				// right half
	}

	//	recurse if names are not yet unique
	if (name < n02) {
		suffix_array(s12, sa12, n02, name);
		//	store unique names in s12 using the suffix array
		for (i = 0; i < n02; ++i) s12[sa12[i]] = i + 1;
	} else {
		for (i = 0; i < n02; ++i) sa12[s12[i] - 1] = i;
	}

	//	stable sort the mod 0 suffixes from sa12 by their first character
	for (i = 0, j = 0; i < n02; ++i) if (sa12[i] < n0) s0[j++] = 3 * sa12[i];
	radix_pass(s0, sa0, s, n0, K);

	//	merge sort sa0 suffixes and sorted sa12 suffixes
  //	the dummy mod1 suffix is at the front of sa12[]
	for (p = 0, t = n0 - n1, k = 0; k < n; ++k) {
		i = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		j = sa0[p];
		if (sa12[t] < n0 ? leq(s[i], s12[sa12[t] + n0], s[j], s12[j / 3]):
			leq(s[i], s[i + 1], s12[sa12[t] - n0 + 1], s[j], s[j + 1], s12[j / 3 + n0])) {
			sa[k] = i;
			++t;
			if (t == n02)
				for (++k; p < n0; ++p, ++k) sa[k] = sa0[p];
		} else {
			sa[k] = j;
			++p;
			if (p == n0)
				for (++k; t < n02; ++t, ++k)
					sa[k] = (sa12[t] < n0 ? sa12[t] * 3 + 1 : (sa12[t] - n0) * 3 + 2);
		}
	}
	delete[] s12;
	delete[] sa12;
	delete[] sa0;
	delete[] s0;
}

void get_height(int s[], int sa[], int rank[], int h[], int n) {
	int i, j, k;
	for (i = 0; i < n; ++i) rank[sa[i]] = i;
	for (j = 0, i = 0; i < n; ++i) {
		if (rank[i] == 0) h[0] = j = 0;
		else {
			k = sa[rank[i] - 1];
			for (j = max(j - 1, 0); s[i + j] == s[k + j]; ++j);
			h[rank[i]] = j;
		}
	}
}

const int N = 200000 + 10;
int s[N], sa[N], rank[N], h[N];
char str[N];
int L[N], R[N];

void run(int a[], int n, int m) {
  suffix_array(s, sa, n, 300);
  get_height(s, sa, rank, h, n);
  int j = rank[m + 1];
  int min_h = INT_MAX;
  for (int k = j + 1; k < n; ++k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
  min_h = INT_MAX;
  for (int k = j - 1; k >= 0; --k) {
    min_h = min(min_h, h[k]);
    if (sa[k] < m) a[sa[k]] = min_h;
  }
}

int main() {
  int n, m, num, ret = 0;
  scanf("%s %d", str, &num);
  for (m = 0; str[m]; ++m) s[m] = str[m];
  for (int i = 0; i < num; ++i) {
    n = m;
    str[n++] = 1;
    scanf("%s", str + n);
    for (; str[n]; ++n) s[n] = str[n];
    int len = n - m - 1;
    if (len == 1) continue;
    // printf("%d %d %d\n", m, n, len);
    s[n] = s[n + 1] = s[n + 2] = 0;
    run(L, n, m);
    for (int j = 0; j < m / 2; ++j) swap(s[j], s[m - 1 - j]);
    run(R, n, m);
    for (int j = 0; j < m / 2; ++j) {
      swap(s[j], s[m - 1 - j]);
      swap(R[j], R[m - 1 - j]);
    }
    for (int j = 1; j < m; ++j) L[j] = max(L[j - 1], L[j]);
    for (int j = m - 2; j >= 0; --j) R[j] = max(R[j], R[j + 1]);
    bool found = false;
    for (int j = 0; j + len <= m; ++j) {
      if (L[j] + R[j + len - 1] >= len) {
        found = true;
        break;
      }
    }
    if (found) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 200005
#define mins 2005
#define eps 0.000000000001
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define lg 20
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

string text,str[105];
int z[maxs],z1[maxs];
int L[mins],R[mins],n1,n2;
void calc_Z(string s){
    int l=0,r=0;
    n1=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z[k]<r-i+1){
                z[i]=z[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z[i]=r-l;
                r--;
            }
        }
    }
}

void calc_Z_rev(string s){
    int l=0,r=0;
    n2=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z1[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z1[k]<r-i+1){
                z1[i]=z1[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z1[i]=r-l;
                r--;
            }
        }
    }
}
int main()
{
    iosbase;
    string text1;
    int m,ans=0,i,j;
    cin>>text;
    text1="";
    for(i=text.size()-1;i>=0;i--){
        text1+=text[i];
    }
    cin>>m;
    for(i=0;i<m;i++){
        cin>>str[i];
    //  cout<<str[i]<<" ";
        calc_Z(str[i]+"$"+text);
        std::reverse(str[i].begin(),str[i].end());
        calc_Z_rev(str[i]+"$"+text1);
        for(j=0;j<=str[i].size();j++){
            L[j]=imax;
            R[j]=-1;
        }
    //  cout<<str[i]<<endl;
        for(j=str[i].size()+1;j<n1;j++){
        //  cout<<z[j]<<" ";
            if(z[j]>=1 && L[z[j]]==imax){
                L[z[j]]=j-str[i].size()-1;
            }
        }
    //  cout<<endl;
        for(j=str[i].size()+1;j<n2;j++){
    //      cout<<z1[j]<<" ";
            if(z1[j]>=1 && R[z1[j]]==-1){
                R[z1[j]]=j-str[i].size()-1;
            //  cout<<z1[j]<<" "<<j-str[i].size()-1<<endl;
                R[z1[j]]=text.size()-1-R[z1[j]];
            }
        }
        for(j=str[i].size()-1;j>=1;j--){
            L[j]=min(L[j],L[j+1]);
            R[j]=max(R[j],R[j+1]);
        }
        for(j=1;j<str[i].size();j++){
        //  cout<<L[j]<<" "<<R[str[i].size()-j]<<endl;
            if(L[j]!=imax && R[str[i].size()-j]!=-1 && L[j]+j-1<R[str[i].size()-j]-str[i].size()+1){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 200005
#define mins 2005
#define eps 0.000000000001
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define lg 20
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

string text,str[105];
int z[maxs],z1[maxs];
int L[mins],R[mins],n1,n2;
void calc_Z(string s){
    int l=0,r=0;
    n1=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z[k]<r-i+1){
                z[i]=z[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z[i]=r-l;
                r--;
            }
        }
    }
}

void calc_Z_rev(string s){
    int l=0,r=0;
    n2=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z1[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z1[k]<r-i+1){
                z1[i]=z1[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z1[i]=r-l;
                r--;
            }
        }
    }
}
int main()
{
    iosbase;
    string text1;
    int m,ans=0,i,j;
    cin>>text;
    text1="";
    for(i=text.size()-1;i>=0;i--){
        text1+=text[i];
    }
    cin>>m;
    for(i=0;i<m;i++){
        cin>>str[i];
    //  cout<<str[i]<<" ";
        calc_Z(str[i]+"$"+text);
        std::reverse(str[i].begin(),str[i].end());
        calc_Z_rev(str[i]+"$"+text1);
        for(j=0;j<=str[i].size();j++){
            L[j]=R[j]=-1;
        }
    //  cout<<str[i]<<endl;
        for(j=str[i].size()+1;j<n1;j++){
        //  cout<<z[j]<<" ";
            if(z[j]>=1 && L[z[j]]==-1){
                L[z[j]]=j-str[i].size()-1;
            }
        }
    //  cout<<endl;
        for(j=str[i].size()+1;j<n2;j++){
    //      cout<<z1[j]<<" ";
            if(z1[j]>=1 && R[z1[j]]==-1){
                R[z1[j]]=j-str[i].size()-1;
                R[z1[j]]=text.size()-1-R[z1[j]];
            }
        }
        for(j=1;j<str[i].size();j++){
        //  cout<<L[j]<<" "<<R[str[i].size()-j]<<endl;
            if(L[j]!=-1 && R[str[i].size()-j]!=-1 && L[j]+j-1<R[str[i].size()-j]-str[i].size()+1){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 200005
#define mins 2005
#define eps 0.000000000001
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define lg 20
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

string text,str[105];
int z[maxs],z1[maxs];
int L[mins],R[mins],n1,n2;
void calc_Z(string s){
    int l=0,r=0;
    n1=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z[k]<r-i+1){
                z[i]=z[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z[i]=r-l;
                r--;
            }
        }
    }
}

void calc_Z_rev(string s){
    int l=0,r=0;
    n2=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z1[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z1[k]<r-i+1){
                z1[i]=z1[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z1[i]=r-l;
                r--;
            }
        }
    }
}
int main()
{
    iosbase;
    string text1;
    int m,ans=0,i,j;
    cin>>text;
    text1="";
    for(i=text.size()-1;i>=0;i--){
        text1+=text[i];
    }
    cin>>m;
    for(i=0;i<m;i++){
        cin>>str[i];
    //  cout<<str[i]<<" ";
        calc_Z(str[i]+"$"+text);
        std::reverse(str[i].begin(),str[i].end());
        calc_Z_rev(str[i]+"$"+text1);
        for(j=0;j<=str[i].size();j++){
            L[j]=R[j]=-1;
        }
    //  cout<<str[i]<<endl;
        for(j=str[i].size()+1;j<n1;j++){
        //  cout<<z[j]<<" ";
            if(z[j]>=1 && L[z[j]]==-1){
                L[z[j]]=j-str[i].size()-1;
            }
        }
    //  cout<<endl;
        for(j=str[i].size()+1;j<n2;j++){
    //      cout<<z1[j]<<" ";
            if(z1[j]>=1 && R[z1[j]]==-1){
                R[z1[j]]=j-str[i].size()-1;
                R[z1[j]]=text.size()-1-R[z1[j]];
            }
        }
        for(j=1;j<str[i].size();j++){
        //  cout<<L[j]<<" "<<R[str[i].size()-j]<<endl;
            if(L[j]!=-1 && R[str[i].size()-j]!=-1 && L[j]+j-1<R[str[i].size()-j]-str[i].size()+1){
                ans++;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 200005
#define mins 2005
#define eps 0.000000000001
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define lg 20
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

string text,str[105];
int z[maxs],z1[maxs];
int L[mins],R[mins],n1,n2;
void calc_Z(string s){
    int l=0,r=0;
    n1=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z[k]<r-i+1){
                z[i]=z[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z[i]=r-l;
                r--;
            }
        }
    }
}

void calc_Z_rev(string s){
    int l=0,r=0;
    n2=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z1[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z1[k]<r-i+1){
                z1[i]=z1[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z1[i]=r-l;
                r--;
            }
        }
    }
}
int main()
{
    iosbase;
    string text1;
    int m,ans=0,i,j;
    cin>>text;
    text1="";
    for(i=text.size()-1;i>=0;i--){
        text1+=text[i];
    }
    cin>>m;
    for(i=0;i<m;i++){
        cin>>str[i];
    //  cout<<str[i]<<" ";
        calc_Z(str[i]+"$"+text);
        std::reverse(str[i].begin(),str[i].end());
        calc_Z_rev(str[i]+"$"+text1);
        for(j=0;j<=str[i].size();j++){
            L[j]=imax;
            R[j]=-1;
        }
    //  cout<<str[i]<<endl;
        for(j=str[i].size()+1;j<n1;j++){
        //  cout<<z[j]<<" ";
            if(z[j]>=1 && L[z[j]]==imax){
                L[z[j]]=j-str[i].size()-1;
            }
        }
    //  cout<<endl;
        for(j=str[i].size()+1;j<n2;j++){
    //      cout<<z1[j]<<" ";
            if(z1[j]>=1 && R[z1[j]]==-1){
                R[z1[j]]=j-str[i].size()-1;
            //  cout<<z1[j]<<" "<<j-str[i].size()-1<<endl;
                R[z1[j]]=text.size()-1-R[z1[j]];
            }
        }
        for(j=str[i].size()-1;j>=1;j--){
            L[j]=min(L[j],L[j+1]);
            R[j]=max(R[j],R[j+1]);
        }
        for(j=1;j<str[i].size();j++){
        //  cout<<L[j]<<" "<<R[str[i].size()-j]<<endl;
            if(L[j]!=imax && R[str[i].size()-j]!=-1 && L[j]+j-1<R[str[i].size()-j]-str[i].size()+1 && L[j]+j-1<text.size()-1){
            //  cout<<L[j]<<" "<<R[str[i].size()-j]<<" "<<j<<endl;
                ans++;
                break;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 200005
#define mins 2005
#define eps 0.000000000001
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define lg 20
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

string text,str[105];
int z[maxs],z1[maxs];
int L[mins],R[mins],n1,n2;
void calc_Z(string s){
    int l=0,r=0;
    n1=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z[k]<r-i+1){
                z[i]=z[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z[i]=r-l;
                r--;
            }
        }
    }
}

void calc_Z_rev(string s){
    int l=0,r=0;
    n2=s.size();
    for(int i=1;i<s.size();i++){
        if(i>r){
            l=r=i;
            while(r<s.size() && s[r-l]==s[r]){
                r++;
            }
            z1[i]=r-i;
            r--;
        }
        else{
            int k=i-l;
            if(z1[k]<r-i+1){
                z1[i]=z1[k];
            }
            else{
                l=i;
                while(r<s.size() && s[r-l]==s[r]){
                    r++;
                }
                z1[i]=r-l;
                r--;
            }
        }
    }
}
int main()
{
    iosbase;
    string text1;
    int m,ans=0,i,j;
    cin>>text;
    text1="";
    for(i=text.size()-1;i>=0;i--){
        text1+=text[i];
    }
    cin>>m;
    for(i=0;i<m;i++){
        cin>>str[i];
    //  cout<<str[i]<<" ";
        calc_Z(str[i]+"$"+text);
        std::reverse(str[i].begin(),str[i].end());
        calc_Z_rev(str[i]+"$"+text1);
        int l5=str[i].size();
        for(j=0;j<=l5;j++){
            L[j]=imax;
            R[j]=-1;
        }
    //  cout<<str[i]<<endl;
        for(j=l5+1;j<n1;j++){
        //  cout<<z[j]<<" ";
            if(z[j]>=1 && L[z[j]]==imax){
                L[z[j]]=j-l5-1;
            }
        }
    //  cout<<endl;
        for(j=l5+1;j<n2;j++){
    //      cout<<z1[j]<<" ";
            if(z1[j]>=1 && R[z1[j]]==-1){
                R[z1[j]]=j-l5-1;
            //  cout<<z1[j]<<" "<<j<<endl;
                R[z1[j]]=text.size()-1-R[z1[j]];
            }
        }
        for(j=l5-1;j>=1;j--){
            L[j]=min(L[j],L[j+1]);
            R[j]=max(R[j],R[j+1]);
        }
        for(j=1;j<l5;j++){
        //  cout<<L[j]<<" "<<R[l5-j]<<endl;
            if(L[j]!=imax && R[l5-j]!=-1 && L[j]+j-1<R[l5-j]-l5+j+1){
        //      cout<<L[j]<<" "<<R[l5-j]<<" "<<j<<" "<<R[l5-j]-l5+1<<endl;
                ans++;
                break;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa[2];
vector<int> rk[2];
vector<int> lcp[2];
vector<int> tmp;
string ALL[2];
int k;
int sz;
int calc;

inline bool compare(int i,int j){
    if(rk[calc][i]!=rk[calc][j]){
        return rk[calc][i]<rk[calc][j];
    }else{
        int ri=(i+k<sz)?rk[calc][i+k]:-1;
        int rj=(j+k<sz)?rk[calc][j+k]:-1;
        return ri<rj;
    }
}

void buildSA(int c){
    calc = c;
    vector<int> &s=sa[calc];
    vector<int> &r=rk[calc];
    vector<int> &l=lcp[calc];
    string &str=ALL[calc];

    s.resize(sz+1);
    r.resize(sz+1);
    l.resize(sz+1);
    tmp.resize(sz+1);
    rep(i,sz+1){
        s[i]=i;
        r[i]= (i<sz)?str[i]:-1;
    }
    for(k=1;k<=sz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=sz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=sz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,sz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,sz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<sz&&j+h<sz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a[2];
    cin >> ALL[0];
    string t;
    int fl=(int)ALL[0].length();
    ALL[1].resize(fl);
    a[0].resize(fl);
    a[1].resize(fl);

    reverse_copy(ALL[0].begin(),ALL[0].end(), ALL[1].begin());
    int m;
    cin >> m;
    int nowp = (int)ALL[0].length()+1;
    rep(i,m){
        pos.pb(nowp);
        //        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL[0]+='$';
        ALL[0]+=t;
        reverse(t.begin(),t.end());
        ALL[1]+='$';
        ALL[1]+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
    //    cout<<ALL[0]<<endl;
    //    cout<<ALL[1]<<endl;
    sz=(int)ALL[0].length();
    buildSA(0);
    buildSA(1);
    //    rep(i,sz){
    //        printf("%3d:lcp:%3dsa[0]:%3d,",i,lcp[i],sa[0][i]);
    //        if(sa[0][i]<sz)cout<<ALL[0].substr(sa[0][i],sz)<<endl;
    //        else cout<<endl;
    //    }
    //    cout<<endl;
    //    rep(i,sz+1){
    //        printf("%3d:lcp:%3dsa[0]:%3d,",i,lcp[1][i],sa[0]_[i]);
    //        if(sa[0]_[i]<sz)cout<<ALL[1].substr(sa[0]_[i],sz)<<endl;
    //        else cout<<endl;
    //
    //    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        fill(a[0].begin(),a[0].end(),0);
        fill(a[1].begin(),a[1].end(),0);
        rep(c,2){
            int hoge = rk[c][pos[i]];
            int he = ls[i];
            while(he&&hoge<=sz){
                if(sa[c][hoge]+he-1<fl){
                    a[c][sa[c][hoge]+he-1]=max(a[c][sa[c][hoge]+he-1],he);
                }
                he=min(he,lcp[c][hoge]);
                hoge++;
            }

            hoge = rk[c][pos[i]];
            he = ls[i];
            while(he&&hoge>=0){
                if(sa[c][hoge]+he-1<fl){
                    a[c][sa[c][hoge]+he-1]=max(a[c][sa[c][hoge]+he-1],he);
                }
                hoge--;
                he=min(he,lcp[c][hoge]);
            }
        }
        rep(j,fl-1){
            a[0][j+1]=max(a[0][j+1],a[0][j]);
            a[1][j+1]=max(a[1][j+1],a[1][j]);
        }
        rep(j,fl-1){
            a[0][fl-j-2]=max(a[0][fl-j-2],a[0][fl-j-1]-1);
            a[1][fl-j-2]=max(a[1][fl-j-2],a[1][fl-j-1]-1);
        }
        //        rep(j,fl){
        //            printf("%3d",a[j]);        }
        //        cout<<endl;
        //        rep(j,fl){
        //            printf("%3d",b[j]);        }
//                cout<<endl;
        for(int j = 0;j < fl-1;j++){
            if(a[0][j]&&a[1][fl-j-2]&&a[0][j]+a[1][fl-j-2]>=ls[i]){
                ans++;
                //                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=ALL.length();
    ALL_.resize(fl);
    a.resize(fl,0);
    a.resize(fl,0);
    b.resize(fl,0);
    b.resize(fl,0);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(i,fl-1){
            a[i+1]=max(a[i+1],a[i]);
            b[i+1]=max(b[i+1],b[i]);
        }
        rep(i,fl-1){
            a[fl-i-2]=max(a[fl-i-2],a[fl-i-1]-1);
            b[fl-i-2]=max(b[fl-i-2],b[fl-i-1]-1);
        }
//        rep(i,fl){
//            cout<< a[i]<<" ";
//        }
//        cout<<endl;
//        rep(i,fl){
//            cout<< b[i]<<" ";
//        }
//        cout<<endl;
        for(int c = 1;c < fl-1;c++){
            if(a[c]&&b[fl-c-1]&&a[c]+b[fl-c-1]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=(int)ALL.length();
    ALL_.resize(fl);
    a.resize(fl);
    b.resize(fl);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        fill(a.begin(),a.end(),0);
        fill(b.begin(),b.end(),0);
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he-1<fl){
                a[sa[hoge]+he-1]=max(a[sa[hoge]+he-1],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he-1<fl){
                a[sa[hoge]+he-1]=max(a[sa[hoge]+he-1],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he-1<fl){
                b[sa_[hoge]+he-1]=max(b[sa_[hoge]+he-1],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he-1<fl){
                b[sa_[hoge]+he-1]=max(b[sa_[hoge]+he-1],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(j,fl-1){
            a[j+1]=max(a[j+1],a[j]);
            b[j+1]=max(b[j+1],b[j]);
        }
        rep(j,fl-1){
            a[fl-j-2]=max(a[fl-j-2],a[fl-j-1]-1);
            b[fl-j-2]=max(b[fl-j-2],b[fl-j-1]-1);
        }
//        rep(j,fl){
//            printf("%3d",a[j]);        }
//        cout<<endl;
//        rep(j,fl){
//            printf("%3d",b[j]);        }
//        cout<<endl;
        for(int j = 0;j < fl-1;j++){
            if(a[j]&&b[fl-j-2]&&a[j]+b[fl-j-2]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=ALL.length();
    ALL_.resize(fl);
    a.resize(fl,0);
    a.resize(fl,0);
    b.resize(fl,0);
    b.resize(fl,0);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(i,fl-1){
            a[i+1]=max(a[i+1],a[i]);
            b[i+1]=max(b[i+1],b[i]);
        }
        rep(i,fl-1){
            a[fl-i-2]=max(a[fl-i-2],a[fl-i-1]-1);
            b[fl-i-2]=max(b[fl-i-2],b[fl-i-1]-1);
        }
//        rep(i,fl){
//            cout<< a[i]<<" ";
//        }
//        cout<<endl;
//        rep(i,fl){
//            cout<< b[i]<<" ";
//        }
//        cout<<endl;
        for(int c = 1;c < fl-1;c++){
            if(a[c]&&b[fl-c-1]&&a[c]+b[fl-c-1]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=ALL.length();
    ALL_.resize(fl);
    a.resize(fl,0);
    a.resize(fl,0);
    b.resize(fl,0);
    b.resize(fl,0);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(j,fl-1){
            a[j+1]=max(a[j+1],a[j]);
            b[j+1]=max(b[j+1],b[j]);
        }
        rep(j,fl-1){
            a[fl-j-2]=max(a[fl-j-2],a[fl-j-1]-1);
            b[fl-j-2]=max(b[fl-j-2],b[fl-j-1]-1);
        }
//        rep(j,fl){
//            cout<< a[j]<<" ";
//        }
//        cout<<endl;
//        rep(j,fl){
//            cout<< b[j]<<" ";
//        }
//        cout<<endl;
        for(int j = 1;j < fl-1;j++){
            if(a[j]&&b[fl-j-1]&&a[j]+b[fl-j-1]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=(int)ALL.length();
    ALL_.resize(fl);
    a.resize(fl,0);
    a.resize(fl,0);
    b.resize(fl,0);
    b.resize(fl,0);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa_[hoge]+he],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa_[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(j,fl-1){
            a[j+1]=max(a[j+1],a[j]);
            b[j+1]=max(b[j+1],b[j]);
        }
        rep(j,fl-1){
            a[fl-j-2]=max(a[fl-j-2],a[fl-j-1]-1);
            b[fl-j-2]=max(b[fl-j-2],b[fl-j-1]-1);
        }
//        rep(j,fl){
//            cout<< a[j]<<" ";
//        }
//        cout<<endl;
//        rep(j,fl){
//            cout<< b[j]<<" ";
//        }
//        cout<<endl;
        for(int j = 1;j < fl-1;j++){
            if(a[j]&&b[fl-j-1]&&a[j]+b[fl-j-1]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 100010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

int tbl[1010];
int a1[100010];
int a2[100010];

int ls,lt;
string str1,str2;
string t;

void kmp1(){
    tbl[0]=-1;
    int j = -1;
    rep(i,lt-1){
        while(j>=0&&t[j]!=t[i]){
            j=tbl[j];
        }
        j++;
        tbl[i+1]=j;
    }
}

void search(int *a,string s){
    int j = 0;
    for(int i = 0;i<ls;){
        while(i+j<ls&&j<lt&&s[i+j]==t[j]){
            j++;
            a[i+j-1]=max(j,a[i+j-1]);
        }

        i+=j-tbl[j];
        if(j>0)j=tbl[j];
    }
}

int main(){
    int m;
    cin>>str1;
    ls = (int)str1.length();
    str2.resize(ls);
    reverse_copy(str1.begin(),str1.end(),str2.begin());
    cin>>m;
    int ans = 0;
    rep(xvideos,m){
        fill(a1,a1+ls,0);
        fill(a2,a2+ls,0);
        cin>>t;
        lt = (int)t.length();
        if(lt==1){
            continue;
        }
        kmp1();

        search(a1,str1);

        reverse(t.begin(),t.end());
        kmp1();
        search(a2,str2);
        for(int i = 1;i<ls;i++){
            a1[i]=max(a1[i-1],a1[i]);
            a2[i]=max(a2[i-1],a2[i]);
        }
        for(int i = 1;i<=ls;i++){
            if(a1[i-1]&&a2[ls-i-1]&&a1[i-1]+a2[ls-i-1]>=lt){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=(int)ALL.length();
    ALL_.resize(fl);
    a.resize(fl);
    b.resize(fl);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        fill(a.begin(),a.end(),0);
        fill(b.begin(),b.end(),0);
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he-1<fl){
                a[sa[hoge]+he-1]=max(a[sa[hoge]+he-1],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he-1<fl){
                a[sa[hoge]+he-1]=max(a[sa[hoge]+he-1],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he-1<fl){
                b[sa_[hoge]+he-1]=max(b[sa_[hoge]+he-1],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he-1<fl){
                b[sa_[hoge]+he-1]=max(b[sa_[hoge]+he-1],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(j,fl-1){
            a[j+1]=max(a[j+1],a[j]);
            b[j+1]=max(b[j+1],b[j]);
        }
        rep(j,fl-1){
            a[fl-j-2]=max(a[fl-j-2],a[fl-j-1]-1);
            b[fl-j-2]=max(b[fl-j-2],b[fl-j-1]-1);
        }
//        rep(j,fl){
//            printf("%3d",a[j]);        }
//        cout<<endl;
//        rep(j,fl){
//            printf("%3d",b[j]);        }
//        cout<<endl;
        for(int j = 0;j < fl-1;j++){
            if(a[j]&&b[fl-j-1]&&a[j]+b[fl-j-1]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=ALL.length();
    ALL_.resize(fl);
    a.resize(fl,0);
    a.resize(fl,0);
    b.resize(fl,0);
    b.resize(fl,0);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(i,fl-1){
            a[i+1]=max(a[i+1],a[i]);
            b[i+1]=max(b[i+1],b[i]);
        }
        rep(i,fl-1){
            a[fl-i-2]=max(a[fl-i-2],a[fl-i-1]-1);
            b[fl-i-2]=max(b[fl-i-2],b[fl-i-1]-1);
        }
//        rep(i,fl){
//            cout<< a[i]<<" ";
//        }
//        cout<<endl;
//        rep(i,fl){
//            cout<< b[i]<<" ";
//        }
//        cout<<endl;
        for(int c = 1;c < fl-1;c++){
            if(a[c]&&b[fl-c-1]&&a[c]+b[fl-c-1]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=(int)ALL.length();
    ALL_.resize(fl);
    a.resize(fl);
    b.resize(fl);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        fill(a.begin(),a.end(),0);
        fill(b.begin(),b.end(),0);
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa_[hoge]+he],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa_[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(j,fl-1){
            a[j+1]=max(a[j+1],a[j]);
            b[j+1]=max(b[j+1],b[j]);
        }
        rep(j,fl-1){
            a[fl-j-2]=max(a[fl-j-2],a[fl-j-1]-1);
            b[fl-j-2]=max(b[fl-j-2],b[fl-j-1]-1);
        }
//        rep(j,fl){
//            printf("%3d",a[j]);        }
//        cout<<endl;
//        rep(j,fl){
//            printf("%3d",b[j]);        }
//        cout<<endl;
        for(int j = 1;j < fl-1;j++){
            if(a[j]&&b[fl-j-1]&&a[j]+b[fl-j-1]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define INF 1000010
#define fi first
#define se second

#define rep(x,n) for(int x = 0;x < n;x++)
typedef long long int ll;
using namespace std;

vector<int> sa;
vector<int> sa_;
vector<int> rk;
vector<int> rk_;
vector<int> lcp;
vector<int> lcp_;
vector<int> tmp;
string ALL;
string ALL_;

int allsz,k;

bool nowcalc=0;

bool compare1(int i,int j){
    if(rk[i]!=rk[j]){
        return rk[i]<rk[j];
    }else{
        int ri=(i+k<allsz)?rk[i+k]:-1;
        int rj=(j+k<allsz)?rk[j+k]:-1;
        return ri<rj;
    }
}

bool compare2(int i,int j){
    if(rk_[i]!=rk_[j]){
        return rk_[i]<rk_[j];
    }else{
        int ri=(i+k<allsz)?rk_[i+k]:-1;
        int rj=(j+k<allsz)?rk_[j+k]:-1;
        return ri<rj;
    }
}

bool compare(int i,int j){
    if(!nowcalc){
        return compare1(i,j);
    }else{
        return compare2(i,j);
    }
}

void buildSA(string str,vector<int> &s,vector<int> &r,vector<int> &l){
    s.resize(allsz+1);
    r.resize(allsz+1);
    l.resize(allsz+1);
    tmp.resize(allsz+1);
    rep(i,allsz+1){
        s[i]=i;
        r[i]= (i<allsz)?str[i]:-1;
    }
    for(k=1;k<=allsz;k*=2){
        int p=0;
        if(!k){
            for(int x=1;x<=allsz;x++){
                if(r[s[p]]!=r[s[x]]){
                    sort(s.begin()+p,s.begin()+x,compare);
                    p=x;
                }
            }
        }
        sort(s.begin()+p,s.end(),compare);
        tmp[s[0]]=0;
        for(int i=1;i<=allsz;i++){
            tmp[s[i]]=tmp[s[i-1]]+(compare(s[i-1],s[i])?1:0);
        }
        rep(i,allsz+1){
            r[i]=tmp[i];
        }
    }
    int h = 0;
    l[0]=0;
    rep(i,allsz){
        int j = s[r[i]-1];
        if(h>0)
            h--;
        while(i+h<allsz&&j+h<allsz){
            if(str[i+h]!=str[j+h])
                break;
            h++;
        }
        l[r[j]]=h;
    }
}

int main(){
    vector<int> pos,ls,a,b;
    cin >> ALL;
    string t;
    int fl=(int)ALL.length();
    ALL_.resize(fl);
    a.resize(fl);
    b.resize(fl);

    reverse_copy(ALL.begin(),ALL.end(), ALL_.begin());
    int m;
    cin >> m;
    int nowp = (int)ALL.length()+1;
    rep(i,m){
        pos.pb(nowp);
//        cout<<i<<" now "<<nowp<<endl;
        cin >> t;
        ALL+='$';
        ALL+=t;
        reverse(t.begin(),t.end());
        ALL_+='$';
        ALL_+=t;
        ls.pb((int)t.length());
        nowp+=ls[i]+1;
    }
//    cout<<ALL<<endl;
//    cout<<ALL_<<endl;
    allsz=(int)ALL.length();
    nowcalc = 0;
    buildSA(ALL,sa,rk,lcp);
    nowcalc = 1;
    buildSA(ALL_,sa_,rk_,lcp_);
//    rep(i,allsz){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp[i],sa[i]);
//        if(sa[i]<allsz)cout<<ALL.substr(sa[i],allsz)<<endl;
//        else cout<<endl;
//    }
//    cout<<endl;
//    rep(i,allsz+1){
//        printf("%3d:lcp:%3dsa:%3d,",i,lcp_[i],sa_[i]);
//        if(sa_[i]<allsz)cout<<ALL_.substr(sa_[i],allsz)<<endl;
//        else cout<<endl;
//
//    }
    int ans = 0;
    rep(i,m){
        if(ls[i]==1){
            continue;
        }
        fill(a.begin(),a.end(),0);
        fill(b.begin(),b.end(),0);
        int hoge = rk[pos[i]];
        int he = ls[i];
        while(he&&hoge<=allsz){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            he=min(he,lcp[hoge]);
            hoge++;
        }

        hoge = rk[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa[hoge]+he<fl){
                a[sa[hoge]+he]=max(a[sa[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp[hoge]);
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge<=allsz){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa_[hoge]+he],he);
            }
            he=min(he,lcp_[hoge]);
            hoge++;
        }

        hoge = rk_[pos[i]];
        he = ls[i];
        while(he&&hoge>=0){
            if(sa_[hoge]+he<fl){
                b[sa_[hoge]+he]=max(b[sa_[hoge]+he],he);
            }
            hoge--;
            he=min(he,lcp_[hoge]);
        }
        rep(j,fl-1){
            a[j+1]=max(a[j+1],a[j]);
            b[j+1]=max(b[j+1],b[j]);
        }
        rep(j,fl-1){
            a[fl-j-2]=max(a[fl-j-2],a[fl-j-1]-1);
            b[fl-j-2]=max(b[fl-j-2],b[fl-j-1]-1);
        }
//        rep(j,fl){
//            printf("%3d",a[j]);        }
//        cout<<endl;
//        rep(j,fl){
//            printf("%3d",b[j]);        }
//        cout<<endl;
        for(int j = 1;j < fl;j++){
            if(a[j]&&b[fl-j]&&a[j]+b[fl-j]>=ls[i]){
                ans++;
//                cout<<"ans "<<i<<endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 201100

char s[NN];

int H[NN], Rank[NN], sa[NN], n;

pi3 pos[NN];

void buildSA(){

	for(int i=0; i<=n; i++) Rank[i]=s[i];

	for(int j=0; j<19; j++){

		for(int i=0; i<n; i++)

			pos[i]=pi3(pii(Rank[i], Rank[min(n, i+(1<<j))]), i);

		sort(pos, pos+n);

		int cnt=0;

		for(int i=0; i<n; i++){

			Rank[pos[i].second]=cnt+1;

			cnt+=(pos[i].first!=pos[i+1].first);

		}

		if(cnt==n) break;

	}

	for(int i=0; i<n; i++) sa[Rank[i]]=i;

}

void Height(){

	int h=0;

	for(int i=0; i<n; i++){

		if(Rank[i]==1){

			H[Rank[i]]=0; continue;

		}

		h=max(0, h-1);

		for(int j=sa[Rank[i]-1]; s[i+h]==s[j+h]; h++);

		H[Rank[i]]=h;

	}

}

char word[1111];

int len[111];

int hei[NN][20], mi[NN][20], ma[NN][20];

int calc(int st, int ed) {

	if (st==ed) return n;

	int u=31-bclz(ed-st);

	return min(hei[st+1][u], hei[ed-(1<<u)+1][u]);

}

int calc_min(int st, int ed) {

	int u=31-bclz(ed-st+1);

	return min(mi[st][u], mi[ed-(1<<u)+1][u]);

}

int calc_max(int st, int ed) {

	int u=31-bclz(ed-st+1);

	return max(ma[st][u], ma[ed-(1<<u)+1][u]);

}

int main() {

	int m;

	scanf("%s", s);

	scanf("%d", &m);

	n=strlen(s);

	int nn=n;

	for (int i=0; i<m; i++) {

		s[n++]='*';

		scanf("%s", word);

		strcpy(s+n, word);

		len[i]=strlen(word);

		n+=len[i];

	}

	buildSA(); Height();

	for (int i=0; i<20; i++) {

		for (int j=1; j+(1<<i)<=n+1; j++) {

			if (i) hei[j][i]=min(hei[j][i-1], hei[j+(1<<(i-1))][i-1]);

			else hei[j][i]=H[j];

			if (i) mi[j][i]=min(mi[j][i-1], mi[j+(1<<(i-1))][i-1]);

			else mi[j][i]=sa[j];

			if (i) ma[j][i]=max(ma[j][i-1], ma[j+(1<<(i-1))][i-1]);

			else ma[j][i]=sa[j]<nn?sa[j]:-1;

		}

	}

	int ans=0, L=nn+1;

	for (int i=0; i<m; i++) {

		for (int k=1; k<len[i]; k++) {

			int u=Rank[L];

			int st=0, ed=u, mid;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(mid, u)<k) st=mid;

				else ed=mid;

			}

			int sst=ed;

			st=u, ed=n+1;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(u, mid)<k) ed=mid;

				else st=mid;

			}

			int eed=st;

			int ansst=calc_min(sst, eed);

			u=Rank[L+k];

			st=0, ed=u;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(mid, u)<len[i]-k) st=mid;

				else ed=mid;

			}

			sst=ed;

			st=u, ed=n+1;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(u, mid)<len[i]-k) ed=mid;

				else st=mid;

			}

			eed=st;

			int ansed=calc_max(sst, eed);

			if (ansst+k<=ansed) {

				ans++; break;

			}

		}

		L+=len[i]+1;

	}

	cout << ans << endl;

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 201100

char s[NN];

int H[NN], Rank[NN], sa[NN], n;

pi3 pos[NN];

void buildSA(){

	for(int i=0; i<=n; i++) Rank[i]=s[i];

	for(int j=0; j<19; j++){

		for(int i=0; i<n; i++)

			pos[i]=pi3(pii(Rank[i], Rank[min(n, i+(1<<j))]), i);

		sort(pos, pos+n);

		int cnt=0;

		for(int i=0; i<n; i++){

			Rank[pos[i].second]=cnt+1;

			cnt+=(pos[i].first!=pos[i+1].first);

		}

		if(cnt==n) break;

	}

	for(int i=0; i<n; i++) sa[Rank[i]]=i;

}

void Height(){

	int h=0;

	for(int i=0; i<n; i++){

		if(Rank[i]==1){

			H[Rank[i]]=0; continue;

		}

		h=max(0, h-1);

		for(int j=sa[Rank[i]-1]; s[i+h]==s[j+h]; h++);

		H[Rank[i]]=h;

	}

}

char word[1111];

int len[111];

int hei[NN][20], mi[NN][20], ma[NN][20];

int calc(int st, int ed) {

	if (st==ed) return n;

	int u=31-bclz(ed-st);

	return min(hei[st+1][u], hei[ed-(1<<u)+1][u]);

}

int calc_min(int st, int ed) {

	int u=31-bclz(ed-st+1);

	return min(mi[st][u], mi[ed-(1<<u)+1][u]);

}

int calc_max(int st, int ed) {

	int u=31-bclz(ed-st+1);

	return max(ma[st][u], ma[ed-(1<<u)+1][u]);

}

int main() {

	int m;

	scanf("%s", s);

	scanf("%d", &m);

	n=strlen(s);

	int nn=n;

	for (int i=0; i<m; i++) {

		s[n++]='*';

		scanf("%s", word);

		strcpy(s+n, word);

		len[i]=strlen(word);

		n+=len[i];

	}

	buildSA(); Height();

	for (int i=0; i<20; i++) {

		for (int j=1; j+(1<<i)<=n+1; j++) {

			if (i) hei[j][i]=min(hei[j][i-1], hei[j+(1<<(i-1))][i-1]);

			else hei[j][i]=H[j];

			if (i) mi[j][i]=min(mi[j][i-1], mi[j+(1<<(i-1))][i-1]);

			else mi[j][i]=sa[j];

			if (i) ma[j][i]=max(ma[j][i-1], ma[j+(1<<(i-1))][i-1]);

			else ma[j][i]=sa[j]<nn?sa[j]:-1;

		}

	}

	int ans=0, L=nn+1;

	for (int i=0; i<m; i++) {

		for (int k=1; k<len[i]; k++) {

			int u=Rank[L];

			int st=0, ed=u, mid;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(mid, u)<k) st=mid;

				else ed=mid;

			}

			int sst=ed;

			st=u, ed=n+1;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(u, mid)<k) ed=mid;

				else st=mid;

			}

			int eed=st;

			int ansst=calc_min(sst, eed);

			u=Rank[L+k];

			st=0, ed=u;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(mid, u)<len[i]-k) st=mid;

				else ed=mid;

			}

			sst=ed;

			st=u, ed=n+1;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(u, mid)<2) ed=mid;

				else st=mid;

			}

			eed=st;

			int ansed=calc_max(sst, eed);

			if (ansst+k<ansed) {

				ans++; break;

			}

		}

		L+=len[i]+1;

	}

	cout << ans << endl;

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 201100

char s[NN];

int H[NN], Rank[NN], sa[NN], n;

pi3 pos[NN];

void buildSA(){

	for(int i=0; i<=n; i++) Rank[i]=s[i];

	for(int j=0; j<19; j++){

		for(int i=0; i<n; i++)

			pos[i]=pi3(pii(Rank[i], Rank[min(n, i+(1<<j))]), i);

		sort(pos, pos+n);

		int cnt=0;

		for(int i=0; i<n; i++){

			Rank[pos[i].second]=cnt+1;

			cnt+=(pos[i].first!=pos[i+1].first);

		}

		if(cnt==n) break;

	}

	for(int i=0; i<n; i++) sa[Rank[i]]=i;

}

void Height(){

	int h=0;

	for(int i=0; i<n; i++){

		if(Rank[i]==1){

			H[Rank[i]]=0; continue;

		}

		h=max(0, h-1);

		for(int j=sa[Rank[i]-1]; s[i+h]==s[j+h]; h++);

		H[Rank[i]]=h;

	}

}

char word[1111];

int len[111];

int hei[NN][20], mi[NN][20], ma[NN][20];

int calc(int st, int ed) {

	if (st==ed) return n;

	int u=31-bclz(ed-st);

	return min(hei[st+1][u], hei[ed-(1<<u)+1][u]);

}

int calc_min(int st, int ed) {

	int u=31-bclz(ed-st+1);

	return min(mi[st][u], mi[ed-(1<<u)+1][u]);

}

int calc_max(int st, int ed) {

	int u=31-bclz(ed-st+1);

	return max(ma[st][u], ma[ed-(1<<u)+1][u]);

}

int main() {

	int m;

	scanf("%s", s);

	scanf("%d", &m);

	n=strlen(s);

	int nn=n;

	for (int i=0; i<m; i++) {

		s[n++]='*';

		scanf("%s", word);

		strcpy(s+n, word);

		len[i]=strlen(word);

		n+=len[i];

	}

	buildSA(); Height();

	for (int i=0; i<20; i++) {

		for (int j=1; j+(1<<i)<=n+1; j++) {

			if (i) hei[j][i]=min(hei[j][i-1], hei[j+(1<<(i-1))][i-1]);

			else hei[j][i]=H[j];

			if (i) mi[j][i]=min(mi[j][i-1], mi[j+(1<<(i-1))][i-1]);

			else mi[j][i]=sa[j];

			if (i) ma[j][i]=max(ma[j][i-1], ma[j+(1<<(i-1))][i-1]);

			else ma[j][i]=sa[j]<nn?sa[j]:-1;

		}

	}

	int ans=0, L=nn+1;

	for (int i=0; i<m; i++) {

		for (int k=1; k<len[i]; k++) {

			int u=Rank[L];

			int st=0, ed=u, mid;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(mid, u)<k) st=mid;

				else ed=mid;

			}

			int sst=ed;

			st=u, ed=n+1;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(u, mid)<k) ed=mid;

				else st=mid;

			}

			int eed=st;

			int ansst=calc_min(sst, eed);

			u=Rank[L+k];

			st=0, ed=u;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(mid, u)<len[i]-k) st=mid;

				else ed=mid;

			}

			sst=ed;

			st=u, ed=n+1;

			while (ed-st>1) {

				mid=st+ed>>1;

				if (calc(u, mid)<2) ed=mid;

				else st=mid;

			}

			eed=st;

			int ansed=calc_max(sst, eed);

			if (ansst+k<=ansed) {

				ans++; break;

			}

		}

		L+=len[i]+1;

	}

	cout << ans << endl;

	return 0;

}


#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> c(n), t(n);
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    vector<ll> d1, d2;
    for (int i = 1; i < n; i++)
    {
        d1.push_back(c[i] - c[i - 1]);
        d2.push_back(t[i] - t[i - 1]);
    }
    sort(d1.begin(), d1.end());
    sort(d2.begin(), d2.end());
    cout << (d1 == d2 ? "Yes" : "No") << endl;
}


#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

// gcd(a, b)
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> c(n), t(n);
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    if (c[0] != t[0] || c[n - 1] != t[n - 1])
    {
        cout << "No" << endl;
        return 0;
    }
    if (n == 2)
    {
        cout << "Yes" << endl;
        return 0;
    }
    ll g = t[0] - t[1] + t[2];
    for (int i = 1; i < n - 1; i++)
        g = gcd(g, t[i - 1] - t[i] + t[i + 1]);
    for (int i = 1; i < n - 1; i++)
    {
        if (abs(c[i] - t[i]) % g)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

// gcd(a, b)
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> c(n), t(n);
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    if (c[0] != t[0] || c[n - 1] != t[n - 1])
    {
        cout << "No" << endl;
        return 0;
    }
    ll g = abs(t[0] - t[1] + t[2]);
    for (int i = 1; i < n - 1; i++)
        g = gcd(g, abs(t[i - 1] - t[i] + t[i + 1]));
    for (int i = 1; i < n - 1; i++)
    {
        if (abs(c[i] - t[i]) % g)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> c(n), t(n);
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    if (c[0] != t[0] || c[n - 1] != t[n - 1])
    {
        cout << "No" << endl;
        return 0;
    }
    vector<ll> d1, d2;
    for (int i = 1; i < n; i++)
    {
        d1.push_back(c[i] - c[i - 1]);
        d2.push_back(t[i] - t[i - 1]);
    }
    sort(d1.begin(), d1.end());
    sort(d2.begin(), d2.end());
    cout << (d1 == d2 ? "Yes" : "No") << endl;
}


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
typedef long long ll;
using namespace std;

const int MAXN = 1e5 + 5;
int N;
int A[MAXN];
int B[MAXN];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    if (A[0] != B[0]) {
        cout << "No" << endl;
        return 0;
    }
    for (int l = 0; l < 2; l++) {
        unordered_multiset<int> diffs;
        for (int i = 1; i < N; i++) {
            diffs.insert(A[i + 1] - A[i]);
        }
        for (int i = 1; i < N - 1; i++) {
            if (B[i] == A[i]) {
                diffs.erase(A[i] - A[i - 1]);
                continue;
            }
            int diff = B[i] - A[i];
            int cur = B[i - 1] - A[i];
            int needVal = diff - cur;
            // cout << diff << ' ' << cur << ' ' << needVal << endl;
            auto x = diffs.find(needVal);
            if (x != diffs.end()) {
                diffs.erase(A[i] - A[i - 1]);
                continue;
            } else {
                goto done;
            }
        }
        cout << "Yes" << endl;
        return 0;
    done:
        reverse(A, A + N);
        reverse(B, B + N);
    }
    cout << "No" << endl;
}


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
typedef long long ll;
using namespace std;

const int MAXN = 1e6 + 5;
int N, M;
int cnt[MAXN];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }
}


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
typedef long long ll;
using namespace std;

const int MAXN = 1e5 + 5;
int N;
int A[MAXN];
int B[MAXN];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    if (A[0] != B[0]) {
        cout << "No" << endl;
        return 0;
    }
    for (int l = 0; l < 2; l++) {
        unordered_multiset<int> diffs;
        for (int i = 1; i < N; i++) {
            diffs.insert(A[i + 1] - A[i]);
        }
        for (int i = 1; i < N - 1; i++) {
            if (B[i] == A[i]) {
                // diffs.erase(A[i] - A[i - 1]);
                continue;
            }
            int diff = B[i] - A[i];
            int cur = B[i - 1] - A[i];
            int needVal = diff - cur;
            // cout << diff << ' ' << cur << ' ' << needVal << endl;
            auto x = diffs.find(needVal);
            if (x != diffs.end()) {
                // diffs.erase(A[i] - A[i - 1]);
                continue;
            } else {
                goto done;
            }
        }
        cout << "Yes" << endl;
        return 0;
    done:
        reverse(A, A + N);
        reverse(B, B + N);
    }
    cout << "No" << endl;
}


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
typedef long long ll;
using namespace std;

const ll MAXN = 1e5 + 5;
ll N;
ll A[MAXN];
ll B[MAXN];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> B[i];
    }
    vector<int> diffA, diffB;
    for (int i = 0; i < N; i++) {
        diffA.push_back(A[i + 1] - A[i]);
        diffB.push_back(B[i + 1] - B[i]);
    }
    sort(all(diffA)), sort(all(diffB));
    for (int i = 0; i < diffA.size(); i++) {
        if (diffA[i] != diffB[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
typedef long long ll;
using namespace std;

const ll MAXN = 1e5 + 5;
ll N;
ll A[MAXN];
ll B[MAXN];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> B[i];
    }
    if (A[0] != B[0]) {
        cout << "No" << endl;
        return 0;
    }
    for (ll l = 0; l < 2; l++) {
        unordered_multiset<ll> diffs;
        for (ll i = 1; i < N; i++) {
            diffs.insert(A[i + 1] - A[i]);
        }
        for (ll i = 1; i < N - 1; i++) {
            if (B[i] == A[i]) {
                // diffs.erase(A[i] - A[i - 1]);
                continue;
            }
            ll diff = B[i] - A[i];
            ll cur = B[i - 1] - A[i];
            ll needVal = diff - cur;
            // cout << diff << ' ' << cur << ' ' << needVal << endl;
            auto x = diffs.find(needVal);
            if (x != diffs.end()) {
                // diffs.erase(A[i] - A[i - 1]);
                continue;
            } else {
                goto done;
            }
        }
        cout << "Yes" << endl;
        return 0;
    done:
        reverse(A, A + N);
        reverse(B, B + N);
    }
    cout << "No" << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef unsigned long long ull;

#define X first
#define Y second
#define pb push_back
#define EL printf("\n")
#define sz(A) (int)A.size()
#define FOR(i, l, r) for (int i = l; i <= r; i++)
#define FOD(i, r, l) for (int i = r; i >= l; i--)
#define faster                                                                 \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);

const int N = 1e5 + 5;
int n, a[N], b[N];

int main() {

    faster;

    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];

    if (a[1] != b[1] || a[n] != b[n]) {
        cout << "No\n";
        return 0;
    }

    multiset<int> diffA, diffB;
    FOR(i, 1, n - 1) {
        diffA.insert(a[i + 1] - a[i]);
        diffB.insert(b[i + 1] - b[i]);
    }

    if (diffA == diffB) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef unsigned long long ull;

#define X first
#define Y second
#define pb push_back
#define EL printf("\n")
#define sz(A) (int)A.size()
#define FOR(i, l, r) for (int i = l; i <= r; i++)
#define FOD(i, r, l) for (int i = r; i >= l; i--)
#define faster                                                                 \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);

const int N = 1e5 + 5;
int n, a[N], b[N];

int main() {

    faster;

    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];

    if (a[1] != b[1] && a[n] != b[n]) {
        cout << "No\n";
        return 0;
    }

    set<int> diffA, diffB;
    FOR(i, 1, n - 1) {
        diffA.insert(a[i + 1] - a[i]);
        diffB.insert(b[i + 1] - b[i]);
    }

    if (diffA == diffB) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}