import sys input = sys.stdin.readline from collections import * class RollingHash(): def __init__(self, s): self._mod = 2 ** 64 - 1 self._base = 4649 n = len(s) self.h = [0] * (n + 1) self.pw = [1] * (n + 1) for i in range(n): self.h[i + 1] = self.h[i] * self._base + ord(s[i]) self.h[i + 1] %= self._mod for i in range(n): self.pw[i + 1] = self.pw[i] * self._base self.pw[i + 1] %= self._mod """ s[l:r]のhash値 """ def get(self, l, r): return (self.h[r] - self.h[l] * self.pw[r - l]) % self._mod S = list(input().rstrip()) Sr = RollingHash(S) D = [defaultdict(int) for i in range(11)] for i in range(1, min(11, len(S) + 1)): for j in range(len(S) - i + 1): D[i][Sr.get(j, j + i)] += 1 ans = 0 M = int(input()) for _ in range(M): C = list(input().rstrip()) if len(C) > len(S): continue Cr = RollingHash(C) ans += D[len(C)][Cr.get(0, len(C))] print(ans)