#ifdef LOCAL #define debug(_) cerr << #_ << ": " << (_) << '\n' #define _GLIBCXX_DEBUG #else #define debug(_) (void(0)) #endif // LOCAL #include using namespace std; int kmp_count(string &s, string &w) { // テーブル構築 vector T(w.size() + 1, 0); T[0] = -1; int i = 2, j = 0; for (i = 2; i <= w.size(); i++){ if (w[j] == w[i - 1]) { j++; T[i] = j; } else if (j > 0) { j = T[j]; } } // 検索 int ret = 0; int m = 0; i = 0; while (m + i < s.size()) { if (w[i] == s[m + i]) { i++; if (i == w.size()) { ret++; m = m + i - T[i]; i = T[i]; } } else { m = m + i - T[i]; if (i > 0) { i = T[i]; } } } // cout << ret << endl; return ret; } int main(){ string S; cin >> S; int M; cin >> M; string C; int ans = 0; for (int i = 0; i < M; i++){ cin >> C; ans += kmp_count(S, C); } cout << ans << '\n'; return 0; }