Knight minimum moves

Given two squares on an 8x8 chessboard, output the fewest knight moves needed to get from the first to the second.

Easy3BFSGraphImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

In chess the knight moves in the strangest way of all the pieces. It goes two squares in one direction and then one square at a right angle to that direction. The picture below shows every square a knight can reach in a single move.

Because of this movement rule, the shortest path between two squares is hard to count by eye. Write a program that computes the minimum number of moves a knight needs to travel from one square to another. The chessboard has 8 rows and 8 columns, and in standard notation the columns are written with the letters a to h.

Input

The input has two lines. The first line holds the starting square of the knight and the second line holds the destination square. Each square is written in standard notation, one column letter from a to h followed by one row digit from 1 to 8, in the form e4. The starting square and the destination square may be the same.

Output

Print a single integer, the minimum number of moves the knight needs to travel from the starting square to the destination square.