PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000006. Những đĩa CD trùng nhau (CD)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những đĩa CD trùng nhau (CD)

CD

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Jack and Jill each own a collection of CDs. Every CD title is represented by its positive catalog number. Neither person owns more than one copy of the same title.

They plan to sell one CD for every title they both own. You are given the catalog numbers in each collection, separately sorted in strictly increasing order. Count how many different titles occur in both collections.

Input

  • The first line contains two nonnegative integers NN and MM: the numbers of CDs owned by Jack and Jill.
  • The next NN lines each contain one integer aia_i, the catalog number of Jack's ii-th CD, in increasing order.
  • The following MM lines each contain one integer bjb_j, the catalog number of Jill's jj-th CD, in increasing order.

Output

Print one integer: the number of distinct catalog numbers present in both collections.

Subtasks

  • Subtask 1 (20 points): 0≤N,M≤1060\le N,M\le 10^6; 1≤N+M≤141\le N+M\le 14; 1≤ai,bj≤1091\le a_i,b_j\le 10^9; each nonempty list is strictly increasing (no repeated catalog numbers within a list).
  • Subtask 2 (30 points): 0≤N,M≤1060\le N,M\le 10^6; 1≤N+M≤1001\le N+M\le 100; 1≤ai,bj≤1091\le a_i,b_j\le 10^9; each nonempty list is strictly increasing (no repeated catalog numbers within a list).
  • Subtask 3 (50 points): 0≤N,M≤1060\le N,M\le 10^6; 1≤N+M≤20000001\le N+M\le 2000000; 1≤ai,bj≤1091\le a_i,b_j\le 10^9; each nonempty list is strictly increasing (no repeated catalog numbers within a list).

Examples

Input

3 3
1
2
3
1
2
4

Output

2

Explanation

Jack owns CDs 1, 2, 3, while Jill owns CDs 1, 2, 4. The common catalog numbers are 1 and 2; 3 belongs only to Jack and 4 only to Jill. They can therefore sell two CDs, so the output is 2.