#C7553. Intersection of Two Arrays

    ID: 51437 Type: Default 1000ms 256MiB

Intersection of Two Arrays

Intersection of Two Arrays

You are given two arrays of integers. Your task is to compute a sorted list of unique elements that appear in both arrays.

The problem is defined as follows:

  • Read an integer n denoting the number of elements in the first array.
  • Read n integers representing the first array.
  • Read an integer m denoting the number of elements in the second array.
  • Read m integers representing the second array.

Output the common elements between the two arrays, printed in ascending order and separated by a single space. If there are no common elements, output an empty line.

Note: Each input array may contain duplicate elements, however the output must only include unique values.

The solution should be efficient and handle negative and positive integers.

inputFormat

The first line contains an integer n, the number of elements in the first array.

The second line contains n space-separated integers.

The third line contains an integer m, the number of elements in the second array.

The fourth line contains m space-separated integers.

outputFormat

Output a single line containing the sorted unique integers that appear in both arrays, separated by a single space. If there are no such integers, output an empty line.

## sample
4
1 2 2 3
4
2 3 3 4
2 3