#C13054. Constrained List Transformation

    ID: 42550 Type: Default 1000ms 256MiB

Constrained List Transformation

Constrained List Transformation

You are given a list of unique positive integers. You are allowed to perform the following operations at most once (each) and in any order:

  1. Rotation: Rotate the list to the left by any number of positions (at least one position). For example, rotating [3, 4, 5, 1, 2] by 3 positions yields [1, 2, 3, 4, 5].
  2. Swapping: Swap the first and last elements of the list. For example, [5, 4, 3, 1, 2] becomes [2, 4, 3, 1, 5].
  3. Removal: Remove exactly one element from the list.
  4. Doubling: Double (multiply by 2) any single element in the list.

The goal is to determine if it is possible to transform the original list into its ascending sorted order by applying a subset (or all) of these operations. If it is possible, output the fully sorted list (in increasing order). Otherwise, output the original list. Note that if the list is empty, you should output an empty list.

inputFormat

The input is read from standard input (stdin) and consists of two parts:

  • The first line contains an integer N, representing the number of elements in the list.
  • The second line contains N space-separated positive integers.

outputFormat

If it is possible to transform the list into a strictly ascending order using the allowed operations, print the resulting list as space‐separated integers via standard output (stdout). Otherwise, print the original list (which might already be sorted) as space‐separated integers.

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

</p>