#K62547. Unique Array Intersection
Unique Array Intersection
Unique Array Intersection
Given two arrays, determine their intersection. The intersection should include each common element only once, even if it appears multiple times in the input arrays. The resulting elements must be printed in ascending order.
Formally, if you are given two arrays A and B, you need to compute the set
$$I = \{ x \mid x \in A \text{ and } x \in B \}$$and then output the sorted elements of \(I\) separated by a space. If there are no common elements, output an empty line.
inputFormat
The input is read from standard input and has the following format:
n A[0] A[1] ... A[n-1] m B[0] B[1] ... B[m-1]
Here, the first line contains an integer n representing the size of the first array, followed by a line containing n space-separated integers. Then, an integer m is given, followed by a line containing m space-separated integers for the second array.
outputFormat
Print the unique common elements from both arrays in ascending order as a single line with each number separated by a space. If no common elements are found, output an empty line.
## sample4
1 2 2 1
2
2 2
2