Students stand in a row facing right. A student is a leader if they are strictly taller than everyone standing to their right. The last student is always a leader.
Print all leaders in the order they stand.
Input Format The first line has n. The second line has n heights.
Output Format Print the leaders in their original order, separated by single spaces.
Constraints • 1 ≤ n ≤ 1000 • 1 ≤ height ≤ 1000
Examples
Example 1
Input
6
16 17 4 3 5 2
Output
17 5 2
Explanation 17 is taller than everyone after it, 5 beats 2, and 2 is last.
Example 2
Input
4
1 2 3 4
Output
4
Explanation Only the last student is a leader.
Example 3
Input
4
9 7 5 3
Output
9 7 5 3
Explanation Every student is taller than all to their right.
Acceptance—
Accepted0
Submissions0
Auto-save
SavedLn 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
17 5 2
No results yet
Run your code to test it against the sample cases.