#include using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define eb emplace_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vectorvint; typedef pairpint; typedef vectorvpint; templateinline void chmin(A &a,B b){if(a>b)a=b;} templateinline void chmax(A &a,B b){if(a ostream& operator<<(ostream& ost,const pair&p){ ost<<"{"< ostream& operator<<(ostream& ost,const vector&v){ ost<<"{"; for(int i=0;isuflist; Node():failink(0){memset(nex,-1,sizeof(nex));} }; vectornds; void build(const vector&ps){ nds.emplace_back(); for(int i=0;ique; for(int i=1;i<256;i++){ if(nds[0].nex[i]==-1){ nds[0].nex[i]=0; } else{ que.push(nds[0].nex[i]); } } while(que.size()){ int k=que.front(); que.pop(); for(int i=1;i<256;i++){ if(nds[k].nex[i]==-1)continue; int nx=nds[k].nex[i]; int l=k; do{ l=nds[l].failink; }while(nds[l].nex[i]==-1); nds[nx].failink=nds[l].nex[i]; nds[nx].suflist.insert(nds[nx].suflist.end(),nds[nds[nx].failink].suflist.begin(),nds[nds[nx].failink].suflist.end()); que.push(nx); } } } }; signed main(){ string S;cin>>S; int M;cin>>M; vectorps(M);rep(i,M)cin>>ps[i]; AhoCorasick ac; ac.build(ps); int ans=0; int k=0; for(auto c:S){ while(ac.nds[k].nex[c]==-1)k=ac.nds[k].failink; k=ac.nds[k].nex[c]; ans+=ac.nds[k].suflist.size(); } cout<