#STK0000086. Hàng đợi (Queue)
Hàng đợi (Queue)
Queue
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are people in a queue from left to right, where person has value . For every , find the farthest position to the right such that . If it exists, print the number of people strictly between and , namely ; otherwise print .
Input
The first line contains . The second line contains integers .
Output
Print integers in position order.
Subtasks
- Subtask 1 (30 points): ; all other conditions are unchanged.
- Subtask 2 (70 points): , .
Examples
Input
6
10 8 5 3 50 45
Output
2 1 0 -1 0 -1
Explanation
The values are .
- Position has value . The farthest smaller value to the right is at position . Positions and lie between them, so the answer is .
- Position has value . The farthest smaller value is again at position ; only position lies between them, so the answer is .
- Position has value . Position has value , and there is no farther smaller value, so the number of positions between them is .
- Position has value . No smaller value exists to its right, so the answer is .
- Position has value . Position has value and is adjacent, so the answer is .
- Position has nobody to its right, so the answer is .
Therefore the output is 2 1 0 -1 0 -1.