#abc287b. B - Postal Card

B - Postal Card

Score : 200200 points

问题描述

给定 NN 个长度为六的数字字符串,记第 iii=1,2,,Ni = 1, 2, \dots, N)个字符串为 SiS_i

另外还给定 MM 个长度为三的数字字符串,记第 jjj=1,2,,Mj = 1, 2, \dots, M)个字符串为 TjT_j

请找出在 S1,S2,,SNS_1, S_2, \dots, S_N 中有多少个字符串的最后三个字符与 T1,T2,,TMT_1, T_2, \dots, T_M 中的一个或多个字符串完全相同。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

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

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

Find the number of strings among S1,S2,,SNS_1, S_2, \dots, S_N whose last three characters coincide with one or more of T1,T2,,TMT_1, T_2, \dots, T_M.

Constraints

  • 1N,M10001 \leq N, M \leq 1000
  • NN and MM are integers.
  • SiS_i is a string of length 66 consisting of digits, for all i=1,2,,Ni = 1, 2, \dots, N.
  • TjT_j is a string of length 33 consisting of digits, for all j=1,2,,Mj = 1, 2, \dots, M.

Input

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

NN MM

S1S_1

S2S_2

\vdots

SNS_N

T1T_1

T2T_2

\vdots

TMT_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 S1S_1 are 857, which coincide with T3T_3.
The last three characters of S2S_2 are 159, which coincide with T1T_1.
The last three characters of S3S_3 are 028, which do not coincide with T1T_1, T2T_2, or T3T_3.

Thus, the answer is 22.

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

update @ 2024/3/10 11:59:25

}