import sys sys.setrecursionlimit(10**7) alpha_dic = {} for i,a in zip(range(1,27),"ABCDEFGHIJKLMNOPQRSTUVWXYZ"): alpha_dic[a] = i def hash(before,rm,ad,length): if before: return (before - alpha_dic[rm]*(27**(length-1)))*27 + alpha_dic[ad] else: ans = 0 for i,a in enumerate(ad): ans += alpha_dic[a] * 27**(length-1-i) return ans S = input() M = int(input()) count = 0 for _ in range(M): c = input() length = len(c) hashed_c = hash(None,None,c,length) s = S[:length] hashed_s = hash(None,None,s,length) if hashed_c == hashed_s: count += 1 for x in S[length:]: rm = s[0] s = s + x s = s[1:] hashed_s = hash(hashed_s,rm,x,length) if hashed_c == hashed_s: count += 1 print(count)