LogiQuest

59. Leaders in an Array

EasyArraySuffix Max

An element is a leader if it is strictly greater than every element to its right. The last element is always a leader. Print all leaders from left to right.

Input format

Line 1: n Line 2: n integers

Output format

The leaders in order.

Example 1

Input

6
16 17 4 3 5 2

Output

17 5 2

Example 2

Input

4
1 2 3 4

Output

4

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…