#pragma GCC optimize("Ofast") #include using namespace std; typedef long long ll; //#define EPS (1e-7) #define INF (1e9) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define pii pair #define pll pair const double PI = acos(-1); const ll MOD = 1000000007; // const ll MOD = 998244353; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } /////////////////////////////////////////////////////////////// struct RollingHash { typedef unsigned long long ull; const ull MASK30 = (1ull << 30) - 1; const ull MASK31 = (1ull << 31) - 1; const ull mod = (1ull << 61) - 1; const ull POSITIVIZER = mod * 3; const ull base = 10007; vector hash,power; RollingHash(const string &s) { int sz = s.size(); hash.assign(sz + 1,0); power.assign(sz + 1,1); for (int i = 0; i < sz; i++) { power[i+1] = CalcMod(Mul(power[i],base)); hash[i+1] = CalcMod(Mul(hash[i],base) + s[i]); } } ull get(int l, int r) { ull res; res = CalcMod(hash[r] + POSITIVIZER - Mul(hash[l],power[r-l])); return res; } ull Mul (ull a, ull b) { ull au = a >> 31; ull ad = a & MASK31; ull bu = b >> 31; ull bd = b & MASK31; ull mid = ad * bu + au * bd; ull midu = mid >> 30; ull midd = mid & MASK30; return (au * bu * 2 + midu + (midd << 31) + ad * bd); } ull CalcMod(ull val) { val = (val & mod) + (val >> 61); if (val > mod) val -= mod; return val; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; int N = S.size(); int M; cin >> M; vector C(M); rep(i,M) cin >> C[i]; RollingHash RH(S); int cnt = 0; rep(i,M) { int K = C[i].size(); RollingHash rh(C[i]); rep(j,N-K+1) { if (RH.get(j,j+K) == rh.get(0,K)) cnt++; } } cout << cnt << endl; }