#K90432. Lexicographically Largest Permutation

    ID: 37751 Type: Default 1000ms 256MiB

Lexicographically Largest Permutation

Lexicographically Largest Permutation

You are given a permutation p of integers from 1 to n. Your task is to compute the lexicographically largest permutation that can be obtained by performing any number (possibly zero) of adjacent swaps.

Since any permutation can be reached by adjacent swaps, the lexicographically largest permutation is simply the permutation sorted in descending order.

Note: A permutation of size n is an arrangement of the integers from 1 to n with each number appearing exactly once. The lexicographical order is defined as follows: for two different sequences, the sequence with a larger number at the first mismatching position is considered larger.

For example, if n = 5 and p = [1, 5, 3, 4, 2], then the lexicographically largest permutation is [5, 4, 3, 2, 1].

inputFormat

The input is given via standard input (stdin) and consists of two lines.

  • The first line contains a single integer n — the size of the permutation.
  • The second line contains n space-separated integers, representing the permutation p.

outputFormat

Output the lexicographically largest permutation. Print n space-separated integers in one line.

## sample
5
1 5 3 4 2
5 4 3 2 1