//#include #include //#include using namespace std; //using namespace atcoder; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef pair p; const int INF = 1e9; const double eps = 1e-7; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; const long double pi = 4 * atan(1); #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout< hash1, hash2, pow1, pow2; public: RollingHash(const string &S) { int n = (int)S.size(); hash1.assign(n + 1, 0); hash2.assign(n + 1, 0); pow1.assign(n + 1, 1); pow2.assign(n + 1, 1); for (int i = 0; i < n; ++i) { hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1; hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2; pow1[i + 1] = (pow1[i] * base1) % mod1; pow2[i + 1] = (pow2[i] * base2) % mod2; } } /** * S の [l, r) のハッシュ値を返す * O(1) */ inline pair get(int l, int r) const { ll res1 = hash1[r] - hash1[l] * pow1[r - l] % mod1; if (res1 < 0) res1 += mod1; ll res2 = hash2[r] - hash2[l] * pow2[r - l] % mod2; if (res2 < 0) res2 += mod2; return make_pair(res1, res2); } /** * S のハッシュ値を返す * O(1) */ inline pair hash() const { return get(0, (int)hash1.size() - 1); } /** * LCP (Longest Common Prefix) * O( log N ) */ inline int getLCP(int a, int b) const { int len = min((int)hash1.size() - a, (int)hash1.size() - b); int low = 0, high = len; while (high - low > 1) { int mid = (low + high) >> 1; if (get(a, a + mid) != get(b, b + mid)) high = mid; else low = mid; } return low; } /** * hash h1 と 長さ h2_len の文字列の hash h2 を結合 */ pair concat(pair h1, pair h2, int h2_len) { return make_pair((h1.first * pow1[h2_len] + h2.first) % mod1, (h1.second * pow2[h2_len] + h2.second) % mod2); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; RollingHash h(s); map, ll> count; rep(i, s.size()) { for (int j = i + 1; j <= min(i + 10, int(s.size())); j++) { count[h.get(i, j)]++; } } int m; cin >> m; ll ans = 0; rep(i, m) { string c; cin >> c; RollingHash ch(c); ans += count[ch.hash()]; } cout << ans << "\n"; }