Under construction

Still being built. Things may change

Minimum cost increasing sequence

Time limit2sMemory limit512 MB

Summary
Transform A into a strictly increasing integer sequence B minimizing the sum of |B_i - A_i|, and output the lexicographically smallest such B.
Level

Hard9 of 10

Topics
Dynamic programming, Greedy, Heap
Solved
No attempts yet

Problem

You are given an integer sequence A1,A2,…,ANA_1, A_2, \dots, A_N of length NN.

Among the integer sequences BB that satisfy B1<B2<⋯<BNB_1 < B_2 < \dots < B_N, find one that minimizes ∣B1−A1∣+∣B2−A2∣+⋯+∣BN−AN∣|B_1 - A_1| + |B_2 - A_2| + \dots + |B_N - A_N|. Every element of BB fits in a signed 32-bit integer.

Several sequences BB can reach the minimum sum. Print the lexicographically smallest one, so make B1B_1 as small as possible, then fix that value and make B2B_2 as small as possible, and continue in the same way.

Input

The first line contains NN. (1≤N≤1061 \le N \le 10^6)

The second line contains A1,A2,…,ANA_1, A_2, \dots, A_N separated by spaces. (0≤Ai≤2×1090 \le A_i \le 2 \times 10^9)

Output

Print the lexicographically smallest optimal sequence BB on NN lines, one element per line.

Hint

For A={9,4,8,20,14,15,18}A = \{9, 4, 8, 20, 14, 15, 18\} the minimum sum is 1313. More than one BB reaches it, and B={6,7,8,13,14,15,18}B = \{6, 7, 8, 13, 14, 15, 18\} also has sum 1313. The lexicographically smallest one is B={3,4,8,13,14,15,18}B = \{3, 4, 8, 13, 14, 15, 18\}.

Examples3

  1. Example 1

    Input
    7
    9 4 8 20 14 15 18
    
    Expected output
    3
    4
    8
    13
    14
    15
    18
    
  2. Example 2

    Input
    1
    0
    
    Expected output
    0
    
  3. Example 3

    Input
    5
    1 2 3 4 5
    
    Expected output
    1
    2
    3
    4
    5