#include #include #include #include using namespace std; using ll = long long; constexpr ll MOD = 998244353; int main(){ string s0; cin >> s0; int m; cin >> m; vector c0(m); for(auto &it: c0) cin >> it; vector s(s0.size()); for(int i = 0; i < s0.size(); i++) s[i] = s0[i]-'A'+1; vector> c(m); for(int i = 0; i < m; i++){ c[i] = vector(c0[i].size()); for(int j = 0; j < c0[i].size(); j++) c[i][j] = c0[i][j]-'A'+1; } // hashs[i][j] := s[j, j+i) のハッシュ値 vector> hashs(11, vector(s.size())); const ll b = 314152; for(int i = 1; i <= min(10, (int)s.size()); i++){ hashs[i][0] = 0; ll bm = 1; for(int j = i-1; j >= 0; j--){ hashs[i][0] += s[j]*bm%MOD; hashs[i][0] %= MOD; bm *= b; bm %= MOD; } for(int j = 1; j+i-1 < s.size(); j++){ hashs[i][j] = (hashs[i][j-1]*b - s[j-1]*bm + s[j+i-1] +MOD)%MOD; } } ll ans = 0; for(const auto &vec: c){ ll hs = 0; ll bm = 1; for(int j = vec.size()-1; j >= 0; j--){ hs += vec[j]*bm%MOD; hs %= MOD; bm *= b; bm %= MOD; } for(int i = 0; i+vec.size()-1 < s.size(); i++){ if(hashs[vec.size()][i] == hs) ans++; } } cout << ans << endl; return 0; }