import sys sys.setrecursionlimit(10 ** 6) def SI(): return sys.stdin.readline()[:-1] def main(): def hash(aa): res = 0 base=1 for a in aa[::-1]: res += a*base base*=26 return res s=SI() s=[ord(c)-65 for c in s] sn=len(s) memo=[[-1]*sn for _ in range(11)] ans=0 for _ in range(II()): t=SI() t = [ord(c) - 65 for c in t] tn=len(t) ht=hash(t) memotn = memo[tn] if memotn[0]!=-1: memotn=memo[tn] for i in range(sn - tn + 1): if memotn[i]==ht:ans+=1 else: hs=hash(s[:tn]) mxd=pow(26,tn-1) for i in range(sn - tn + 1): if i:hs=(hs-mxd*s[i-1])*26+s[i+tn-1] if hs==ht:ans+=1 memotn[i]=hs print(ans) main()