King's Tour#2621

King's Tour

1 second
128 megabytes
Very easy

Chess is played on an 8 \times 8 square board. Columns are marked 'a' to 'h' from left to right, and rows are numbered '1' to '8' from bottom to top. To play chess, you must know how the pieces move and attack.

A pawn attacks one square diagonally upward to the left or right. For example, if a pawn is on c3, it threatens d4 and b4. A king can move or attack one square in any direction: vertically, horizontally, or diagonally. When a pawn or king attacks a square, it moves to that square and captures the piece occupying it.

You are given the initial positions of a king, pawn A and pawn B. Find the minimum number of moves the king needs to capture pawn A. The king cannot move to squares threatened by pawns or leave the board. The king can capture pawn B, but it is not required. Pawns do not move.

Input

The input consists of several test cases. Each line contains the starting positions of the king, pawn A, and pawn B. Each position consists of two characters: the column ('a'–'h') and the row ('1'–'8'). All three positions are distinct. The king's starting position is not threatened by a pawn.

Output

For each test case, output a single line with the minimum number of moves for the king to capture pawn A.

Examples

Example 1

Loading
Loading