using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class Program { static void Main() { var s = ReadLine(); var m = int.Parse(ReadLine()); var rh = new RollingHash(s); var d = new Map(); for (int i = 1; i < 11; i++) { for (int j = 0; j <= s.Length - i; j++) { d[rh.Hash(j, j + i)]++; } } var a = 0L; for (int i = 0; i < m; i++) { var c = ReadLine(); var h = RollingHash.ComputeHash(c, 27); a += d[h]; } WriteLine(a); } } public class Map : Dictionary { public Map() { } public Map(int capacity) : base(capacity) { } public Map(IEqualityComparer comparer) : base(comparer) { } public Map(int capacity, IEqualityComparer comparer) : base(capacity, comparer) { } public Map(IDictionary dictionary) : base(dictionary) { } public Map(IDictionary dictionary, IEqualityComparer comparer) : base(dictionary, comparer) { } public Map(IEnumerable> collection) : base(collection) { } public Map(IEnumerable> collection, IEqualityComparer comparer) : base(collection, comparer) { } public new TValue this[TKey key] { get => TryGetValue(key, out var value) ? value : default; set => base[key] = value; } } class RollingHash { ulong[] hash; ulong[] pow; ulong @base; const ulong mod = (2 << 61) - 1; public RollingHash(string s, int b = 27) { hash = new ulong[s.Length + 1]; pow = new ulong[s.Length + 1]; pow[0] = 1; for (int i = 1; i < pow.Length; i++) { pow[i] = pow[i - 1] * (ulong)b % mod; hash[i] = hash[i - 1] * (ulong)b % mod + s[i - 1] % mod; } @base = (ulong)b; } public static ulong ComputeHash(string s, int b) { var h = 0UL; for (int i = 0; i < s.Length; i++) { h = (h + s[i]) % mod; if (i != s.Length - 1) h = (h * (ulong)b) % mod; } return h; } public ulong Hash(int l, int r) { var h = 0UL; h = hash[r] - (hash[l] * pow[r - l] % mod) % mod; return h; } }