#include using namespace std; struct rolling_hash { string s; vector hash, bp; uint64_t b = 1007; int n; rolling_hash(const string &s) : s(s), n(s.size()) { hash.resize(n + 1); bp.resize(n + 1); hash[0] = 0; bp[0] = 1; for (int i = 0; i < n; i++) { hash[i + 1] = hash[i] * b + s[i]; bp[i + 1] = bp[i] * b; } } //[l, r) uint64_t get_hash(int l, int r) { assert(0 <= l && l < r && r <= n); return hash[r] - bp[r - l] * hash[l]; } }; int main() { string s; cin >> s; rolling_hash s_hash(s); int m; cin >> m; int ans = 0; for (int i = 0; i < m; i++) { string t; cin >> t; rolling_hash t_hash(t); uint64_t puni = t_hash.get_hash(0, t.size()); for (int j = 0; j + t.size() <= s.size(); j++) { if (puni == s_hash.get_hash(j, j + t.size())) { ans++; } } } cout << ans << endl; return 0; }