#P1852. Jumping Checkers on a Number Line

    ID: 15135 Type: Default 1000ms 256MiB

Jumping Checkers on a Number Line

Jumping Checkers on a Number Line

On a number line, we have a simple board game called Jumping Checkers. There are three indistinguishable pieces initially placed at positions \(a, b, c\) (each on an integer point with no duplicates allowed) and the goal is to move them to the positions \(x, y, z\). The pieces are identical so the order of the positions does not matter.

The only allowed move is a jump move defined as follows: In one move, you may select any one of the three pieces and a different piece to serve as the pivot. The selected piece will "jump" from its current position \(p\) to a new position \(p'\) which is the reflection of \(p\) about the pivot \(q\). In other words, the new position is given by \[ p' = 2q - p, \] and it is required that the landing position \(p'\) is not already occupied by any piece. Each jump move is allowed to cross over exactly one piece.

Your task is to determine whether it is possible to achieve the target configuration. If it is possible, output the minimum number of jump moves required; otherwise, output \(-1\).

inputFormat

The input consists of a single line containing six space-separated integers: \(a\), \(b\), \(c\), \(x\), \(y\), and \(z\). Here, \(a, b, c\) are the starting positions and \(x, y, z\) are the target positions of the three checkers. All positions are integers and no two pieces share the same position at any time.

outputFormat

Output a single integer representing the minimum number of moves required to reach the target configuration. If it is impossible, output \(-1\).

sample

1 3 6 2 4 8
2