import java.util.Scanner;
public class Main {
private static int[][] KNIGHT_MOVES = {{1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}};
private static boolean[][] cleanBoard() {
boolean [][] board = new boolean[8][];
for (int i = 0; i < 8; ++i) {
board[i] = new boolean[8];
}
return board;
}
private static boolean isValidCoordinates(int x, int y) {
return ((0 <= x && x < 8) && (0 <= y && y < 8));
}
private static void safeSet(boolean[][] board, int x, int y, boolean value) {
if (isValidCoordinates(x, y)) {
board[x][y] = value;
}
}
//kinda Lee algorithm
private static boolean[][] nextKnightMove(boolean[][] currentBoard) {
boolean[][] result = cleanBoard();
for (int x = 0; x < 8; ++x) {
for (int y = 0; y < 8; ++y) {
if (currentBoard[x][y]) {
for (int[] move : KNIGHT_MOVES) {
int newX = x + move[0];
int newY = y + move[1];
safeSet(result, newX, newY, true);
}
}
}
}
return result;
}
public static float solve(boolean[][] reachableByKnight, Point2d pawn) {
float result = 1;
//check if pawn may already be taken
if (reachableByKnight[pawn.x][pawn.y]) {
result = -1;
}
else {
while (pawn.y < 8 - 1) { // we start with white's move
// knight may blocks
if (reachableByKnight[pawn.x][pawn.y + 1]) {
result = 0.5f;
//We can't win after draw. No need to consider this square anymore.
reachableByKnight[pawn.x][pawn.y + 1] = false;
}
// pawn may take, so there are forbidden squares for knight
safeSet(reachableByKnight, pawn.x - 1, pawn.y + 1, false);
safeSet(reachableByKnight, pawn.x + 1, pawn.y + 1, false);
// otherwise white move forward
++pawn.y;
// and knight makes next move
reachableByKnight = nextKnightMove(reachableByKnight);
// if knight can take pawn then black immediately win
if (reachableByKnight[pawn.x][pawn.y]) {
result = -1;
break;
}
}
}
return result;
}
//btw, if knight and pawn are on different colored squares then knight can't win - every move color of squares under knight and pawn changes
public static float solve(Point2d pawn, Point2d knight) {
boolean[][] reachableByKnight = cleanBoard();
reachableByKnight[knight.x][knight.y] = true;
float resultCase2 = -1;
// consider case when pawn makes 2-square move in the beginning
if (pawn.y == 1) {
boolean isColliding = (knight.x == pawn.x) && (knight.y == 2 || knight.y == 3);
if (!isColliding) {
Point2d pawnCase2 = new Point2d(pawn);
pawnCase2.y += 2;
boolean[][] reachableByKnightCase2 = nextKnightMove(reachableByKnight);
resultCase2 = solve(reachableByKnightCase2, pawnCase2);
}
}
// case without 2-square move by pawn
float resultCase1 = solve(reachableByKnight, pawn);
return Math.
max(resultCase1, resultCase2
); }
public static void main
(String[] args
) { Scanner in
= new Scanner
(System.
in); Point2d pawn = new Point2d(in.next());
Point2d knight = new Point2d(in.next());
in.close();
System.
out.
println(solve
(pawn, knight
)); }
public static class Point2d {
public int x = 0;
public int y = 0;
public Point2d() {}
public Point2d(Point2d other) {
this.x = other.x;
this.y = other.y;
}
assert s.matches("[a-h][1-8]");
this.x = s.charAt(0) - 'a';
this.y = s.charAt(1) - '1';
}
}
}