#C13312. Intersection of Two Lists Without Duplicates

    ID: 42837 Type: Default 1000ms 256MiB

Intersection of Two Lists Without Duplicates

Intersection of Two Lists Without Duplicates

You are given two lists of integers. Your task is to find the intersection of these two lists, i.e. the set of numbers that appear in both lists. The result should not contain any duplicates and must be printed in ascending order.

More formally, let \(A\) be the first list and \(B\) be the second list. You need to compute the set \(X = \{ x \mid x \in A \wedge x \in B \}\) and output the elements of \(X\) in sorted order.

If there are no common elements, output an empty line.

inputFormat

The input is read from the standard input in the following format:

  1. The first line contains an integer \(n\) representing the number of elements in the first list.
  2. The second line contains \(n\) space-separated integers representing the first list.
  3. The third line contains an integer \(m\) representing the number of elements in the second list.
  4. The fourth line contains \(m\) space-separated integers representing the second list.

outputFormat

Print a single line containing the common elements in ascending order. The elements must be separated by a single space. If no common elements exist, print an empty line.

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