codeforces#P1237D. Balanced Playlist
Balanced Playlist
Description
Your favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of tracks numbered from to . The playlist is automatic and cyclic: whenever track finishes playing, track starts playing automatically; after track goes track .
For each track , you have estimated its coolness . The higher is, the cooler track is.
Every morning, you choose a track. The playlist then starts playing from this track in its usual cyclic fashion. At any moment, you remember the maximum coolness of already played tracks. Once you hear that a track with coolness strictly less than (no rounding) starts playing, you turn off the music immediately to keep yourself in a good mood.
For each track , find out how many tracks you will listen to before turning off the music if you start your morning with track , or determine that you will never turn the music off. Note that if you listen to the same track several times, every time must be counted.
The first line contains a single integer (), denoting the number of tracks in the playlist.
The second line contains integers (), denoting coolnesses of the tracks.
Output integers , where is either the number of tracks you will listen to if you start listening from track or if you will be listening to music indefinitely.
Input
The first line contains a single integer (), denoting the number of tracks in the playlist.
The second line contains integers (), denoting coolnesses of the tracks.
Output
Output integers , where is either the number of tracks you will listen to if you start listening from track or if you will be listening to music indefinitely.
Samples
Note
In the first example, here is what will happen if you start with...
- track : listen to track , stop as .
- track : listen to track , stop as .
- track : listen to track , listen to track , listen to track , stop as .
- track : listen to track , listen to track , stop as .
In the second example, if you start with track , you will listen to track , listen to track , listen to track , listen to track , listen to track again, listen to track again, and stop as . Note that both track and track are counted twice towards the result.