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 <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <functional>
using namespace std;

template<typename Type> class RangeMin {
private:
	int size_;
	std::vector<Type> dat;
public:
	RangeMin() : size_(0), dat(std::vector<Type>()) {};
	RangeMin(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RangeMin(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(int l, int r) {
		Type ret = std::numeric_limits<Type>::max();
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};

long long power[100009]; const long long HASH = 311;

class RollingHash {
public:
	string A; vector<long long>dat;

	void init(string T) {
		A = T;
		dat.resize(A.size() + 1, 0);
		dat[0] = 0;
		for (int i = 0; i < A.size(); i++) {
			dat[i + 1] = dat[i] * HASH + A[i];
		}
	}
	long long roll(long long l, long long r) {
		// 半開区間
		return (dat[r] - power[r - l] * dat[l]);
	}
};

void init_math() {
	power[0] = 1;
	for (int i = 1; i <= 100008; i++) power[i] = HASH * power[i - 1];
}
long long hash_value(string S) {
	long long F = 0;
	for (int i = 0; i < S.size(); i++) F = F * HASH + S[i];
	return F;
}

string S, T[100009]; int n;
vector<pair<int, string>>X; vector<int>J; vector<pair<int, int>>Z;
vector<pair<long long, int>>vec;

int main() {
	cin >> S >> n; init_math();
	for (int i = 1; i <= n; i++) { cin >> T[i]; X.push_back(make_pair(T[i].size(), T[i])); }
	sort(X.begin(), X.end());
	for (int i = 1; i <= n; i++) T[i] = X[i - 1].second;

	RollingHash A; A.init(S);
	RangeMin<int> Y(S.size() + 2);

	for (int i = 1; i <= n; i++) {
		if (T[i].size() >= 100) {
			long long V1 = hash_value(T[i]);

			for (int j = 0; j < S.size() - T[i].size() + 1; j++) {
				if (Y.query(j, j + T[i].size()) <= j + T[i].size()) continue;
				if (A.roll(j, j + T[i].size()) == V1) {
					Z.push_back(make_pair(j, j + T[i].size() - 1));
					
					Y.update(j, min(Y.query(j, j + 1), (int)j + (int)T[i].size()));
				}
			}
		}

		else {
			if (i == 0 || T[i].size() != T[i - 1].size()) {
				vec.clear();
				for (int j = 0; j < S.size() - T[i].size() + 1; j++) {
					if (Y.query(j, j + T[i].size()) <= j + T[i].size()) continue;
					
					vec.push_back(make_pair(A.roll(j, j + T[i].size()), j));
				}
				sort(vec.begin(), vec.end());
			}
			long long V1 = hash_value(T[i]);
			int pos1 = lower_bound(vec.begin(), vec.end(), make_pair(V1, 0)) - vec.begin();

			for (int j = pos1; j < vec.size(); j++) {
				if (vec[j].first != V1) break;
				Z.push_back(make_pair(vec[j].second, vec[j].second + T[i].size() - 1));
				
				Y.update(vec[j].second, min(Y.query(vec[j].second, vec[j].second + 1), (int)vec[j].second + (int)T[i].size()));
			}
		}
	}
	sort(Z.begin(), Z.end());
	
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>Q;
	for (int i = 0; i < Z.size(); i++) Q.push(make_pair(Z[i].second, Z[i].first));

	int cx = 0, cnt = 0;

	while (!Q.empty()) {
		cnt++;
		cx = Q.top().first;
		while (!Q.empty() && Q.top().second <= cx) Q.pop();
	}
	cout << cnt << endl;
	return 0;
}