We say that an ascending range in an array is a range where any item is greater than or equal to the previous item.

Your task is to write a program that reverses all longest and no-overlapping ascending ranges.

The program should call a function that takes an array and reverse the ascending ranges in-place.

Requirements

Input

The program takes the number list from the standard input.
The format of the input is:

  • line #1 contains the size of the list.
  • line #2 contains space-separated integer numbers.

Output

The program should display the reversed the modified array. The displaying format should be space-separated numbers.

Samples

Sample #1

$ reverse-ascending
11
5 6 7 8 8 7 5 7 4 8 9
8 8 7 6 5 7 7 5 9 8 4

Let’s explain:

The longest no-overlapping ascending ranges are :
  • Range #1 : 0..4
  • Range #2 : 5..5
  • Range #3 : 6..7
  • Range #4 : 8..10
Thus, The original array:
5 6 7 8 8 7 5 7 4 8 9
should be modified to:
8 8 7 6 5 7 7 5 9 8 4

Solutions

Python3