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

Problem Statement

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

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



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

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



Input

An input is given in the following format.


S
N
p_1
p_2
$\vdots$
p_N


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



Constraints

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



Output

Print the minimum number of operations in one line.

Sample Input 1


brainfuck
1
fuck


Sample Output 1


1

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

Sample Input 2


aaa
1
a


Sample Output 2


3

You have to operate for all characters.

Sample Input 3


hellshakeyano
3
hell
shake
key


Sample Output 3


2

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





Example

Input

brainfuck
1
fuck


Output

1

Solution (in CPP):

Solution:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(iinclude<snt i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

typedef pair<int, P> speP;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll mod_pow(ll x, ll n, ll m) {
	ll ret = 1;
	while (n) {
		if (n % 2)ret = ret * x%m;
		x = x * x%m; n >>= 1;
	}
	return ret;

}

struct rolling_hash {
private:
	int sz;
	vector<ll> node;
	vector<ll> r;
	ll t = 999999937;
	ll m = 1000000009;
	ll invt;
public:
	rolling_hash(const string &s) {
		int n = s.length();
		sz = n;
		node.resize(n + 1); r.resize(n + 1);
		node[0] = 0;

		invt = mod_pow(t, m - 2, m);
		ll a = 1;
		rep(i, n) {
			//r[i] = a;
			int z = s[i] - 'a';
			node[i + 1] = node[i] + a * z;
			node[i + 1] %= m;
			a = a * t%m;
		}
		a = 1;
		rep(i, n) {
			r[i] = a; a = invt * a%m;
		}
	}
	ll calc(int le, int len) {
		ll ret = node[le + len] - node[le];
		if (ret < 0)ret += m;
		ret = ret * r[le] % m;
		return ret;
	}
	ll on_hash(const string &s) {
		ll ret = 0;
		int len = s.length();
		ll a = 1;
		rep(i, len) {
			int z = s[i] - 'a';
			ret = (ret + a * z) % m;
			a = t * a%m;
		}
		return ret;
	}
};

vector<P> v;

//map<int, bool> mp[301];

int lemin[1 << 17];

bool comp(string &s, string &t) {
	return s.length() < t.length();
}

void solve() {
	string s; cin >> s;
	int m = s.length();
	rolling_hash r(s);

	fill(lemin, lemin + m, mod);


	int n; cin >> n;
	vector<string> st(n);
	rep(i, n) {
		cin >> st[i];
	}
	sort(st.begin(), st.end(), comp);
	rep(i, n) {
		if (st[i].size() < 300) {
			int le = i;
			while (i + 1 < n&&st[i].size() == st[i + 1].size())i++;
			map<int, bool> mp;
			for (int j = le; j <= i;j++) {
				ll ro = r.on_hash(st[j]);
				mp[ro] = true;
			}
			int len = st[i].size();
			rep(j, m - len + 1) {
				ll c = r.calc(j, len);
				if (mp[c]) {
					lemin[j] = min(lemin[j], j + len);
				}
			}
		}
		else {
			int len = st[i].length();
			ll ro = r.on_hash(st[i]);
			rep(j, m - len + 1) {
				ll le = r.calc(j, len);
				if (le == ro) {
					lemin[j] = min(lemin[j], j + len);
					//v.push_back({ j + len,j });
				}
			}
		}
	}

	rep(i, m) {
		if (lemin[i] < mod) {
			v.push_back({ lemin[i],i });
			//cout << i << " " << lemin[i] << endl;
		}
	}

	int le = -1;
	int ans = 0;



	sort(v.begin(), v.end());
	rep(i, v.size()) {
		if (le < v[i].second) {
			le=v[i].first-1; ans++;
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}