Under construction

Still being built. Things may change

Restoring a Permutation

Time limit2sMemory limit1024 MB

Summary
Given a transformed permutation, construct a Robin permutation of 1 to 2n that maps to it, or report -1 if none exists.
Level

Medium7 of 10

Topics
Greedy, Sorting, Implementation
Solved
No attempts yet

Statement

Today Christopher studied sequences and permutations at school. A permutation of the numbers 1 to nn is a sequence a1,…,ana_1, \ldots, a_n in which each of these numbers appears exactly once.

Christopher especially liked these definitions:

  • A descent at position ii in a permutation ⟨a1,a2,…,an⟩\langle a_1, a_2, \ldots, a_n \rangle is a case where ai>ai+1a_i > a_{i+1}.
  • A fixed point at position ii in a permutation ⟨a1,a2,…,an⟩\langle a_1, a_2, \ldots, a_n \rangle is an element aia_i such that ai=ia_i = i.

Christopher made up his own permutation and called it a Robin permutation. A permutation A=⟨a1,a2,…,a2n⟩A = \langle a_1, a_2, \ldots, a_{2n} \rangle of the numbers 1 to 2n2n is a Robin permutation if both of the following hold:

  • AA has exactly nn descents, and all of them are at odd positions. That is, a2i−1>a2i<a2i+1a_{2i-1} > a_{2i} < a_{2i+1} for every ii.
  • AA has exactly nn fixed points.

For example, ⟨3,2,6,4,5,1⟩\langle 3, 2, 6, 4, 5, 1 \rangle is a Robin permutation.

Christopher shared his discovery with Rabbit. After learning about Robin permutations, Rabbit came up with this transformation: remove all fixed points from the sequence, then replace each remaining number with the count of numbers in the remaining sequence that are not greater than it. For example, ⟨3,2,6,4,5,1⟩→⟨3,6,1⟩→⟨2,3,1⟩\langle 3, 2, 6, 4, 5, 1 \rangle \to \langle 3, 6, 1 \rangle \to \langle 2, 3, 1 \rangle.

Christopher now wants to take a transformed permutation and find a Robin permutation that transforms into it.

Input

The first line contains nn, the number of elements in the transformed permutation (1≤n≤100 0001 \le n \le 100\,000). The second line contains nn natural numbers, the transformed permutation.

Output

If no solution exists, print −1-1 on the first line. If a Robin permutation exists, print one. If there are several, print any Robin permutation.

Examples2

  1. Example 1

    Input
    3
    2 3 1
    
    Expected output
    3 2 6 4 5 1
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    -1