e-olymp
favorite We need a little bit of your help to keep things running, click on this banner to learn more
Competitions

Data Structures

Replacement

Given a sequence of n positive integers. You must replace each element with the next nearest one (with a larger index) that is strictly larger than its value. If there is no larger element, replace this element with zero.

Input

First line contains the number of elements n (1n105). Second line contains n positive integers ai (ai109) - the values of sequence elements.

Output

Print the desired sequence, separating the neighboring elements with a single space.

Time limit 1 second
Memory limit 128 MiB
Input example #1
6
1 2 3 1 1 5
Output example #1
2 3 5 5 5 0
Input example #2
5
1 2 3 4 5
Output example #2
2 3 4 5 0
Source 2005 Petrozavodsk,SPb ETU Contest, Thursday, August 25