#include using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) using ll = long long; using P = std::tuple; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; template T expt(T a, T n, T mod = std::numeric_limits::max()){ T res = 1; while(n){ if(n & 1){res = res * a % mod;} a = a * a % mod; n >>= 1; } return res; } string S, C[5000]; int M; ll _hash[11][50000]; vector hash_v[11]; int main(){ //* std::cin.tie(nullptr); std::ios::sync_with_stdio(false); /*/ /*/ std::cin >> S; int s_length = S.size(); for(int i=1;i<=10;++i){ for(int j=0;j 0 ? _hash[i][j-1] * 26 : 0) + S[j] - 'A'; if(j - i >= 0){ _hash[i][j] -= 1ll * (S[j-i] - 'A') * expt(26ll, 1ll * i); } } for(int j=i-1;j> M; ll res = 0; for(int i=0;i> C[i]; ll h = 0; for(const auto& c : C[i]){ h = h * 26 + c - 'A'; } // std::cout << "Hashs" << std::endl; // for(int x : hash_v[C[i].size()]){ // std::cout << x << std::endl; // } // std::cout << "Hitomazu" << std::endl; auto it = lower_bound(hash_v[C[i].size()].begin(), hash_v[C[i].size()].end(), h), it2 = upper_bound(hash_v[C[i].size()].begin(), hash_v[C[i].size()].end(), h); if(it != hash_v[C[i].size()].end() && *it == h){ res += it2 - it; } } std::cout << res << std::endl; }