#include using namespace std; class RollingHash { private: using u64 = std::uint_fast64_t; const u64 mod = (1ULL << 61) - 1; std::vector hashes, pows; inline u64 add(u64 a, u64 b) const { a += b; if (a >= mod) a -= mod; return a; } inline u64 sub(u64 a, u64 b) const { if (a < b) a += mod; a -= b; return a; } inline u64 mul(u64 a, u64 b) const { u64 ah = a >> 31, al = a & ((1ULL << 31) - 1), bh = b >> 31, bl = b & ((1ULL << 31) - 1), m = ah * bl + al * bh, v = (ah * bh << 1) + (m >> 30) + ((m & ((1ULL << 30) - 1)) << 31) + al * bl; v = (v & ((1ULL << 61) - 1)) + (v >> 61); return v; } public: RollingHash(const std::string &S, u64 base = 10007) : hashes((int)S.size() + 1, 0), pows((int)S.size() + 1, 0) { int sz = (int)S.size(); pows[0] = 1; for (int i = 0; i < sz; i++) { pows[i + 1] = mul(pows[i], base); hashes[i + 1] = add(mul(hashes[i], base), S[i]); } } u64 slice(int l, int r) const { return sub(hashes[r], mul(hashes[l], pows[r - l])); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); string S; cin >> S; RollingHash rhs(S); int M; cin >> M; int res = 0; for (int i = 0; i < M; i++) { string C; cin >> C; RollingHash rhc(C); for (int i = 0; i + (int)C.size() < (int)S.size() + 1; i++) { if (rhs.slice(i, i + (int)C.size()) == rhc.slice(0, (int)C.size())) res++; } } cout << res << '\n'; return 0; }