// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; using ld = long double; using pll = pair; using pii = pair; using vvl = vector>; using vvi = vector>; using vvpll = vector>; #define rep(i, a, b) for (ll i=(a); i<(b); i++) #define rrep(i, a, b) for (ll i=(a); i>(b); i--) #define pb push_back #define tostr to_string #define ALL(A) A.begin(), A.end() #define elif else if // constexpr ll INF = LONG_LONG_MAX; constexpr ll INF = 1e18; constexpr ll MOD = 1000000007; const string digits = "0123456789"; const string ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"; const string ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const string ascii_letters = ascii_lowercase + ascii_uppercase; template vector> list2d(int N, int M, T init) { return vector>(N, vector(M, init)); } template vector>> list3d(int N, int M, int L, T init) { return vector>>(N, vector>(M, vector(L, init))); } template vector>>> list4d(int N, int M, int L, int O, T init) { return vector>>>(N, vector>>(M, vector>(L, vector(O, init)))); } vector LIST(ll N) { vector A(N); rep(i, 0, N) cin >> A[i]; return A; } void print(ld out) { cout << fixed << setprecision(15) << out << '\n'; } void print(double out) { cout << fixed << setprecision(15) << out << '\n'; } template void print(T out) { cout << out << '\n'; } template void print(pair out) { cout << out.first << ' ' << out.second << '\n'; } template void print(vector A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } } template void print(set S) { vector A(S.begin(), S.end()); print(A); } void Yes() { print("Yes"); } void No() { print("No"); } void YES() { print("YES"); } void NO() { print("NO"); } ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } } ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } } pll divmod(ll a, ll b) { ll d = a / b; ll m = a % b; return {d, m}; } template bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; } template bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; } template T sum(vector A) { T res = 0; for (T a: A) res += a; return res; } template T max(vector A) { return *max_element(ALL(A)); } template T min(vector A) { return *min_element(ALL(A)); } ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; } int toint(char num) { return num - '0'; } char tochar(int num) { return '0' + num; } int ord(char c) { return (int)c; } char chr(int a) { return (char)a; } ll pow(ll x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; } ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } int popcount(ll S) { return __builtin_popcountll(S); } ll gcd(ll a, ll b) { return __gcd(a, b); } ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); } template int bisect_left(vector &A, T val) { return lower_bound(ALL(A), val) - A.begin(); } template int bisect_right(vector &A, T val) { return upper_bound(ALL(A), val) - A.begin(); } struct RollingHash { static const uint64_t mod = (1ull << 61ull) - 1; using uint128_t = __uint128_t; vector< uint64_t > power; const uint64_t base; static inline uint64_t add(uint64_t a, uint64_t b) { if((a += b) >= mod) a -= mod; return a; } static inline uint64_t mul(uint64_t a, uint64_t b) { uint128_t c = (uint128_t) a * b; return add(c >> 61, c & mod); } // 2^61-1以下の乱数を返す。これをbaseとするとHackされにくい static inline uint64_t generate_base() { mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution< uint64_t > rand(1, RollingHash::mod - 1); return rand(mt); } inline void expand(size_t sz) { if(power.size() < sz + 1) { int pre_sz = (int) power.size(); power.resize(sz + 1); for(int i = pre_sz - 1; i < sz; i++) { power[i + 1] = mul(power[i], base); } } } // 基数baseのローリングハッシュを構築する explicit RollingHash(uint64_t base = generate_base()) : base(base), power{1} {} // 文字列sのハッシュテーブルを返す:O(n) vector< uint64_t > build(const string &s) const { int sz = s.size(); vector< uint64_t > hashed(sz + 1); for(int i = 0; i < sz; i++) { hashed[i + 1] = add(mul(hashed[i], base), s[i]); } return hashed; } template< typename T > vector< uint64_t > build(const vector< T > &s) const { int sz = s.size(); vector< uint64_t > hashed(sz + 1); for(int i = 0; i < sz; i++) { hashed[i + 1] = add(mul(hashed[i], base), s[i]); } return hashed; } // sの区間[l,r)のハッシュ値を返す:O(1) uint64_t query(const vector< uint64_t > &s, int l, int r) { expand(r - l); return add(s[r], mod - mul(s[l], power[r - l])); } // ハッシュ値h1と長さh2lenのハッシュ値h2を結合する uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) { expand(h2len); return add(mul(h1, power[h2len]), h2); } // ハッシュテーブルaの区間[l1,r1)と、ハッシュテーブルbの区間[l2,r2)の文字列の最長共通接頭辞の長さを返す:O(logn) int lcp(const vector< uint64_t > &a, int l1, int r1, const vector< uint64_t > &b, int l2, int r2) { int len = min(r1 - l1, r2 - l2); int low = 0, high = len + 1; while(high - low > 1) { int mid = (low + high) / 2; if(query(a, l1, l1 + mid) == query(b, l2, l2 + mid)) low = mid; else high = mid; } return low; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; ll N = S.size(); RollingHash rh; auto s_hash_table = rh.build(S); ll M; cin >> M; set hashs; rep(i, 0, M) { string t; cin >> t; auto t_hash_table = rh.build(t); hashs.insert(rh.query(t_hash_table, 0, t.size())); } ll ans = 0; rep(i, 0, N) { rep(j, i+1, min(i+11, N+1)) { auto s_hash = rh.query(s_hash_table, i, j); if (hashs.count(s_hash)) { ans++; } } } print(ans); return 0; }