667. Next Greater Element - II

0

Medium

Given a circular integer array called 'nums', where the next element of nums[nums.length - 1] is nums[0], find the next greater number for every element in nums. The next greater number of a number 'x' is the first greater number to its traversing-order next in the array. If it doesn't exist, print -1 for this number.

Input Format

The first line contains an integer 'n' which represents the size of the array.
The second line contains 'n' space-separated integers, representing the elements of the array.

Output Format

Print the next greater number for every element in nums.

Example

Input

5
1 2 3 4 3

Output

2 3 4 -1 4

Constraints

1 <= n <= 10^5
-10^4 <= nums[i] <= 10^4

Loading...

View Submissions

Console