cho.sh
Notes
Loading...

Gap Pair Sequence

Time limit

2s

Memory limit

128 MB

Problem

A set X contains N distinct integers. We want to build a sequence S of length 2N.

S is a gap pair sequence if it satisfies both conditions below.

  1. Every element of X appears in S exactly twice.
  2. If the element is i, then exactly i numbers appear between the two occurrences of i in S.

For instance, if X = {1, 2, 3} and S = {2 3 1 2 1 3}, every element of X appears twice. There are exactly 2 numbers between the two 2s, exactly 1 number between the two 1s, and exactly 3 numbers between the two 3s, so the sequence satisfies the conditions.

Given X, construct a valid sequence S.

Input

The first line contains N, the size of X. The second line contains the N distinct integers in X, separated by spaces. N is a positive integer not greater than 8. Each element of X is an integer from 0 to 16, inclusive.

Output

Print one valid sequence on the first line. If more than one valid sequence exists, print the lexicographically smallest one. If no valid sequence exists, print -1.