// https://yukicoder.me/problems/no/430 // ハッシュは文字に数字0を対応させると衝突が起こる(AとAAが同じハッシュになる) // なので必ず1から対応させる #include using namespace std; using ll = long long; using ull = unsigned long long; #define rep0(i,n) for(int i=0; i &mp){ int t_len = text.length(); rep1(len, min(10, t_len)){ ll t_hash = 0; rep0(i, len){ t_hash += powpowm(base, len - 1 - i, mod) * (ll)(text[i] + 1 - 'A'); t_hash %= mod; } mp[t_hash] += 1; // 先頭文字でforを回してt_hashを更新していく for(int i=1; i<=t_len-len; ++i){ ll new_hash = (base * t_hash) % mod; new_hash = (new_hash - powpowm(base, len, mod) * (text[i-1] + 1 - 'A') + mod) % mod; new_hash += (text[i + len - 1] + 1 - 'A'); new_hash %= mod; t_hash = new_hash; mp[t_hash] += 1; } } } int main(){ ll mod1 = 1000000007; ll mod2 = 998244353; string S; cin >> S; int M; cin >> M; map mp1; MakeRollingHashMap(S, mod1, mp1); map mp2; MakeRollingHashMap(S, mod2, mp2); int ans = 0; rep1(i, M){ string C; cin >> C; ll hsh1 = CalcHash(C, mod1); ll hsh2 = CalcHash(C, mod2); if(mp1.count(hsh1) && mp2.count(hsh2)) ans += mp1[hsh1]; } cout << ans << endl; }