#pragma GCC target("avx") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include using namespace std; using uint = unsigned; using ull = unsigned long long; constexpr ull mod = 0x1fffffffffffffff, base = 257; constexpr ull mask(int a) { return (1ull << a) - 1; } inline constexpr ull mul(ull a, ull b) { __uint128_t ans = __uint128_t(a) * b; ans = (ans >> 61) + (ans & mask(61)); if(ans >= mod) ans -= mod; return ans; } struct RollingHash { ull hashed[50001], power[50001]; RollingHash(const string &s) { power[0] = 1; for(uint i = 0; i < s.size(); i++) { power[i + 1] = mul(power[i], base); hashed[i + 1] = mul(hashed[i], base) + s[i]; if(hashed[i + 1] >= mod) hashed[i + 1] -= mod; } } ull get(uint l, uint r) const { ull ret = hashed[r] + mod - mul(hashed[l], power[r - l]); if(ret >= mod) ret -= mod; return ret; } }; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; int m; cin >> s >> m; RollingHash rh(s); int ans = 0; for(uint i = 0; i < m; i++) { string t; cin >> t; __uint128_t rh2 = 0; for(auto i : t) { rh2 *= base; rh2 = (rh2 >> 61) + (rh2 & mask(61)); rh2 += i; if(rh2 >= mod) rh2 -= mod; } for(uint i = t.size(); i < s.size() + 1; i++) ans += rh.get(i - t.size(), i) == rh2; } cout << ans << endl; }