#if !__INCLUDE_LEVEL__ #include __FILE__ int main() { string S;cin >> S; ll L = S.size(); RH rh(S); map hashnum; range(len,1,11){ range(l,0,L-len+1){ ll hash = rh.get(l,l+len); hashnum[hash]+=1; } } ll N;cin >> N; ll Ans = 0; rep(n,N){ string s;cin >> s; Ans += hashnum[rh.gethash(s)]; } cout << Ans << endl; } #else #include #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i = 0; i < n; i++) #define rrep(i, n) for(int i = n; i >= 0; i--) #define range(i, m, n) for(int i = m; i < n; i++) #define fore(i,a) for(auto &i:a) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define sum(v) accumulate(all(v),0) typedef long long ll; typedef vector vl; typedef vector> vvl; const ll INF = 1e16; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll SN(char s){return ll(s-'0');} ll SN(string s){return stoll(s);} int alpN(char s){return int(s-'a');} int AlpN(char s){return int(s-'a');} using Graph = vector>; using mint1 = modint1000000007; using mint2 = modint998244353; template ostream &operator<<(ostream &o,const vector&v){for(int i=0;i<(int)v.size();i++)o<<(i>0?" ":"")< struct RollingHash { vector< unsigned > hashed, power; inline unsigned mul(unsigned a, unsigned b) const { unsigned long long x = (unsigned long long) a * b; unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m; asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod)); return m; } RollingHash(const string &s, unsigned base = 10007) { int sz = (int) s.size(); hashed.assign(sz + 1, 0); power.assign(sz + 1, 0); power[0] = 1; for(int i = 0; i < sz; i++) { power[i + 1] = mul(power[i], base); hashed[i + 1] = mul(hashed[i], base) + s[i]; if(hashed[i + 1] >= mod) hashed[i + 1] -= mod; } } unsigned gethash(const string&s, unsigned base = 10007){ int sz = (int) s.size(); unsigned ret = 0; for(int i = 0; i < sz; i++) { ret = mul(ret,base)+s[i]; if(ret >= mod)ret-=mod; } return ret; } unsigned get(int l, int r) const { unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]); if(ret >= mod) ret -= mod; return ret; } unsigned connect(unsigned h1, int h2, int h2len) const { unsigned ret = mul(h1, power[h2len]) + h2; if(ret >= mod) ret -= mod; return ret; } int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) { int len = min(r1 - l1, r2 - l2); int low = -1, high = len + 1; while(high - low > 1) { int mid = (low + high) / 2; if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid; else high = mid; } return (low); } }; using RH = RollingHash< 1000000007 >; #endif