using System; using System.Collections.Generic; using System.Linq; class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } static string[] ReadStrings() { return Console.ReadLine().Split(); } private const long B = 26; static long Hash(string s) { long h = 0; for (int i = 0; i < s.Length; i++) { h = h * B + (s[i] - 'A' + 1); } return h; } static int Calc(string s, List ss) { var hs = new HashSet(); var lens = new bool[11]; for (int i = 0; i < ss.Count; i++) { lens[ss[i].Length] = true; hs.Add(Hash(ss[i])); } int ans = 0; for (int i = 1; i < 11; i++) { if (!lens[i]) continue; // 長さ i の検索文字列はない if (s.Length < i) break; long pow = (long)Math.Pow(26, i - 1); long h = 0; for (int j = 0; j < i; j++) { h = h * B + (s[j] - 'A' + 1); } if (hs.Contains(h)) ans++; for (int j = i; j < s.Length; j++) { h -= (s[j - i] - 'A' + 1) * pow; h = h * B + (s[j] - 'A' + 1); if (hs.Contains(h)) ans++; } } return ans; } static void Main() { var s = Console.ReadLine(); int m = ReadInt(); var ss = new List(); for (int i = 0; i < m; i++) ss.Add(Console.ReadLine()); var ans = Calc(s, ss); Console.WriteLine(ans); } }