L=50000 B=123451234512345 M=(1<<61)-1 P=[1,B] R=[1,pow(B,M-2,M)] for i in range(2,L+1): P+=[P[-1]*P[1]%M] R+=[R[-1]*R[1]%M] class RH(): def __init__(self,s): self.len=len(s) self.h=[0]*(len(s)+1) for i in range(self.len): self.h[i]=(ord(s[i])*P[i]+self.h[i-1])%M return def rh(self,l,r): return (self.h[r]-self.h[l-1])*R[l]%M S=RH(input()) L=S.len d=[{} for i in range(11)] for l in range(1,11): for i in range(L-l+1): p=S.rh(i,i+l-1) if p not in d[l]: d[l][p]=0 d[l][p]+=1 n=int(input()) c=0 for _ in range(n): t=RH(input()) l=t.len p=t.rh(0,l-1) if p in d[l]: c+=d[l][p] print(c)