#include using namespace std; #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define rep(i, n) repl(i, 0, n) using ll = long long; using u64 = std::uint_fast64_t; using size_type = std::uint_fast32_t; static constexpr __int128_t o = 0; static constexpr u64 MOD = (1uL << 61) - 1; static constexpr u64 base = 20200213; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s; int m; cin >> s >> m; int n = s.size(); map<__int128_t, int> M; __int128_t K = base; repl(i, 1, min(11, n + 1)) { __int128_t H = o; rep(j, i) H = (H * base + s[j]) % MOD; M[H]++; rep(j, n - i) { H = (H * base - s[j] * K + s[j + i] + MOD) % MOD; M[H]++; } K = K * base % MOD; } int ans = 0; while (m--) { string t; cin >> t; __int128_t now = o; for (auto c : t) now = (now * base + c) % MOD; ans += M[now]; } cout << ans << endl; return 0; }