#000284

BubbleBilliard

Fifteen billiard balls are placed randomly in the triangle rack. In one step you can switch any two balls. You are required to place balls correctly for game start in the minimal number of steps.


Here is the description of the correct ball placements: Balls are labeled with numbers from 1 to 15. Ball number 8 is black and must be placed in the position of the black circle (see images a and b). Balls 1-7 are called solid, and balls 9-15 are called striped. Position of all balls of either group must match all places denoted by an X on any of two images bellow, giving 4 types of correct placements in total.

Image: taskImage


InputFirst (and the only) line contains a permutation of numbers 1 – 15, separated by a space. These numbers are ball labels read row by row in top down order, each row from left to right.

OutputThe output consists of one integer number, the minimal number of moves.



Input (also in the image):
Image: ExampleImage

3 5 8 4 10 7 15 11 12 6 14 13 2 9 1
Output:
3

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.