B - Postal Card Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

数字のみからなる長さ 6 の文字列が N 個与えられます。i \, (i = 1, 2, \dots, N) 番目のものを S_i と表します。

さらに、数字のみからなる長さ 3 の文字列が M 個与えられます。j \, (j = 1, 2, \dots, M) 番目のものを T_j と表します。

S_1, S_2, \dots, S_N のうち、末尾 3 文字が T_1, T_2, \dots, T_M のいずれかに一致するものの個数を求めてください。

制約

  • 1 \leq N, M \leq 1000
  • N, M は整数
  • 全ての i = 1, 2, \dots, N に対し、S_i は数字のみからなる長さ 6 の文字列
  • 全ての j = 1, 2, \dots, M に対し、T_j は数字のみからなる長さ 3 の文字列

入力

入力は以下の形式で標準入力から与えられる。

N M
S_1
S_2
\vdots
S_N
T_1
T_2
\vdots
T_M

出力

答えを出力せよ。


入力例 1

3 3
142857
004159
071028
159
287
857

出力例 1

2

S_1 の末尾 3 文字は 857 であり、これは T_3 に一致します。
S_2 の末尾 3 文字は 159 であり、これは T_1 に一致します。
S_3 の末尾 3 文字は 028 であり、これは T_1, T_2, T_3 のいずれにも一致しません。

以上から、答えは 2 です。


入力例 2

5 4
235983
109467
823476
592801
000333
333
108
467
983

出力例 2

3

入力例 3

4 4
000000
123456
987111
000000
000
111
999
111

出力例 3

3

Score : 200 points

Problem Statement

You are given N strings of length six each, consisting of digits. Let S_i be the i-th (i = 1, 2, \dots, N) of them.

You are also given M strings of length three each, consisting of digits. Let T_j be the j-th (j = 1, 2, \dots, M) of them.

Find the number of strings among S_1, S_2, \dots, S_N whose last three characters coincide with one or more of T_1, T_2, \dots, T_M.

Constraints

  • 1 \leq N, M \leq 1000
  • N and M are integers.
  • S_i is a string of length 6 consisting of digits, for all i = 1, 2, \dots, N.
  • T_j is a string of length 3 consisting of digits, for all j = 1, 2, \dots, M.

Input

The input is given from Standard Input in the following format:

N M
S_1
S_2
\vdots
S_N
T_1
T_2
\vdots
T_M

Output

Print the answer.


Sample Input 1

3 3
142857
004159
071028
159
287
857

Sample Output 1

2

The last three characters of S_1 are 857, which coincide with T_3.
The last three characters of S_2 are 159, which coincide with T_1.
The last three characters of S_3 are 028, which do not coincide with T_1, T_2, or T_3.

Thus, the answer is 2.


Sample Input 2

5 4
235983
109467
823476
592801
000333
333
108
467
983

Sample Output 2

3

Sample Input 3

4 4
000000
123456
987111
000000
000
111
999
111

Sample Output 3

3