for input:

10

4 3 5 9 2

output is 2 3 5 9 which gives a cost of 30,

but the correct output is 5 2 3 9 which gives a cost of 23

for input:

10

4 3 5 9 2

output is 2 3 5 9 which gives a cost of 30,

but the correct output is 5 2 3 9 which gives a cost of 23