#P10497. Cow Lineup Reconstruction

    ID: 12511 Type: Default 1000ms 256MiB

Cow Lineup Reconstruction

Cow Lineup Reconstruction

Farmer John has N (2 \(\leq N \leq\) 8000) cows each with a unique brand from 1 to N. After a night at the local watering hole, the cows lined up for dinner in a random order. Unfortunately, Farmer John did not record the actual brands. Instead, for each cow he noted a rather odd statistic: the number of cows before that cow in line that have a smaller brand than it. Given this inversion sequence, your task is to reconstruct the exact ordering of the cows.

The inversion sequence a is defined as follows: for each position \(i\) (0-indexed) in the lineup, \(a_i\) is the number of cows before position \(i\) that have smaller brands than the cow in position \(i\). Notice that since a cow at position \(i\) can have at most \(i\) cows preceding it, we must have \(0 \leq a_i \leq i\) for all \(i\).

A standard method to reconstruct the permutation from this inversion sequence is to use a sorted list of the available brands \(\{1, 2, \dots, N\}\) and process the inversion data in reverse order. For \(i = N-1\) down to 0, remove the element at index \(a_i\) in the list and assign it as the cow's brand at position \(i\). This guarantees that the inversion condition holds.

Input constraints:
\(2 \leq N \leq 8000\)

inputFormat

The input begins with a single integer N, representing the number of cows. This is followed by N lines, each containing a single integer. The integer on the i-th line (0-indexed) represents the number of cows that precede the i-th cow in line which have a smaller brand.

outputFormat

Output the reconstructed permutation of cow brands (one per line) corresponding to the original lineup.

sample

4
0
1
0
2
2

4 1 3

</p>