alphabet_to_int = { 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'I': 9, 'J': 10, 'K': 11, 'L': 12, 'M': 13, 'N': 14, 'O': 15, 'P': 16, 'Q': 17, 'R': 18, 'S': 19, 'T': 20, 'U': 21, 'V': 22, 'W': 23, 'X': 24, 'Y': 25, 'Z': 26 } def count_string(s: str, t: str): """ Rolling hash function """ count = 0 n = len(s) m = len(t) if n < m: return 0 base = 26 mod = 10 ** 9 + 7 t_hash = 0 for i, c in enumerate(t): t_hash += alphabet_to_int[c] * (base ** (m - i - 1)) t_hash %= mod s_hash = 0 for i in range(m): s_hash += alphabet_to_int[s[i]] * (base ** (m - i - 1)) s_hash %= mod if s_hash == t_hash: count += 1 # rolling hash for i in range(1, len(s) - m + 1): s_hash = s_hash * base - alphabet_to_int[s[i - 1]] * (base ** m) + alphabet_to_int[s[i + m - 1]] s_hash %= mod if s_hash == t_hash: count += 1 return count if __name__ == "__main__": s = str(input()) m = int(input()) t_array = [str(input()) for _ in range(m)] result = 0 for t in t_array: result += count_string(s, t) print(result)