#K73992. Devices Receiving Light

    ID: 34098 Type: Default 1000ms 256MiB

Devices Receiving Light

Devices Receiving Light

In this problem, you are given a sequence of devices with certain heights arranged in a row from left to right. A light source is installed at the far right end of the row. A device can receive light if there is no device to its right that is of equal or greater height. Formally, given a device at position i with height \(h_i\), it will receive light if and only if for every device at position j such that i < j ≤ n, the following holds:

[ h_i > h_j \quad \text{for all } j \text{ such that } i < j \leq n ]

Your task is to output the list of devices that receive the light in the order they appear (from left to right).

Note: The input size will be at most 105, so your solution must be efficient.

inputFormat

The first line contains a single integer n (1 ≤ n ≤ 105) representing the number of devices.

The second line contains n space-separated integers representing the heights of the devices.

outputFormat

Output a single line containing the heights of the devices that can receive light, in their original order (from left to right), separated by spaces.

## sample
6
3 7 8 3 6 1
8 6 1