#ABC301B. [ABC301B] Fill the Gaps

[ABC301B] Fill the Gaps

Score : 200200 points

Problem Statement

We have a sequence of length NN consisting of positive integers: A=(A1,,AN)A=(A_1,\ldots,A_N). Any two adjacent terms have different values.

Let us insert some numbers into this sequence by the following procedure.

  1. If every pair of adjacent terms in AA has an absolute difference of 11, terminate the procedure.
  2. Let Ai,Ai+1A_i, A_{i+1} be the pair of adjacent terms nearest to the beginning of AA whose absolute difference is not 11.- If Ai<Ai+1A_i < A_{i+1}, insert Ai+1,Ai+2,,Ai+11A_i+1,A_i+2,\ldots,A_{i+1}-1 between AiA_i and Ai+1A_{i+1}.
    • If Ai>Ai+1A_i > A_{i+1}, insert Ai1,Ai2,,Ai+1+1A_i-1,A_i-2,\ldots,A_{i+1}+1 between AiA_i and Ai+1A_{i+1}.
  3. Return to step 1.

Print the sequence when the procedure ends.

Constraints

  • 2N1002 \leq N \leq 100
  • 1Ai1001 \leq A_i \leq 100
  • AiAi+1A_i \neq A_{i+1}
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print the terms in the sequence when the procedure ends, separated by spaces.

4
2 5 1 2
2 3 4 5 4 3 2 1 2

The initial sequence is (2,5,1,2)(2,5,1,2). The procedure goes as follows.

  • Insert 3,43,4 between the first term 22 and the second term 55, making the sequence (2,3,4,5,1,2)(2,3,4,5,1,2).
  • Insert 4,3,24,3,2 between the fourth term 55 and the fifth term 11, making the sequence (2,3,4,5,4,3,2,1,2)(2,3,4,5,4,3,2,1,2).
6
3 4 5 6 5 4
3 4 5 6 5 4

No insertions may be performed.