#include #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using namespace std; using ll = long long; using PL = pair; using P = pair; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; struct RollingHash { using u64 = unsigned long long; static const u64 M1 = 2147483647,M2 = 1000000007; static u64 B1,B2; int N; vector hash1,hash2,power1,power2; RollingHash(string &s) { N = s.size(); power1.resize(N + 1); power2.resize(N + 1); hash1.resize(N + 1); hash2.resize(N + 1); power1[0] = 1; power2[0] = 1; hash1[0] = 0; hash2[0] = 0; for (int i = 0;i < N; ++i) { power1[i + 1] = power1[i] * B1 % M1; power2[i + 1] = power2[i] * B2 % M2; hash1[i + 1] = (hash1[i] * B1 + s[i]) % M1; hash2[i + 1] = (hash2[i] * B2 + s[i]) % M2; } } // retunr hash of S pair get() { return make_pair(hash1[N],hash2[N]); } // return hash of S[0,k) pair get(int k) { return make_pair(hash1[k],hash2[k]); } // return hash of S[l,r) pair get(int l,int r) { u64 x = (hash1[r] - (hash1[l] * power1[r - l]) % M1 + M1) % M1; u64 y = (hash2[r] - (hash2[l] * power2[r - l]) % M2 + M2) % M2; return make_pair(x,y); } //return if S[l1,r1) == S[l2,r2) bool equal(int l1,int r1,int l2,int r2) { return get(l1,r1) == get(l2,r2); } }; mt19937_64 mt; uniform_int_distribution rand1(1,RollingHash::M1 - 1); uniform_int_distribution rand2(1,RollingHash::M2 - 1); unsigned long long RollingHash::B1 = rand1(mt); unsigned long long RollingHash::B2 = rand2(mt); using u64 = unsigned long long; using Pu = pair; int main() { string S; cin >> S; RollingHash rh(S); map mp; for (int l = 0;l < S.size(); ++l) { for (int r = l + 1;r <= min(l + 10,(int)S.size()); ++r) { Pu x = rh.get(l,r); mp[rh.get(l,r)] ++; } } ll ans = 0; int M; cin >> M; rep(i,M) { string a; cin >> a; RollingHash rha(a); ans += mp[rha.get()]; } cout << ans << '\n'; return 0; }