#C12849. Find Common Unique Elements

    ID: 42321 Type: Default 1000ms 256MiB

Find Common Unique Elements

Find Common Unique Elements

You are given two lists of integers. Your task is to find all the common elements between the two lists, remove any duplicates, and output them in ascending order. More formally, given two lists (A) and (B), you need to compute (\text{result} = \mathrm{sorted}({ x \mid x \in A \text{ and } x \in B })). If there are no common elements, output an empty line.

inputFormat

The input is read from standard input and consists of four lines:

  1. The first line contains an integer (n), 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), the number of elements in the second list.
  4. The fourth line contains (m) space-separated integers representing the second list.

outputFormat

Print the common unique elements in ascending order, separated by a single space. If there are no common elements, print an empty line.## sample

6
1 2 3 4 4 5
6
3 4 4 5 6 7
3 4 5