#C4311. Immediate Left Larger

    ID: 47836 Type: Default 1000ms 256MiB

Immediate Left Larger

Immediate Left Larger

You are given an array (A) of length (N). For every element with index (i) (where (1 \leq i < N)), if the previous element (A_{i-1}) is larger than (A_i), then update (A_i) to (A_{i-1}); otherwise, update it to -1. Note that the first element (A_0) should always be updated to -1 since it does not have a left neighbor.

The task is to transform the array according to this rule and output the modified array as space-separated integers.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (N) representing the number of elements in the array. The second line contains (N) space-separated integers denoting the elements of the array.

outputFormat

Print the modified array as space-separated integers in one line to standard output (stdout).## sample

5
4 2 1 5 3
-1 4 2 -1 5