/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #pragma GCC optimize("Ofast") #include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VP = vector

; using VVP = vector>; using VS = vector; using VC = vector; using VVC = vector>; using VD = vector; using VVD = vector>; using I_I = pair; // using VI_I = vector; // using VVI_I = vector>; // #define MOD 1000000007 #define MOD 998244353 const int INF = (int) 1e9 + 10; // int max > 2*10^9 const long long INFL = (ll) 2e18 + 10; // ll max > 9*10^18 P operator+(const P &a, const P &b) { return make_pair(a.first + b.first, a.second + b.second); } P operator-(const P &a, const P &b) { return make_pair(a.first - b.first, a.second - b.second); } P operator*(const P &a, const P &b) { return make_pair(a.first * b.first, a.second * b.second); } P operator/(const P &a, const P &b) { return make_pair(a.first / b.first, a.second / b.second); } #define pmod(x, y) ((x%y)+y)%y // jhelper 用変数 ostream *__cout; istream *__cin; /********** libs **********/ // 最大公約数, 最小公倍数 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template bool chmax(T& a, C b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T& a, C b) { if (a > b) { a = b; return true; } return false; } template T sum(const vector& v) { T res = 0; for (size_t i = 0; i < v.size(); ++i) res += v[i]; return res; } template VP idx_pair(T vals) { VP ans; rep(i, vals.size()) { ans.emplace_back(vals[i], i); } return ans; } void _init_io(std::istream &cin, std::ostream &cout) { // 入出力高速化用 ios::sync_with_stdio(false); cin.tie(nullptr); // 少数15桁まで出力 cout << std::setprecision(15); /////////////////////////////// __cout = &cout;// jhelper 用 __cin = &cin; // jhelper 用 } /* デバッグ用 出力 */ template ostream& operator<<(ostream& os, const deque& vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template ostream& operator<<(ostream& os, const set& vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream& operator<<(ostream& os, const unordered_set& vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream& operator<<(ostream& os, const multiset& vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream& operator<<(ostream& os, const unordered_multiset& vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template ostream& operator<<(ostream& os, const pair& pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template ostream& operator<<(ostream& os, const map& mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template ostream& operator<<(ostream& os, const unordered_map& mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } ///////////////////////////////////////////////////////// // print like python // https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed ///////////////////////////////////////////////////////// void print() { *__cout << endl; } template void print(Head&& head, Tail&&... tail) { *__cout << head; if (sizeof...(tail) != 0) *__cout << " "; print(forward(tail)...); } template void print(vector& vec) { for (auto& a : vec) { *__cout << a; if (&a != &vec.back()) *__cout << " "; } *__cout << endl; } template void print(vector>& df) { for (auto& vec : df) { print(vec); } } /* * 以下の vector 入力パクった. * jhelper で使用するため, 全部 cin での入力にしている. (現状のレベルでは困らないので) * * https://atcoder.jp/contests/abc213/submissions/24901856 */ template void scan(T& a){ *__cin >> a; } template void scan(vector&); template void scan(pair&); template void scan(vector& a){ for(auto&& i : a) scan(i); } template void scan(pair& p){ scan(p.first); scan(p.second); } template void scan(T (&a)[size]){ for(auto&& i : a) scan(i); } void in(){} template void in(T&... a){ (void)initializer_list{ (scan(a), 0)... }; } ////////////////////////////////////////////////// // vector 定義 #define let_v(type,name,...) vectorname(__VA_ARGS__) // vector 定義 + 入力 #define let_V(type,name,size) vectorname(size);in(name) // 2次元 vector 定義 #define let_vv(type,name,h,...) vector>name(h,vector(__VA_ARGS__)) // 2次元 vector 定義 + 入力 #define let_VV(type,name,h,w) vector>name(h,vector(w));in(name) #define let_vvv(type,name,h,w,...) vector>>name(h,vector>(w,vector(__VA_ARGS__))) ////////////////////////////////////////////////// /* string 入力を vector で受け取るみたいな */ vector let_CharVec() { string s; *__cin >> s; return {s.begin(), s.end()}; } // add other source // よく使う // #include "../library/graph/UnionFind.cpp" // #include "../library/tree/SegmentTree.cpp" // #include "../library/graph/template.cpp" // utils // #include "../library/mint.cpp" // #include "../library/string/utils.cpp" // #include "../library/math/utils.cpp" /**************************/ /** * src: https://ei1333.github.io/library/string/rolling-hash.cpp.html * * @brief Rolling-Hash(ローリングハッシュ) * @see https://qiita.com/keymoon/items/11fac5627672a6d6a9f6 * @docs docs/rolling-hash.md */ struct RollingHash { static const uint64_t mod = (1ull << 61ull) - 1; using uint128_t = __uint128_t; vector 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); } static inline uint64_t generate_base() { mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution 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); } } } explicit RollingHash(uint64_t base = generate_base()) : base(base), power{1} {} vector build(const string &s) const { int sz = s.size(); vector hashed(sz + 1); for (int i = 0; i < sz; i++) { hashed[i + 1] = add(mul(hashed[i], base), s[i]); } return hashed; } template vector build(const vector &s) const { int sz = s.size(); vector hashed(sz + 1); for (int i = 0; i < sz; i++) { hashed[i + 1] = add(mul(hashed[i], base), s[i]); } return hashed; } uint64_t query(const vector &s, int l, int r) { expand(r - l); return add(s[r], mod - mul(s[l], power[r - l])); } uint64_t combine(uint64_t h1, uint64_t h2, size_t h2len) { expand(h2len); return add(mul(h1, power[h2len]), h2); } int lcp(const vector &a, int l1, int r1, const vector &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; } }; class yukiko { public: //@formatter:off void solve(std::istream &cin, std::ostream &cout) { _init_io(cin, cout); int t = 1; while (t--) _solve(cin, cout); } //@formatter:on int _solve(std::istream &cin, std::ostream &cout) { // write here string s; cin >> s; RollingHash rh; auto hash_s = rh.build(s); int m; cin >> m; ll cnt=0; rep(i, m) { string t; cin >> t; auto hash_t = rh.build(t); auto v=rh.query(hash_t,0,t.size()); rep(j,s.size()){ if(j+t.size()>s.size())break; auto u=rh.query(hash_s,j,j+t.size()); if(u==v)cnt++; } } print(cnt); // rh.build() return 0; } }; int main() { yukiko solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }