#include using namespace std; //#include //using namespace atcoder; //cout << fixed << setprecision(10); #define rep(i, N) for(int i=0;i<(N);i++) #define all(x) (x).begin(),(x).end() using ll = long long; using ld = long double; using Graph = vector>; using P = pair; const int INF = 1e9; const ll INFL = 1e18; const ll MOD = 1e9 + 7; const int dx[4] = { 1,0,-1,0 }; const int dy[4] = { 0,1,0,-1 }; class Hash { private: /*メンバ*/ ll mod = 998244353; ll base = 32; string s; vector hash; /*modint関連のメソッドを持っておく*/ ll mod_pow(ll base, ll exp) { if (exp == 0) return 1; if (exp == 1) return base % mod; ll half = mod_pow(base, exp / 2); ll ret = (half * half) % mod; if (exp % 2 == 1) ret = ret * base % mod; return ret; } int id(char c) { return c - 'a' + 1; } public: /*コンストラクタ*/ Hash(string _s, ll _mod = 998244353, ll _base = 100) :s(_s), mod(_mod), base(_base), hash(_s.size() + 1) { } /*メソッド*/ /*ハッシュの表を作る*/ void build() { hash[0] = 0; for (int i = 0; i < s.size(); i++) { hash[i + 1] = (hash[i] * base % mod + id(s[i]) % mod) % mod; } } /*区間ハッシュを求める*/ ll rangeHash(int l,int r) { return (hash[r] - mod_pow(base, r - l + 1) * hash[l - 1] % mod + mod) % mod; //hash[l,r]=hash[r]-base^(r-l+1)*hash[l-1] } bool same(int l, int r, int L, int R) { bool check = (rangeHash(l, r) == rangeHash(L, R)); return check; } }; int main() { string S; cin >> S; Hash S1(S); S1.build(); int M; cin >> M; int ans = 0; while (M--) { string c; cin >> c; int siz = c.size(); Hash S2(c); S2.build(); ll val2 = S2.rangeHash(1, siz); for (int i = 1; i + siz - 1 <= S.size(); i++) { ll val = S1.rangeHash(i, i + siz - 1); if (val == val2)ans++; } } cout << ans << endl; }