from itertools import * from bisect import * from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def LcpByZ(target,ln): # s = input() len_t = len(target) lcp = [-1] * len_t top = 1 # 右の箱において、左の箱の0に対応する点 left = 0 # 左の箱の左端(本当はここでので宣言は不要だけど理解の為) right = 0 # 左の箱の右端 lcp[0] = 0 cnt=0 while top < len_t: # 箱を右に広げていく while top + right < len_t and target[right] == target[top + right]: right += 1 # 右の箱左端のlcpを記録 lcp[top] = right if lcp[top]==ln:cnt+=1 left = 1 # 箱の幅が0だったらtopを動かして、このターン終了 if right == 0: top += 1 continue # lcpを記録しながら箱を左に縮めていく(最初の条件重要) while left + lcp[left] < right and left < right: lcp[top + left] = lcp[left] if lcp[left] == ln: cnt += 1 left += 1 # topを右の箱の左端にして、左の箱を0まで戻す top += left right -= left left = 0 # これも本当は不要 return cnt def main(): s=SI() ans=0 for _ in range(II()): t=SI() res=LcpByZ(t+"@"+s,len(t)) ans+=res print(ans) main()