#K6041. Daily Temperatures

    ID: 31080 Type: Default 1000ms 256MiB

Daily Temperatures

Daily Temperatures

You are given a sequence of daily temperatures \( T = [T_0, T_1, \ldots, T_{n-1}] \). For each day, your task is to determine the number of days one must wait until a warmer temperature occurs. If there is no future day for which this is possible, output 0 for that day.

Explanation: For each position \( i \), find the smallest index \( j \) such that \( j > i \) and \( T_j > T_i \). The answer for the day is \( j-i \). If no such \( j \) exists, the answer is 0.

Example:

Input: 8
       73 74 75 71 69 72 76 73
Output: 1 1 4 2 1 1 0 0

inputFormat

The input is read from standard input and has the following format:

  • The first line contains an integer \( n \), the number of days.
  • The second line contains \( n \) space-separated integers, each representing the temperature for one day.

outputFormat

Print a single line containing \( n \) space-separated integers. The \( i^{th} \) integer represents the number of days until a warmer temperature appears. If no warmer day exists, output 0 for that day.

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