#include using namespace std; #define FOR(i,n) for(int i=0;i<(n);i++) #define all(t) (t).begin(),(t).end() #define MOD 1000000007 typedef long long ll; template inline bool chmax(T& a,T b){if(a inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}} template inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;} template inline T LCM(T a,T b){return a*b/GCD(a,b);} int main(){ string s; cin >> s; ll ans=0; int m; cin >> m; FOR(i,m){ string c; cin >> c; if(c.size()>s.size())continue; ll h=0,cnt=0; FOR(j,(int)c.size()){ h+=(c[j]-'A')*pow(26ll,(int)c.size()-j-1); cnt+=(s[j]-'A')*pow(26ll,(int)c.size()-j-1); } if(h==cnt)ans++; FOR(j,(int)s.size()-(int)c.size()){ cnt-=(s[j]-'A')*pow(26ll,(int)c.size()-1); cnt*=26; cnt+=(s[j+(int)c.size()]-'A'); if(h==cnt)ans++; } } cout << ans << endl; }