cho.sh
Notes
Loading...

Lexicographically Smallest Valid Sequence

Time limit

1s

Memory limit

128 MB

Problem

You are given a sequence S of length n. S is a permutation containing every integer from 1 to n exactly once.

Find the lexicographically smallest sequence T that satisfies all of the following conditions.

  1. T is also a permutation containing every integer from 1 to n exactly once.
  2. For every i, |T_i - S_i| <= 1.

Input

The first line contains the length n of the sequence. (3 <= n <= 50,000)

Each of the next n lines contains one element of S, in order.

Output

Print the lexicographically smallest valid sequence T, one number per line.