Page not loading? Try clicking here.
Placeholder

#1809

Tower 1s 32MB

Problems

KOI Communication Research Institute is conducting an experiment to develop a new secret communication system using lasers. 

For the experiment, N towers of different heights are placed in order from left to right on a horizontal straight line, 

and a laser transmitter is installed at the top of each tower.

The laser transmitters on all towers fire laser signals to the left, parallel to the ground,

and all tower columns are equipped with devices to receive laser signals.

A laser signal fired from one tower can only be received by the first tower it encounters.

 

For example, suppose five towers with heights 6, 9, 5, 7, and 4 are standing in a row on a horizontal line,

and all towers fire laser signals simultaneously in the opposite direction of the given tower order (to the left).

Then, the laser signal fired from the fifth tower with a height of 4 is received by the fourth tower with a height of 7,

the signal from the fourth tower with a height of 7 is received by the second tower with a height of 9,

and the signal from the third tower with a height of 5 is also received by the second tower with a height of 9.

The laser signals sent by the second tower with a height of 9 and the first tower with a height of 6 are not received by any tower.

 

Given the number of towers N and their heights,

write a program to determine which tower receives the laser signal fired from each tower.


Input

The first line contains an integer N, representing the number of towers. N is between 1 and 500,000 inclusive.

The second line contains the heights of the N towers in the order they are placed on a straight line, separated by a single space.

The heights of the towers are integers between 1 and 100,000,000 inclusive.


Output

On the first line, print the numbers of the towers that received the laser signals fired from each tower in the order they were given, separated by a single space.

If no tower receives the laser signal, print 0.


Example

5

6 9 5 7 4
0 0 2 2 4



Source

KOI 본선 2009 초4/고2

You must sign in to write code.