class PatriciaNode: def __init__(self, string=None): self.data = string self.child = {} self.valid = False def set_child(self, string): self.child[string[0]] = PatriciaNode(string) return self.child[string[0]] def get_child(self, s): if s not in self.child: return None return self.child[s] class Patricia: def __init__(self): self.root = PatriciaNode() def _longest_match(self, string): ptr = self.root i = 0 while i < len(string): ptrch = ptr.get_child(string[i]) if ptrch is None: break j = 1 while j < len(ptrch .data): if i + j == len(string) or string[i + j] != ptrch .data[j]: return ptrch , i + j, j j += 1 i += j ptr = ptrch return ptr, i, 0 def search(self, string): ptr, match, sub_match = self._longest_match(string) if len(string) == match and sub_match == 0: return ptr.valid return False def insert(self, string): ptr, match, sub_match = self._longest_match(string) if sub_match > 0: newptr = PatriciaNode(ptr.data[sub_match:]) newptr.child = ptr.child newptr.valid = ptr.valid ptr.data = ptr.data[:sub_match] ptr.child = {newptr.data[0]: newptr} if match < len(string): ptr.valid = False ptr = ptr.set_child(string[match:]) ptr.valid = True else: if match == len(string): return False else: ptr = ptr.set_child(string[match:]) ptr.valid = True s = input() m = int(input()) c = [input() for i in range(m)] tr = Patricia() for string in c: tr.insert(string) ans = 0 for i in range(len(s)): for length in range(1, 11): if i + length > len(s): break if tr.search(s[i:i + length]): ans += 1 print(ans)