Chain
Easy
Execution time limit is 3 seconds
Runtime memory usage limit is 128 megabytes
Given a sequence of integers . For any element we find the first larger than element, which is placed to the right of (if such exists). Denote it by . Then do the same with and denote the found element by , and so on until we run out of the given sequence. Thus formed subsequence , we call chain beginning at index .
Write a program that outputs for any index the length of the corresponding chain that starts at index .
Input
The first line contains positive integer . The second line contains the elements of the given sequence .
Output
Print in one line the sequence of chain’s lengths, corresponding to the elements of the input data.
Examples
Input #1
Answer #1
Submissions 520
Acceptance rate 34%