#TP0000006. Những đĩa CD trùng nhau (CD)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 and : the numbers of CDs owned by Jack and Jill.
- The next lines each contain one integer , the catalog number of Jack's -th CD, in increasing order.
- The following lines each contain one integer , the catalog number of Jill's -th CD, in increasing order.
Output
Print one integer: the number of distinct catalog numbers present in both collections.
Subtasks
- Subtask 1 (20 points): ; ; ; each nonempty list is strictly increasing (no repeated catalog numbers within a list).
- Subtask 2 (30 points): ; ; ; each nonempty list is strictly increasing (no repeated catalog numbers within a list).
- Subtask 3 (50 points): ; ; ; 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.