#include #include #include #define ABC "ABCDEFGHIJKLMNOPQRSTUVWXYZ" using namespace std; string s; int n; string *c; int d[100000]; unsigned int i, j, k, anser = 0; void scan() { cin >> s; cin >> n; c = new string[n]; for (i = 0; i < n; i++) { cin >> c[i]; } } long long tolong(string ss) { long long result = 0; long long p = 1; for (j = 0; j < ss.size(); j++) { result += d[ss[j]] * p; p *= 26; } return result; } int main(void) { scan(); for (i = 0; i < 26; i++) { d[ABC[i]] = i; } for (i = 0; i < n; i++) { long long search = tolong(c[i]); long long p = 1, l = 0; for (j = 0; j < c[i].size() - 1; j++) { l += d[s[j]] * p; p *= 26; } for (j = c[i].size() - 1; j < s.size(); j++) { l += d[s[j]] * p; if (l == search) { anser++; } l /= 26; } } cout << anser << endl; return 0; }