Problem E
Color Tubes
There is a new puzzle generating buzz on social media—Color
Tubes. The rules are relatively simple: you are given
Using a series of moves, you are supposed to reach a Color Tubes state—each tube should either hold 3 balls of a single color or it should be empty.
The only move allowed is to take the top ball from one tube and place it into a different tube that has room for it (i.e. holds at most two balls before the move).
You want to write a program to solve this puzzle for you.
Initially, you are not interested in an optimal solution, but
you want your program to be good enough to solve any puzzle
configuration using at most
Input
The first line of input contains a single integer
Each of the next
The tubes are numbered from
Output
On the first line output an integer
On the next
Your solution will be deemed incorrect if it uses more than
Sample Input 1 | Sample Output 1 |
---|---|
3 2 2 0 1 3 1 3 1 2 3 0 0 |
6 3 1 2 3 2 4 3 2 3 2 3 4 |
Sample Input 2 | Sample Output 2 |
---|---|
1 0 0 0 1 1 1 |
0 |