#Q139. 「一本通 4.4 练习 4」跳跳棋

「一本通 4.4 练习 4」跳跳棋

Description

Original source: BZOJ 2144

Halma is played on a number line. Pieces can only be placed on integer points, and no point can hold more than one piece. We use Halma to create a simple game: there are three pieces on the board at positions aa, bb, and cc. The goal is to move them to positions xx, yy, and zz (note: the pieces are indistinguishable) with the fewest moves possible.

The rules for moving are simple. Select any piece and jump it over a central piece. After the jump, the distance between the two pieces remains the same. Only one piece may be jumped over in a single move.

Write a program to first determine if the task can be completed. If possible, output the minimum number of moves required.

halma.png

Input Format

The first line contains three integers representing the current positions of the pieces aa, bb, cc. The second line contains three integers representing the target positions xx, yy, zz.

Output Format

If there is no solution, output a single line NO. If the target can be reached, the first line should output YES, and the second line should output the minimum number of moves.

Sample 1

1 2 3
0 3 5

YES
2

Data Range and Hints

For 20%20\% of the data, the absolute values of the input integers do not exceed 1010;

For 40%40\% of the data, the absolute values of the input integers do not exceed 10410^4;

For 100%100\% of the data, the absolute values of the input integers do not exceed 10910^9. It is guaranteed that aa, bb, cc are distinct, and xx, yy, zz are distinct.