import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) throws Exception { InputStreamReader is = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(is); List mylist = new ArrayList<>(); // 標準入力からの値を変数strinputに代入 String strinput = reader.readLine(); while (strinput != null) { mylist.add(strinput); strinput = reader.readLine(); } String s = mylist.get(0); int m = Integer.valueOf(mylist.get(1)); int mysum = 0; for (int i = 2; i < 2 + m; i++) { String temp = mylist.get(i); int sposi = 0; while (s.indexOf(temp, sposi) >= 0) { sposi = s.indexOf(temp, sposi) + 1; mysum += 1; } } System.out.println(mysum); } }