#include using namespace std; class Random { private: static inline std::mt19937 mt{std::random_device()()}; public: template static T random(T hi) { std::uniform_int_distribution uid(0, hi); return uid(mt); } template static T random(T lo, T hi) { std::uniform_int_distribution uid(lo, hi); return uid(mt); } }; class RollingHash { private: const uint64_t mod = (UINT64_C(1) << 61) - 1; static inline uint64_t base = Random::random(UINT64_C(10007), UINT64_C(1) << 28); std::vector hashes, pows; uint64_t add(uint64_t a, uint64_t b) const { a += b; if (a >= mod) a -= mod; return a; } uint64_t sub(uint64_t a, uint64_t b) const { if (a < b) a += mod; a -= b; return a; } uint64_t mul(uint64_t a, uint64_t b) const { uint64_t ah = a >> 31, al = a & ((UINT64_C(1) << 31) - 1), bh = b >> 31, bl = b & ((UINT64_C(1) << 31) - 1), m = ah * bl + al * bh, v = (ah * bh << 1) + (m >> 30) + ((m & ((UINT64_C(1) << 30) - 1)) << 31) + al * bl; v = (v & ((UINT64_C(1) << 61) - 1)) + (v >> 61); return v; } public: template RollingHash(const T &S) : hashes(S.size() + 1, 0), pows(S.size() + 1, 0) { pows[0] = 1; for (size_t i = 0; i < S.size(); i++) { pows[i + 1] = mul(pows[i], base); hashes[i + 1] = add(mul(hashes[i], base), S[i]); } } template RollingHash(const T &S, const uint64_t base) : hashes(S.size() + 1, 0), pows(S.size() + 1, 0) { pows[0] = 1; for (size_t i = 0; i < S.size(); i++) { pows[i + 1] = mul(pows[i], base); hashes[i + 1] = add(mul(hashes[i], base), S[i]); } } // S[l, r) uint64_t 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; int M; cin >> M; RollingHash rhs(S); int res = 0; for (int i = 0; i < M; i++) { string C; cin >> C; RollingHash rhc(C); for (int j = 0; j + (int)C.size() < (int)S.size() + 1; j++) { if (rhs.slice(j, j + (int)C.size()) == rhc.slice(0, (int)C.size())) res++; } } cout << res << '\n'; return 0; }