Replacement
Easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given a sequence of n positive integers. You must replace each element with the next nearest one (with a larger index) that is strictly larger than its value. If there is no larger element, replace this element with zero.
Input
First line contains the number of elements n (1 ≤ n ≤ 10^5
). Second line contains n positive integers a[i]
(a[i]
≤ 10^9
) - the values of sequence elements.
Output
Print the desired sequence, separating the neighboring elements with a single space.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 4K
Acceptance rate 33%