B - Tombola Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

HW 列からなるグリッドがあります。各マスには整数が 1 つずつ書かれており、これらの整数は相異なります。グリッドの上から i 行目・左から j 行目のマスには整数 A_{i,j} が書かれています。

いま、司会が N 個の相異なる整数 B_1, \dots, B_N を叫びました。

それぞれの行に対して、司会の叫んだ整数がその行に何個含まれるかを求めたとき、それらの最大値はいくつになりますか?

制約

  • 1 \leq H \leq 3
  • 1 \leq W \leq 5
  • 1 \leq N \leq 90
  • 1 \leq A_{i,j} \leq 90
  • A_{i,j} は相異なる
  • 1 \leq B_i \leq 90
  • B_i は相異なる
  • 入力される値はすべて整数

入力

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

H W N
A_{1,1} \cdots A_{1,W}
\vdots
A_{H,1} \cdots A_{H,W}
B_1
\vdots
B_N

出力

答えを 1 行に出力せよ。


入力例 1

3 4 5
12 3 5 7
6 10 11 9
1 2 4 8
2
4
9
6
11

出力例 1

3
  • 上から 1 行目にある整数のうち、司会の叫んだ整数は 0 個です。
  • 上から 2 行目にある整数のうち、司会の叫んだ整数は 6,11,93 個です。
  • 上から 3 行目にある整数のうち、司会の叫んだ整数は 2,42 個です。

以上より、0,3,2 のうちの最大値である 3 が答えです。


入力例 2

3 5 2
81 63 31 16 15
30 3 6 54 24
26 41 48 64 66
44
79

出力例 2

0

入力例 3

3 5 12
78 19 70 58 83
12 30 80 20 27
48 71 8 43 82
82
30
43
8
80
70
20
78
12
71
19
48

出力例 3

5

Score : 200 points

Problem Statement

There is a grid with H rows and W columns. Each square has one integer written on it, and these integers are distinct. The square at the i-th row from the top and j-th column from the left has the integer A_{i,j} written on it.

Now, the host called out N distinct integers B_1, \dots, B_N.

If you find, for each row, how many of the integers called out by the host are contained in that row, what is the maximum value among these?

Constraints

  • 1 \leq H \leq 3
  • 1 \leq W \leq 5
  • 1 \leq N \leq 90
  • 1 \leq A_{i,j} \leq 90
  • A_{i,j} are distinct.
  • 1 \leq B_i \leq 90
  • B_i are distinct.
  • All input values are integers.

Input

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

H W N
A_{1,1} \cdots A_{1,W}
\vdots
A_{H,1} \cdots A_{H,W}
B_1
\vdots
B_N

Output

Output the answer in one line.


Sample Input 1

3 4 5
12 3 5 7
6 10 11 9
1 2 4 8
2
4
9
6
11

Sample Output 1

3
  • Among the integers in the 1-st row from the top, 0 integers were called out by the host.
  • Among the integers in the 2-nd row from the top, 3 integers 6,11,9 were called out by the host.
  • Among the integers in the 3-rd row from the top, 2 integers 2,4 were called out by the host.

Thus, the answer is the maximum value among 0,3,2, which is 3.


Sample Input 2

3 5 2
81 63 31 16 15
30 3 6 54 24
26 41 48 64 66
44
79

Sample Output 2

0

Sample Input 3

3 5 12
78 19 70 58 83
12 30 80 20 27
48 71 8 43 82
82
30
43
8
80
70
20
78
12
71
19
48

Sample Output 3

5