Under construction

Still being built. Things may change

Elder price robot

Interview

Time limit4sMemory limit1024 MB

Summary
For each day, report how many days back the price was last lower than or equal to today's price, or infinity if no earlier price was that low.
Level

Medium5 of 10

Topics
Stack, Array, Implementation, Two pointers
Solved
No attempts yet

Problem

The idea behind your latest business adventure, BarGain Overview (BGO), is to collect the history of prices for a certain item that is available for sale on the web. The BarGain score of a particular day is defined as the number of days since the price was lower or equal to today's price. The worst BarGain score is thus 11, and if the price is strictly better than all previous prices ever recorded, then it is infinity. You want to report the BarGain score to your customers to help them identify a good buy.

Input

The first line of input contains a single integer 2≤n≤400 0002 \leq n \leq 400\,000, the number of days for which you have collected price data for the item. On the second line of input follows nn space-separated integers p1,p2,…,pnp_1, p_2, \ldots, p_{n}, where 0≤pi≤1060 \leq p_i \leq 10^6 is the price of the item i−1i-1 days ago. Today's price is p1p_1.

Output

Output nn rows, one for each day you have collected price data for the item. On the ithi^{\text{th}} such line, output the BarGain score for the day that was i−1i-1 days ago.

Examples1

  1. Example 1

    Input
    6
    9 10 11 9 12 11
    
    Expected output
    3
    2
    1
    infinity
    1
    infinity