#P8390. MalnaRISC Sorting
MalnaRISC Sorting
MalnaRISC Sorting
This problem is adapted from COI 2021 Task 4 "MalnaRISC". In this problem, you are required to sort a sequence of numbers in non-decreasing order.
You are provided with a magical processor called MalnaRISC which supports only one command:
$\mathtt{CMPSWP\ }R_i\ R_j$
The semantics of this command is as follows: it compares the contents of registers $R_i$ and $R_j$, and if $R_i > R_j$, it swaps their values.
An interesting feature of MalnaRISC is that it can execute multiple distinct commands in one line provided that the parameters do not conflict. In other words, any register can only appear once as an argument in a given line.
Your task is to write a MalnaRISC program to sort a sequence of length N in non-decreasing (ascending) order. The performance of your solution will be evaluated based on the length of your program.
inputFormat
The first line of input contains a single integer N representing the length of the sequence.
The second line contains N space-separated integers.
outputFormat
Output the sorted sequence of numbers in non-decreasing order on a single line, separated by spaces.
sample
5
3 1 2 5 4
1 2 3 4 5
</p>