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 = 0; for (int i = 0; i < m; i++) { var c = ReadLine(); var h = RollingHash.ComputeHash(c); 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; } } public class RollingHash { ulong[] hash; ulong[] pow; const ulong @base = 131; const ulong mod = (1UL << 61) - 1; static ulong Mul(ulong a, ulong b) { const ulong MASK30 = (1UL << 30) - 1; const ulong MASK31 = (1UL << 31) - 1; var ah = a >> 31; var al = a & MASK31; var bh = b >> 31; var bl = b & MASK31; var mid = al * bh + ah * bl; var midu = mid >> 30; var midd = (mid & MASK30); return Mod(ah * bh * 2 + midu + (midd << 31) + al * bl); } static ulong Mod(ulong v) { v = (v & mod) + (v >> 61); if (v > mod) v -= mod; return v; } public RollingHash(ReadOnlySpan s) { 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] = Mul(pow[i - 1], @base); hash[i] = (Mul(hash[i - 1], @base) + s[i - 1]) % mod; } } public static ulong ComputeHash(ReadOnlySpan s) { var h = 0UL; for (int i = 0; i < s.Length; i++) { h = Mul(h, @base) + s[i]; } return h % mod; } public ulong Hash(int l, int r) { var a = hash[r]; var b = Mul(hash[l], pow[r - l]); if (a < b) a += mod; return (a - b) % mod; ; } }