689. Next Greater Node in a Linked List

0

Easy

Given the *head* of a linked list with n nodes, your task is to determine the value of the next greater node for each node in the list. The next greater node is defined as the first node that appears after the current node and has a strictly larger value. If there is no such node, the value is set to 0. Return an integer array answer, where answer[i] represents the value of the next greater node for the ith node (1-indexed).

Input Format

The first line of input contains the length N of the linked list. The second line contains the node values of the linked list.

Output Format

Print the next greater node for each node in the linked list.

Example

Input

3
2 1 5

Output

5 5 0

Constraints

The linked list contains N nodes.

1 <= N <= 10

1 <= Node.val <= 10

1 <= N <= 10

^{4}1 <= Node.val <= 10

^{9}Loading...

View Submissions

Console