CCC '12 S4 - A Coin Game
For some starting configurations, it is not always possible to obtain the goal of strictly increasing order.
Input Specification
The input will contain some number of test cases. A test case consists of two lines. The first line will contain a positive integer \(n\) ( \(n < 8\) ), which is the number of coins. We assume that the coins are labeled \(1, 2, 3, \dots, n\) . The second line will contain a list of numbers \(1\) to \(n\) in an arbitrary order, which represents the initial coin configuration. For the above example, the input test case would be:
3
3 2 1The end of test cases is indicated by \(0\) on a line by itself.
Output Specification
For each test case, output one line, which will either contain the minimal number of moves in which Jo can achieve the goal coin line-up, or, if it is not possible to achieve the goal coin line-up, IMPOSSIBLE .
Sample Input
3
3 2 1
2
2 1
0Output for Sample Input
20
IMPOSSIBLE
Comments