#C13730. Common Elements Finder

    ID: 43301 Type: Default 1000ms 256MiB

Common Elements Finder

Common Elements Finder

Given two lists of integers, find their intersection. The output should contain only the elements that appear in both lists without duplicates. In mathematical terms, for two sets \(A\) and \(B\), compute \(A \cap B\).

Read the input from standard input and write the result to standard output.

inputFormat

The input consists of four lines:

  • The first line contains an integer \(n\) denoting the number of elements in the first list.
  • The second line contains \(n\) space-separated integers representing the first list. (If \(n = 0\), this line will be empty.)
  • The third line contains an integer \(m\) denoting the number of elements in the second list.
  • The fourth line contains \(m\) space-separated integers representing the second list. (If \(m = 0\), this line will be empty.)

outputFormat

Output a single line with the common elements in increasing order, separated by a single space. If there are no common elements, output an empty line.

## sample
5
1 2 3 4 5
5
0 2 4 6 8
2 4