Search for unique elements in the intersection of two arrays

JavaScript Medium sets

Task «Search for unique elements in the intersection of two arrays»

Two arrays of integers are given. It is necessary to find all unique elements that are present in both arrays and output them in ascending order. Use the Set data structure to solve the problem.

Input Format

First line: an integer N (1 ≤ N ≤ 1000) — the number of elements in the first array. Second line: N integers separated by spaces. Third line: an integer M (1 ≤ M ≤ 1000) — the number of elements in the second array. Fourth line: M integers separated by spaces.

Output Format

One line: unique elements of the intersection of arrays, sorted in ascending order, separated by a space. If the intersection is empty, output an empty line.

Examples

Example 1

INPUT
3 10 20 30 3 40 50 60
OUTPUT

Example 2

INPUT
4 1 1 2 2 4 2 2 3 3
OUTPUT
2

Example 3

INPUT
5 apple banana apple cherry banana
OUTPUT
apple banana cherry
main.js