#include #include #include #include #include #include #include #include using namespace std; int main() { string s; cin >> s; int m; cin >> m; int ans = 0; for (int i = 0; i < m; i++) { string target; cin >> target; if (target.size() > s.size())continue; long long hash = 0,target_hash=0; for (int j = 0; j < target.size(); j++) target_hash += (target[j] - 'A')*pow(26, j); for (int j = 0; j < target.size(); j++) hash += (s[j] - 'A')*pow(26, j); if (hash == target_hash)ans++; //cout << target_hash << endl; //cout << target_hash << endl; for (int j = target.size(); j < s.size(); j++) { hash -= s[j - target.size()] - 'A'; hash /= 26; hash += (s[j] - 'A')*pow(26, target.size() - 1); if (hash == target_hash)ans++; //cout << hash << endl; } } cout << ans << endl; return 0; }