#include #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n-1);i>=0;i--) #define FOR(i,n,m) for(int i=n;i<=(int)(m);i++) #define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--) #define all(x) (x).begin(),(x).end() #define sz(x) int(x.size()) #define get_unique(x) x.erase(std::unique(all(x)), x.end()); typedef long long ll; const int INF = 1e9; const ll MOD = 1e9+7; const ll LINF = 1e18; const double PI=acos(-1); using namespace std; vector dx={1,0,-1,0}; vector dy={0,1,0,-1}; template vector make_vec(size_t a){ return vector(a); } template auto make_vec(size_t a, Ts... ts){ return vector(ts...))>(a, make_vec(ts...)); } struct RollingHash { int n; vector> vec,pw; ll mod1,mod2,base1,base2; RollingHash(string s) { srand(time(NULL)); n=sz(s); vec.resize(n+1); pw.resize(n+1); pw[0]={1,1}; mod1=1e9+93; mod2=1e9+97; base1=(ll)rand()%((ll)1e7+9); base2=(ll)rand()%((ll)1e7+9); rep(i,n) { pw[i+1].first=pw[i].first*base1%mod1; pw[i+1].second=pw[i].second*base2%mod2; vec[i+1].first=(vec[i].first*base1+(ll)s[i])%mod1; vec[i+1].second=(vec[i].second*base2+(ll)s[i])%mod2; } } //[l,r) pair get(int l,int r) { ll fi,se=0; fi=(vec[r].first-vec[l].first*pw[r-l].first+mod1*mod1)%mod1; se=(vec[r].second-vec[l].second*pw[r-l].second+mod1*mod2)%mod2; return make_pair(fi,se); } }; int main() { string s; cin>>s; int n=sz(s); RollingHash rlh(s); map,int> mp; FOR(len,1,10) { rep(i,n-len+1) mp[rlh.get(i,i+len)]++; } int m; cin>>m; int ans=0; while(m--) { string t; cin>>t; RollingHash rlh2(t); ans+=mp[rlh2.get(0,sz(t))]; } cout<