import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); int length = arr.length; long[][] table = new long[10][length]; for (long[] xx : table) { Arrays.fill(xx, -1L); } HashMap map = new HashMap<>(); for (int i = 0; i < length; i++) { table[0][i] = arr[i] - 'A' + 1; map.put(table[0][i], map.getOrDefault(table[0][i], 0) + 1); } for (int i = 1; i < 10; i++) { for (int j = 0; j + i < length; j++) { table[i][j] = table[i - 1][j] * 27 + table[0][j + i]; map.put(table[i][j], map.getOrDefault(table[i][j], 0) + 1); } } int m = sc.nextInt(); int ans = 0; for (int i = 0; i < m; i++) { ans += map.getOrDefault(getLong(sc.next()), 0); } System.out.println(ans); } static long getLong(String s) { long ans = 0; for (char c : s.toCharArray()) { ans *= 27; ans += c - 'A' + 1; } return ans; } }