Messy Kevin IX


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C++, Java, Python

Kevin has stacked up his empty energy drink cans in towers in the Duck Lounge after consuming copious amounts of caffeine during his LeetCode grind. The stacks of cans are in differing heights, and Kevin stacks them in a line from left to right.

Kevin wonders: for each can, how far can he see from left to right before his view is blocked by a taller or equal-height stack of cans? Of course, he could just brute force this calculation by staring at each can one by one, but Shahid sees him trying this and bursts out laughing. Kevin is now determined to redeem himself and solve the problem efficiently.

He has a list of the heights of each tower of cans. Help Kevin redeem his dignity!

Input

The first line contains a single integer n (1 \leq n \leq 2 \times 10^9), the number of can towers.

The second line contains n space-separated integers h_1, h_2, \dots, h_n (1 \leq h_i \leq 10^9), the heights of the can towers that Kevin can see.

Output

Print n integers. For each can i, output the index j of the next can to the right with h[j] \geq h[i]. If no such can exists, output -1.

Example

Input 1
5
2 1 3 2 5
Output 1
3
3
5
5
-1
  • Can 1 (height 2) is blocked by Can 3 (height 3).
  • Can 2 (height 1) is also blocked by Can 3.
  • Can 3 (height 3) is blocked by Can 5 (height 5).
  • Can 4 (height 2) is blocked by Can 5.
  • Can 5 sees nothing taller to the right, so -1.

Comments

There are no comments at the moment.