from random import randint class RollingHash(object): mod = 1 << 61 - 1 base = randint(2, mod - 2) def __init__(self, s): self.s = s self.pw = pw = [1] * (len(s) + 1) l = len(s) self.h = h = [0] * (l + 1) v = 0 for i in range(l): h[i + 1] = v = (v * self.base + ord(s[i])) % self.mod v = 1 for i in range(l): pw[i + 1] = v = v * self.base % self.mod def hash(self, l, r): """ s[l:r] のhash (rはexclusive) """ return (self.h[r] - self.h[l] * self.pw[r - l]) % self.mod def contains(self, t): """ sがtを含むか O(|s|+|t|) tはRollingHashオブジェクト """ slen, tlen = len(self.s), len(t.s) if slen < tlen: return False th = t.hash(0, tlen) for i in range(slen - tlen + 1): if th == self.hash(i, i + tlen): return True return False def count(self, t): """ s中に含まれるtの数をカウントする O(|s|+|t|) tはRollingHashオブジェクト """ slen, tlen = len(self.s), len(t.s) if slen < tlen: return 0 cnt = 0 th = t.hash(0, tlen) for i in range(slen - tlen + 1): if th == self.hash(i, i + tlen): cnt += 1 return cnt S = input() M = int(input()) rh = RollingHash(S) cnt = 0 for c in (input() for _ in range(M)): cnt += rh.count(RollingHash(c)) print(cnt)