#include using namespace std; int64_t random_number(int64_t n) { mt19937_64 mt(std::chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution dist(0, n - 1); return dist(mt); } const int64_t MOD = ((int64_t)1 << 61) - 1; const int64_t MASK30 = ((int64_t)1 << 30) - 1; const int64_t MASK31 = ((int64_t)1 << 31) - 1; const int64_t MASK61 = ((int64_t)1 << 61) - 1; int64_t base = random_number(MOD); int64_t mod(int64_t x) { int64_t res = (x >> 61) + (x & MASK61); if (res >= MOD) res -= MOD; return res; } int64_t mul(int64_t a, int64_t b) { int64_t au = (a >> 31), ad = (a & MASK31); int64_t bu = (b >> 31), bd = (b & MASK31); int64_t c = (au * bd + ad * bu); int64_t cu = (c >> 30), cd = (c & MASK30); return mod(au * bu * 2 + cu + (cd << 31) + ad * bd); } int64_t add(int64_t a, int64_t b) { return mod(a + b); } int64_t sub(int64_t a, int64_t b) { int64_t res = a - b; if (res < 0) res += MOD; return res; } int main() { string S; int M; cin >> S >> M; map mp; for (int k = 1; k <= 10; ++k) { int64_t h = 0, t = 1; for (int i = 0; i < k; ++i) { h = add(mul(h, base), S[i]); t = mul(t, base); } for (int i = 0; i + k <= (int)S.size(); ++i) { mp[h]++; if (i + k < (int)S.size()) { h = sub(add(mul(h, base), S[i + k]), mul(S[i], t)); } } } int ans = 0; for (int q = 0; q < M; ++q) { string C; cin >> C; int64_t ch = 0; for (auto&& c : C) { ch = add(mul(ch, base), c); } ans += mp[ch]; } cout << ans << endl; return 0; }