#K10076. Daily Temperatures

    ID: 23166 Type: Default 1000ms 256MiB

Daily Temperatures

Daily Temperatures

Given a list of daily temperatures, your task is to determine for each day how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, store 0 for that day.

More formally, given an array \(T\) of \(n\) integers, for each index \(i\) (where \(0 \leq i < n\)), define the answer \(d_i\) as:

[ d_i = \begin{cases} j - i, & \text{if there exists a smallest index } j \text{ such that } j > i \text{ and } T[j] > T[i], \ 0, & \text{if no such index exists.} \end{cases} ]

Your solution must read the input from stdin and output your answer to stdout as space-separated integers.

inputFormat

The input consists of two lines. The first line contains a single integer \(n\) indicating the number of days. The second line contains \(n\) space-separated integers representing the daily temperatures.

For example:

8
73 74 75 71 69 72 76 73

outputFormat

Output a single line containing \(n\) space-separated integers, where the \(i\)-th integer represents the number of days you must wait until a warmer temperature for the \(i\)-th day. If no warmer day exists, output 0 for that position.

For the example above, the output should be:

1 1 4 2 1 1 0 0
## sample
8
73 74 75 71 69 72 76 73
1 1 4 2 1 1 0 0