String String

Time limit: 1s Memory limit: 256MB Input: Output:

For Halloween, Mondialu went to each of his neighbors to ask for candies. In order to receive the maximum number of candies, he needs to be as scary as possible.

Mondialu has nn Halloween costumes a1,a2,a3,,ana_1, a_2, a_3, \dots , a_n. He needs to choose a subsequence (a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements) from the nn costumes (yes, \t{Mondialu} can wear multiple costumes, this is the level of scariness we are dealing with).

A subsequence is the scariest if it has the following properties:

  • Has an even positive length.
  • The first half of the subsequence is equal to the second half.
  • It is the lexicographically largest subsequence.

An array XX is lexicographically larger than an array YY if there exist an ii so that x1=y1,x2=y2,,xi1=yi1x_1 = y_1, x_2 = y_2, \dots , x_{i-1} = y_{i-1} and xi>yix_i > y_i or if YY is a prefix of XX.

Input data

The first line of each test case contains a single integer nn, 1n1051 \le n \le 10^5 - the length of the array.

The second line of each test case contains nn integers a1,a2,a3,,ana_1, a_2, a_3, \dots , a_n, 1ai1091 \le a_i \le 10^9 - the elements of the array.

Output data

Output a single line, the elements of the scariest subsequence separated by spaces. If no such subsequence exists, print -1.

Constraints and clarifications

  • 1n51 \le n \le 5 for 2020 points;
  • 5<n1005 < n \le 100 for 2020 points;
  • 100<n1 000100 < n \le 1 \ 000 for 2020 points;
  • 1 000<n100 0001 \ 000 < n \le 100 \ 000 for 4040 points.

Example 1

stdin

8
3 1 2 3 2 3 3 3

stdout

3 3 3 3

Explanation

In the first example, the subsequence 3 3 3 33\ 3\ 3\ 3 has an even positive length (44) and the first half 3 33\ 3 is equal to the second half 3 33\ 3. This is the lexicographically largest subsequence which respects the conditions.

Example 2

stdin

3
1 2 3

stdout

-1

Explanation

In the second example, we cannot generate any subsequence which would respect the conditions, so the output is -1.

Log in or sign up to be able to send submissions!