#K77417. Filter Elements Greater Than Next

    ID: 34860 Type: Default 1000ms 256MiB

Filter Elements Greater Than Next

Filter Elements Greater Than Next

Given a list of integers, your task is to construct a new list by selecting those elements that are greater than the element immediately following them. The last element is always included in the output.

For example, consider the list [5, 3, 8, 4, 2, 10]. The elements 5, 8, and 4 are each greater than the element that follows them, and by rule the final element 10 is also included. Therefore, the expected output is [5, 8, 4, 10].

If the list is empty, the output should also be an empty list.

Note: When comparing elements, use the strict greater-than condition.

inputFormat

The first line contains an integer n representing the number of elements in the list.

The second line contains n space-separated integers.

It is guaranteed that n is non-negative.

outputFormat

Output a single line containing the filtered list elements separated by a single space.

## sample
6
5 3 8 4 2 10
5 8 4 10