Incomplete Chessboard

In chess, King is the most important piece. It can move left, right, up, down or diagonally, but only one square at a time, shown below. Given two squares A(r1, c1), B(r2, c2), your task is to calculate the number of moves needed to move a king from A to B. To make the problem (slightly) harder, one square C(r3,c3) is removed from the chessboard, that means the king should never go into square C during his trip. In this problem, rows are numbered 1..8 from bottom to top, and columns are numbered 1..8 from left to right. Input There will be at most 10000 test cases. Each case contains 6 integers r1, c1, r2, c2, r3, c3 (1 ≤ r1, c1, r2, c2, r3, c3 ≤ 8). Three squares A, B, C are always distinct. Output For each test case, print the case number and the minimum number of moves needed. Sample Input 118756 113322 Sample Output Case 1: 7 Case 2: 3