import sys sys.setrecursionlimit(100000000) def input(): return sys.stdin.readline()[:-1] from bisect import * from collections import * from heapq import * from fractions import Fraction CHRtoINT = defaultdict(int) AtoZ = [chr(i) for i in range(65,65+26)] for i, c in enumerate(AtoZ): CHRtoINT[c] = i def RollingHash(S, s, x, b=26, m=10**9+7): B, val, se = pow(b, x-1, m), 0, set() for _s in s: v, t = 0, B for c in _s: v = (v + CHRtoINT[c] * t) % m t //= b se.add(v) t = B for c in S[:x]: val = (val + CHRtoINT[c] * t) % m t //= b ret = int(val in se) B *= b for i, c in enumerate(S[:-x]): val = (val * b - CHRtoINT[c] * B + CHRtoINT[S[i+x]]) % m ret += int(val in se) return ret S = input() M = int(input()) s = [input() for i in range(M)] s.sort(key=lambda x: len(x)) l, r, ans = 0, 0, 0 for k in range(len(s[0]), len(s[-1])+1): while r < M and len(s[r]) == k: r += 1 if l != r: ans += RollingHash(S, s[l:r], k) l = r print(ans)