#include #include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; using u64 = unsigned long long; constexpr u64 M = (1UL << 61) - 1; constexpr u64 POSITIVISER = M * 3; constexpr u64 MASK30 = (1UL << 30) - 1; constexpr u64 MASK31 = (1UL << 31) - 1; class rolling_hash_u64 { static u64 get_base(){ u64 z = (static_cast((chrono::system_clock::now().time_since_epoch().count())&((1LL << 32)-1)))+0x9e3779b97f4a7c15; z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; return z; } static u64 &B() { static u64 B_ = (get_base())%(M-2)+2; return B_; } static vector &p() { static vector p_{1, B()}; return p_; } static inline u64 mul(u64 x, u64 y){ u64 a = x >> 31, b = x & MASK31, c = y >> 31, d = y & MASK31; u64 e = b*c+a*d, f = e >> 30, g = e & MASK30; return a*c*2 + f + (g << 31) + b*d; } static inline u64 calc_mod(u64 val){ val = (val & M) + (val >> 61); if(val > M) val -= M; return val; } public: vector hash; explicit rolling_hash_u64(const string &s) { if(p().size() <= s.size()){ int l = p().size(); p().resize(s.size()+1); for (int i = l; i < p().size(); ++i) { p()[i] = calc_mod(mul(p()[i-1], p()[1])); } } hash.resize(s.size()+1, 0); for (int i = 0; i < s.size(); ++i) { hash[i+1] = calc_mod(mul(hash[i],B()) + s[i]); } }; u64 get(int l, int r){ return calc_mod(hash[r] + POSITIVISER - mul(hash[l], p()[r-l])); } }; int main() { string s; cin >> s; int n = s.size(); vector> v(11); rolling_hash_u64 sh(s); for (int i = 1; i <= 10; ++i) { for (int j = 0; j+i <= n; ++j) { v[i][sh.get(j, j+i)]++; } } int m; cin >> m; ll ans = 0; for (int i = 0; i < m; ++i) { string t; cin >> t; rolling_hash_u64 th(t); ans += v[t.size()][th.get(0, t.size())]; } cout << ans << "\n"; return 0; }