Under construction

Still being built. Things may change

Rightplant

Time limit1sMemory limit1024 MB

Summary
Given N, build an arrangement of heights 1 to N so that the total number of direction reversals over all rightward branch fires is maximized.
Level

Hard8 of 10

Topics
Array, Simulation, Greedy
Solved
No attempts yet

Problem

There are NN buildings in a row, each with a distinct integer height from 11 to NN. The height of the ii-th building from the left is HiH_i.

If a branch is fired to the right from a building of height hh, the branch flies over buildings whose height is at most hh. When the branch hits a building taller than hh, that building's height decreases by 11, and the branch reverses direction.

A branch fired right from a building of height hh flies over a building shorter than hh

A branch fired right from a building of height hh flies over a building of height hh

A branch fired right from a building of height hh hits a building taller than hh and reverses direction

Fire a branch to the right from the ii-th building from the left. Let BiB_i be the number of times that branch changes direction until it flies past the leftmost or rightmost building. Find the sequence HH that maximizes B1+B2+⋯+BNB_1 + B_2 + \dots + B_N.

Input

The first line contains an integer NN. (2≤N≤5 0002 \le N \le 5\,000)

Output

Print the elements H1,H2,…,HNH_1, H_2, \dots, H_N of a sequence HH that maximizes B1+B2+⋯+BNB_1 + B_2 + \dots + B_N, separated by spaces. If there are several such sequences, print any of them.

Examples1

  1. Example 1

    Input
    2
    
    Expected output
    1 2