import sys input = lambda: sys.stdin.readline().rstrip() S = input() M = int(input()) Cs = [input() for _ in range(M)] def kmp_count(string, word): # バックトラックテーブルの構築 # T[i] : word の先頭が string[m] で、 # i 番目で不一致だったとき(i.e. string[m + i] != word[i])、 # word の先頭を m + i - T[i] にずらす。 assert len(word) >= 1 T = [0] * (len(word) + 1) T[0] = -1 i = 2 j = 0 for i, c in enumerate(word[1:], start=2): if c == word[j]: j += 1 T[i] = j elif j > 0: j = T[j] # print(word) # print(T) # 文字列検索 m = 0 i = 0 ret = 0 while m + i < len(string): if word[i] == string[m + i]: i += 1 if i == len(word): ret += 1 m = m + i - T[i] i = T[i] else: m = m + i - T[i] if i > 0: i = T[i] # print(ret) return ret ans = 0 for C in Cs: ans += kmp_count(S, C) print(ans)