#line 2 "template.hpp" #include using namespace std; #define rep(i, N) for(int i=0;i<(N);i++) #define all(x) (x).begin(),(x).end() #define popcount(x) __builtin_popcount(x) using i128=__int128_t; using ll = long long; using ld = long double; using graph = vector>; using P = pair; constexpr int inf = 1e9; constexpr ll infl = 1e18; constexpr ld eps = 1e-6; const long double pi = acos(-1); constexpr uint64_t MOD = 1e9 + 7; constexpr uint64_t MOD2 = 998244353; constexpr int dx[] = { 1,0,-1,0 }; constexpr int dy[] = { 0,1,0,-1 }; templatestatic constexpr inline void chmax(T&x,T y){if(xstatic constexpr inline void chmin(T&x,T y){if(x>y)x=y;} #line 2 "math/mod_pow.hpp" template U mod_pow(T base, T exp, T mod){ T ans = 1; base %= mod; while (exp > 0) { if (exp & 1) { ans *= base; ans %= mod; } base *= base; base %= mod; exp >>= 1; } return ans; } ///@brief mod pow(バイナリ法) #line 3 "string/rolling_hash.hpp" class RollingHash { using ull = uint_fast64_t; using i128 = __int128_t; using u128 = __uint128_t; // mod static constexpr ull msk30 = (1ul << 30) - 1; static constexpr ull msk61 = (1ul << 31) - 1; string str; vector hash, pow; static const ull mod = (1uL << 61) - 1; static const ull primitive_root = 37; public: static const uint mapping_max = 'Z' + 1; static ull base; private: ull mul(const u128& a,const u128& b) const { u128 t = a * b; t = (t >> 61) + (t & mod); if (t >= mod) { t -= mod; } return t; } ull mapping(const char& c) const { return (ull)c; //変更する? } static ull generate() { mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution rand(1uL, mod - 1); return rand(engine); } static void generate_base() { if (base != 0){ return; } ull r = mod - 1; while (gcd(r, mod - 1) != 1 || r <= mapping_max){ r = generate(); } base = mod_pow<__uint128_t>(primitive_root, r, mod); } public: RollingHash() :str() { } RollingHash(const string& str) :str(str) { generate_base(); build(); } void build() { hash.resize(str.size() + 1); pow.resize(str.size() + 1, 1); for (int i = 0; i < str.size(); i++) { hash[i + 1] = mul(hash[i], base) + mapping(str[i]); pow[i + 1] = mul(pow[i], base); if (hash[i + 1] >= mod) { hash[i + 1] -= mod; } } } ull range(int l, int r) const { ull res = mod + hash[r] - mul(hash[l], pow[r - l]); return res < mod ? res : res - mod; } ull get_all() const { return hash.back(); } int size() const {return str.size();} static int lcp(const RollingHash &a, const RollingHash &b, const int &start_a, const int &start_b) { int ok = 0; int ng = min(a.size() - start_a, b.size() - start_b) + 1; while (abs(ok - ng) > 1){ int md = (ok + ng) >> 1; if (a.range(start_a, start_a + md) == b.range(start_b, start_b + md)){ ok = md; } else{ ng = md; } } return ok; } }; typename RollingHash::ull RollingHash::base; ///@brief Rollinghash(ローリングハッシュ) #line 3 "main.cpp" #pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") int main(){ string s; int m; cin >> s >> m; RollingHash S(s); map hash_count; rep(i, s.size()) { for (int length = 1; length <= 10; length++){ int j = i + length; hash_count[S.range(i, j)]++; } } long long ans = 0; for (int i = 0; i < m; i++) { string c; cin >> c; ans += hash_count[RollingHash(c).range(0, c.size())]; } cout << ans << '\n'; }