#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair i_ll; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define pb push_back int INF = INT_MAX / 10; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int mod_inv(ll x, int M) { int t = M - 2, y = 1; for (; t; t>>=1) { if (t & 1) y = y * x % M; x = x * x % M; } return y; } struct rolling_hash { int M; vector a, b; rolling_hash(string s, int _M) { M = _M; int N = s.length(); a.resize(N + 1); ll x = 1; for (int i = 0; i < N; i++) { a[i + 1] = (a[i] + x * s[i]) % M; x = x * 256 % M; } ll inv = mod_inv(256, M); b.resize(N + 1); b[0] = 1; for (int i = 0; i < N; i++) b[i + 1] = b[i] * inv % M; } int get(int l, int r) { return ((ll)(a[r] - a[l]) * b[l] % M + M) % M; } }; int main() { string s; cin >> s; int N = s.length(); rolling_hash a(s, _MOD); vector > mp(11); for (int d = 1; d <= 10; d++) for (int l = 0; l + d <= N; l++) mp[d][a.get(l, l + d)]++; int M; cin >> M; ll ans = 0; while (M--) { string t; cin >> t; rolling_hash b(t, _MOD); ans += mp[t.length()][b.get(0, t.length())]; } cout << ans << endl; }