403866: GYM101343 H Give Me This Pizza

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Give Me This Pizzatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Today Abdalrahman and Ali have one hour break, so they decided to spend it in the Innovation Programming Lab to invent new game.

After a deep thinking they invented a new game that is played using an array a. The goal of the game is to find for each value in the array the nearest larger value to it from the right. (i.e. for the ith value in the array, the goal is to find the value in the nearest jth index, such that (1  ≤  i  <  j  ≤  n) and (aj  >  ai)). If the nearest larger value does not exist, then the answer is "-1".

Abdalrahman and Ali thought that this game is very hard and no one can solve it, so they wrote it in the white board inside the lab, and under it they wrote the following statement: "If you solve this game correctly we will give you a very big pizza".

Yosef enter the lab after Abdalrahman and Ali left it. When he saw the game, he decided to solve it to take the pizza. Yosef is very hungry currently so you decided to help him to solve the game as soon as possible. Can you?

Input

The first line contains an integer n (1  ≤  n  ≤  105), where n is the length of the array a.

The second line contains n integers a1, a2, ..., an (1  ≤  ai  ≤  50), giving the array a.

Output

Print n integers b1, b2, ..., bn, where bi is the nearest larger value for the ith value in array a. If such value does not, then bi must be "-1" (without quotes).

ExamplesInput
5
2 1 3 9 4
Output
3 3 9 -1 -1
Input
7
5 9 7 3 2 1 4
Output
9 -1 -1 4 4 4 -1

加入题单

上一题 下一题 算法标签: