#include #include #include #include #include using namespace std; typedef unsigned long long ull; const ull B = 100000007; int main() { string s; cin >> s; int m; cin >> m; vector c(m); for (int i = 0; i < m; i++) { cin >> c[i]; } vector > hash_s; hash_s = vector >(11, vector(s.size(), 0)); for (int l = 1; l <= 10; l++) { if (l > s.size()) { break; } ull b_pow_l = 1; for (int i = 0; i < l; i++) { b_pow_l *= B; } ull hs = 0; for (int i = 0; i < l; i++) { hs = hs * B + s[i]; } hash_s[l][0] = hs; for (int i = 0; i + l < s.size(); i++) { hs = hs * B + s[i + l] - s[i] * b_pow_l; hash_s[l][i+1] = hs; } } long long ans = 0; for (int i = 0; i < m; i++) { if (s.size() < c[i].size()) { continue; } ull hc = 0; for (int j = 0; j < c[i].size(); j++) { hc = hc * B + c[i][j]; } int l = c[i].size(); for (int j = 0; j + l <= s.size(); j++) { if (hash_s[l][j] == hc) { ans++; } } } cout << ans << endl; return 0; }