#include #include #include using namespace std; using ll = long long; struct RollingHash { ll base = 1007, MOD = 1e9 + 7; vector hash, pow; RollingHash(string s) { int n = (int)s.size(); hash.assign(n + 1, 0); pow.assign(n + 1, 1); for (int i = 0; i < n; i++) { hash[i + 1] = (hash[i] * base + s[i]) % MOD; pow[i + 1] = pow[i] * base % MOD; } } ll get(int l, int r) { ll res = (hash[r] - hash[l] * pow[r - l]) % MOD; if (res < 0) res += MOD; return res; } }; int main() { string s; cin >> s; int m; cin >> m; vector c(m); for (int i = 0; i < m; i++) cin >> c[i]; RollingHash rh(s); map mp; for (int i = 1; i <= 10; i++) { for (int j = 0; j + i <= (int)s.size(); j++) { ll hash = rh.get(j, j + i); mp[hash]++; } } ll ans = 0; for (int i = 0; i < m; i++) { RollingHash now(c[i]); ll hash = now.get(0, (int)c[i].size()); ans += mp[hash]; } cout << ans << endl; return 0; }