### COCI 2008/2009, Contest #4

## Task MJEHURIC

Goran has five wooden pieces arranged in a sequence. There is a number between 1 and 5 inscribed onevery piece, so that every number appears on exactly one of the five pieces.

Goran wants to order the pieces to form the sequence 1, 2, 3, 4, 5 and does it like this:

- If the number on the first piece is greater than the number on the second piece, swap them.
- If the number on the second piece is greater than the number on the third piece, swap them.
- If the number on the third piece is greater than the number on the fourth piece, swap them.
- If the number on the fourth piece is greater than the number on the fifth piece, swap them.
- If the pieces don't form the sequence 1, 2, 3, 4, 5, go to step 1.

### Input

The first line contains five integers separated by single spaces, the ordering of the pieces.The numbers will be between 1 and 5 (inclusive) and there will be no duplicates.

The initial ordering will not be 1, 2, 3, 4, 5.

### Output

After any two pieces are swapped, output the ordering of the pieces, on a single line separated by spaces.### Examples

## Input2 1 5 3 4 ## Output1 2 5 3 4 |
## Input2 3 4 5 1 ## Output2 3 4 1 5 |

All Submissions

Best Solutions

**Point Value:** 3

**Time Limit:** 2.00s

**Memory Limit:** 16M

**Added:** Jan 19, 2009

**Languages Allowed:**

C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

43618418on Jan 01, 2018 - 10:56:51 pm UTC Latest answer should workjargonon Jan 02, 2018 - 11:34:04 pm UTC Re: Latest answer should workjialeyuon Aug 09, 2016 - 3:06:01 pm UTC helpImaxPurpleon Aug 09, 2016 - 3:56:10 pm UTC Re: helpTry outputting your sequence after every iteration.

Man I had to solve a+b to help you

hardest problem of my life

jialeyuon Aug 09, 2016 - 4:27:30 pm UTC Re: helpI print my sequence after each swap...

ImaxPurpleon Aug 09, 2016 - 7:14:49 pm UTC Re: helpjialeyuon Aug 10, 2016 - 4:22:45 pm UTC Re: helpunless they're both wrong

bobbyg212009on Feb 12, 2011 - 11:43:22 pm UTC need help plsbbi5291on Feb 13, 2011 - 12:11:21 am UTC Re: need help plsbobbyg212009on Feb 13, 2011 - 12:38:28 am UTC Re: Re: need help plsbbi5291on Feb 13, 2011 - 3:59:35 am UTC Re: Re: need help pls1. If you want help because you're getting the answer wrong, say so. Otherwise it looks like you want help because you don't know how to solve the problem. Why can't you take an extra few seconds to be specific?

2. You seem to assume that only one of each of the steps 1-4 can be done each cycle. As a matter of fact, this is not true --- always go through these steps in order, and re-print the sequence after each swap, but do not go back to step 1 after performing a swap. Only go back to step 1 after you reach step 5.

bobbyg212009on Feb 13, 2011 - 5:53:21 pm UTC Re: Re: need help plsSourSpinachon Feb 13, 2011 - 2:52:46 am UTC lol