#C3111. Bishop Moves Calculation

    ID: 46503 Type: Default 1000ms 256MiB

Bishop Moves Calculation

Bishop Moves Calculation

You are given a standard 8×8 chessboard and a bishop. The bishop moves diagonally, meaning in one move it can travel any number of squares on a diagonal. Given the initial position (r₁, c₁) and the target position (r₂, c₂) (both 1-indexed), determine the minimum number of moves required for the bishop to reach the target square. If the target square is not reachable by the bishop (i.e. the squares are of different colors), output -1.

Two squares (r₁, c₁) and (r₂, c₂) have the same color if and only if $$ (r₁ + c₁) \mod 2 = (r₂ + c₂) \mod 2 $$. Additionally, if the starting and target positions are the same, the answer is 0. If the bishop can move directly in one diagonal move, the answer is 1. Otherwise, it is always possible in 2 moves.

inputFormat

The input consists of a single line containing four space-separated integers: r₁, c₁, r₂, c₂, representing the starting and ending positions respectively. It is guaranteed that 1 ≤ r₁, c₁, r₂, c₂ ≤ 8.

outputFormat

Output a single integer which is the minimum number of moves required for the bishop to move from the starting square to the target square. If the bishop cannot reach the target, output -1.## sample

1 1 8 8
1