#C2554. Count Distinct Marble Pairs
Count Distinct Marble Pairs
Count Distinct Marble Pairs
You are given two bags of marbles, where each marble is represented by an integer indicating its color. Your task is to determine the number of distinct pairs of marbles (one from each bag) that share the same color. In other words, you need to count the number of distinct colors that appear in both bags.
Formally, if (A) is the set of unique colors in the first bag and (B) is the set of unique colors in the second bag, the answer is (|A \cap B|).
inputFormat
The input is given via standard input (stdin). The first line contains two integers (n) and (m), representing the number of marbles in the first and second bag, respectively. The second line contains (n) space-separated integers describing the colors of the marbles in the first bag. The third line contains (m) space-separated integers describing the colors of the marbles in the second bag.
outputFormat
Output a single integer via standard output (stdout), which represents the number of distinct common colors between the two bags.## sample
6 5
1 2 3 4 1 2
2 3 4 4 5
3