All problems

Problem 101

Intersection of Two Arrays

Easy · 10 pts · Array, Hash Table, Sorting

Problem

You are given two arrays of integers. Print every value that appears in both arrays, each value only once, in increasing order. If the arrays have no value in common, print -1. Put the values of the first array in a hash set, then collect the values of the second array that are in it (using another set to avoid repeats), and sort the result.

Input

First line: integer N. Second line: N integers. Third line: integer M. Fourth line: M integers.

Output

Print the common values in increasing order, space-separated, or -1.

Constraints

1 <= N, M <= 100000; -1000000000 <= values <= 1000000000

Example input

4
1 2 2 1
2
2 2

Example output

2

Explanation

The first array is 1 2 2 1 and the second is 2 2. The only value in both is 2, and it is printed once, so the output is 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Pair With Given Difference Next: Contains Duplicate