Lexicographically Smallest Valid Sequence
InterviewTime limit1sMemory limit128 MB
Given a permutation S, construct the lexicographically smallest permutation T where each element differs from the corresponding S element by at most 1.
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.
Tis also a permutation containing every integer from1tonexactly once.- 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.