#include using namespace std; #define rep(i, s, n) for (Int i = s; i < (Int)(n); i++) #define rrep(i, n, s) for (Int i = n - 1; i >= s; i--) #define dump(x) cout << (x) << '\n' #define Int int64_t #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).end() double EPS = 1e-10; Int INF = 1e18; int inf = 1e9; Int mod = 1e9+7; // s の中に t が何回現れるか typedef unsigned long long ull; const ull B = 1e9+7; Int string_count(string s, string t) { Int s_len = s.length(); Int t_len = t.length(); if (s_len < t_len) return 0; ull x = 1; rep(i, 0, t_len) x *= B; ull s_hash = 0, t_hash = 0; rep(i, 0, t_len) s_hash = s_hash * B + s[i]; rep(i, 0, t_len) t_hash = t_hash * B + t[i]; Int ret = 0; rep(i, 0, s_len - t_len + 1) { if (s_hash == t_hash) ret++; if (i + t_len < s_len) { s_hash = s_hash * B + s[i + t_len] - s[i] * x; } } return ret; } int main() { string s; cin >> s; Int m; cin >> m; vector t(m); rep(i, 0, m) cin >> t[i]; Int res = 0; rep(i, 0, m) { res += string_count(s, t[i]); } dump(res); return 0; }