# include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include using namespace std; using LL = long long; using ULL = unsigned long long; using D = double; constexpr int INF = 2147483647; constexpr int HINF = INF / 2; constexpr double DINF = 100000000000000000.0; constexpr double HDINF = 50000000000000000.0; constexpr long long LINF = 9223372036854775807; constexpr long long HLINF = 4500000000000000000; const double PI = acos(-1); template T_char TL(T_char cX) { return tolower(cX); }; template T_char TU(T_char cX) { return toupper(cX); }; typedef pair pii; const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 }; const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }; int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; } LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); }; LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; }; # define ALL(qpqpq) (qpqpq).begin(),(qpqpq).end() # define RALL(qpqpq) (qpqpq).rbegin(),(qpqpq).rend() # define UNIQUE(wpwpw) sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end()) # define LOWER(epepe) transform(ALL((epepe)),(epepe).begin(),TL) # define UPPER(rprpr) transform(ALL((rprpr)),(rprpr).begin(),TU) # define FOR(i,tptpt,ypypy) for(LL i=(tptpt);i<(ypypy);i++) # define RFOR(i,tptpt,ypypy) for(LL i=(tptpt);i>=(ypypy);i--) # define REP(i,upupu) FOR(i,0,upupu) # define INIT std::ios::sync_with_stdio(false);std::cin.tie(0) const ULL B[] = { 999999937ULL,1000000007ULL }; //aはbにいくつ含まれているか? int contain(string a, string b) { int ret = 0; int al = a.length(), bl = b.length(); if (al > bl)return false; //Bのal乗を計算 ULL t[] = { 1 ,1 }; for (int i = 0; i < al; i++)t[0] *= B[0]; for (int i = 0; i < al; i++)t[1] *= B[1]; //aとbの最初のal文字に関するハッシュ値を計算 ULL ah[] = { 0 ,0 }, bh[] = { 0 ,0 }; for (int i = 0; i < al; i++)ah[0] = ah[0] * B[0] + a[i]; for (int i = 0; i < al; i++)bh[0] = bh[0] * B[0] + b[i]; for (int i = 0; i < al; i++)ah[1] = ah[1] * B[1] + a[i]; for (int i = 0; i < al; i++)bh[1] = bh[1] * B[1] + b[i]; //bの場所を1つずつ進めながらハッシュ値をチェック for (int i = 0; i + al <= bl; i++) { if (ah[0] == bh[0] && ah[1] == bh[1])ret++;//bのi文字目からのal文字が一致 if (i + al < bl) { bh[0] = bh[0] * B[0] + b[i + al] - b[i] * t[0]; bh[1] = bh[1] * B[1] + b[i + al] - b[i] * t[1]; } } //return false;//一致する文字列がない return ret; } string s; string c[5050]; int m; int main() { cin >> s >> m; int ret = 0; REP(i, m) { cin >> c[i]; ret+= contain(c[i], s); } cout << ret << endl; }