Messy Kevin IX
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
, the number of can towers.
The second line contains space-separated integers
, the heights of the can towers that Kevin can see.
Output
Print integers. For each can
, output the index
of the next can to the right with
. If no such can exists, output
.
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