class RollingHash(): def __init__(self, s, base, mod): self.mod = mod n = len(s) self.hash = [0]*(n+1) self.power = [1]*(n+1) v = 0 for i in range(n): self.hash[i+1] = (v*base+s[i])%mod v = (v*base+s[i])%mod v = 1 for i in range(n): self.power[i+1] = v*base%mod v = v*base%mod def get(self, l, r): # [l, r)のhashを取得 return (self.hash[r]-self.hash[l]*self.power[r-l])%self.mod base = 1<<30 mod1 = (1<<61)-1 mod2 = (1<<31)-1 import sys import io, os input = sys.stdin.readline S = str(input().rstrip()) n = len(S) m = int(input()) S = [ord(c)-ord('A')+1 for c in S] rhs1 = RollingHash(S, base, mod1) rhs2 = RollingHash(S, base, mod2) from collections import defaultdict M = [defaultdict(lambda: 0) for i in range(11)] for i in range(1, 11): for l in range(n-i+1): h1 = rhs1.get(l, l+i) h2 = rhs2.get(l, l+i) M[i][(h1, h2)] += 1 ans = 0 for i in range(m): C = str(input().rstrip()) C = [ord(c)-ord('A')+1 for c in C] rhc1 = RollingHash(C, base, mod1) rhc2 = RollingHash(C, base, mod2) h1 = rhc1.get(0, len(C)) h2 = rhc2.get(0, len(C)) ans += M[len(C)][(h1, h2)] print(ans)