import java.util.*;
import java.lang.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Ideone {
public static class Pair<T1, T2> {
public T1 fst;
public T2 snd;
public Pair(T1 t1, T2 t2) {
this.fst = t1;
this.snd = t2;
}
}
public static void main
(String[] args
) {
char a, b;
int nx, ny, tx, ty;
int mx[] = {-1, -1, 1, 1, -2, -2, 2, 2};
int my[] = {2, -2, 2, -2, 1, -1, 1, -1};
int A[][] = new int[8][8];
Scanner s
= new Scanner
(System.
in); while (s.hasNextLine()) {
Pattern p = Pattern.compile("^(.)(\\d) (.)(\\d)$");
Matcher m = p.matcher(line);
m.find();
a = m.group(1).toCharArray()[0];
b = m.group(3).toCharArray()[0];
nx = a - 'a';
ny--;
tx = b - 'a';
ty--;
A[nx][ny] = 0;
Queue
<Pair
<Integer, Integer
>> q
= new LinkedList
<Pair
<Integer, Integer
>>(); q.
add(new Pair
<Integer, Integer
>(nx, ny
)); while (!q.isEmpty()) {
Pair
<Integer, Integer
> c
= q.
peek(); int x = c.fst, y = c.snd;
if (x == tx && y == ty) break;
q.remove();
for (int i = 0; i < 8; i++) {
if (x + mx[i] >= 0 && x + mx[i] < 8 && y + my[i] >= 0 && y + my[i] < 8) {
q.
add(new Pair
<Integer, Integer
>(x
+ mx
[i
], y
+ my
[i
])); A[x + mx[i]][y + my[i]] = A[x][y] + 1;
}
}
}
System.
out.
printf("To get from %c%d to %c%d takes %d knight moves.\n", a, ny
+ 1, b, ty
+ 1, A
[tx
][ty
]); }
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLnV0aWwucmVnZXguTWF0Y2hlcjsKaW1wb3J0IGphdmEudXRpbC5yZWdleC5QYXR0ZXJuOwoKY2xhc3MgSWRlb25lIHsKCiAgICBwdWJsaWMgc3RhdGljIGNsYXNzIFBhaXI8VDEsIFQyPiB7CiAgICAgICAgcHVibGljIFQxIGZzdDsKICAgICAgICBwdWJsaWMgVDIgc25kOwoKICAgICAgICBwdWJsaWMgUGFpcihUMSB0MSwgVDIgdDIpIHsKCiAgICAgICAgICAgIHRoaXMuZnN0ID0gdDE7CiAgICAgICAgICAgIHRoaXMuc25kID0gdDI7CiAgICAgICAgfQogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIAogewogICAgICAgIGNoYXIgYSwgYjsKICAgICAgICBpbnQgbngsIG55LCB0eCwgdHk7CiAgICAgICAgaW50IG14W10gPSB7LTEsIC0xLCAxLCAxLCAtMiwgLTIsIDIsIDJ9OwogICAgICAgIGludCBteVtdID0gezIsIC0yLCAyLCAtMiwgMSwgLTEsIDEsIC0xfTsKICAgICAgICBpbnQgQVtdW10gPSBuZXcgaW50WzhdWzhdOwogICAgICAgIFNjYW5uZXIgcyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICAgU3RyaW5nIHN0cjsKICAgICAgICB3aGlsZSAocy5oYXNOZXh0TGluZSgpKSB7CiAgICAgICAgICAgIFN0cmluZyBsaW5lID0gcy5uZXh0TGluZSgpOwogICAgICAgICAgICBQYXR0ZXJuIHAgPSBQYXR0ZXJuLmNvbXBpbGUoIl4oLikoXFxkKSAoLikoXFxkKSQiKTsKICAgICAgICAgICAgTWF0Y2hlciBtID0gcC5tYXRjaGVyKGxpbmUpOwogICAgICAgICAgICBtLmZpbmQoKTsKICAgICAgICAgICAgYSA9IG0uZ3JvdXAoMSkudG9DaGFyQXJyYXkoKVswXTsKICAgICAgICAgICAgbnkgPSBJbnRlZ2VyLnBhcnNlSW50KG0uZ3JvdXAoMikpOwogICAgICAgICAgICBiID0gbS5ncm91cCgzKS50b0NoYXJBcnJheSgpWzBdOwogICAgICAgICAgICB0eSA9IEludGVnZXIucGFyc2VJbnQobS5ncm91cCg0KSk7CiAgICAgICAgICAgIG54ID0gYSAtICdhJzsKICAgICAgICAgICAgbnktLTsKICAgICAgICAgICAgdHggPSBiIC0gJ2EnOwogICAgICAgICAgICB0eS0tOwogICAgICAgICAgICBBW254XVtueV0gPSAwOwogICAgICAgICAgICBRdWV1ZTxQYWlyPEludGVnZXIsIEludGVnZXI+PiBxID0gbmV3IExpbmtlZExpc3Q8UGFpcjxJbnRlZ2VyLCBJbnRlZ2VyPj4oKTsKICAgICAgICAgICAgcS5hZGQobmV3IFBhaXI8SW50ZWdlciwgSW50ZWdlcj4obngsIG55KSk7CiAgICAgICAgICAgIHdoaWxlICghcS5pc0VtcHR5KCkpIHsKICAgICAgICAgICAgICAgIFBhaXI8SW50ZWdlciwgSW50ZWdlcj4gYyA9IHEucGVlaygpOwogICAgICAgICAgICAgICAgaW50IHggPSBjLmZzdCwgeSA9IGMuc25kOwogICAgICAgICAgICAgICAgaWYgKHggPT0gdHggJiYgeSA9PSB0eSkgYnJlYWs7CiAgICAgICAgICAgICAgICBxLnJlbW92ZSgpOwogICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCA4OyBpKyspIHsKICAgICAgICAgICAgICAgICAgICBpZiAoeCArIG14W2ldID49IDAgJiYgeCArIG14W2ldIDwgOCAmJiB5ICsgbXlbaV0gPj0gMCAmJiB5ICsgbXlbaV0gPCA4KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHEuYWRkKG5ldyBQYWlyPEludGVnZXIsIEludGVnZXI+KHggKyBteFtpXSwgeSArIG15W2ldKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIEFbeCArIG14W2ldXVt5ICsgbXlbaV1dID0gQVt4XVt5XSArIDE7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJUbyBnZXQgZnJvbSAlYyVkIHRvICVjJWQgdGFrZXMgJWQga25pZ2h0IG1vdmVzLlxuIiwgYSwgbnkgKyAxLCBiLCB0eSArIDEsIEFbdHhdW3R5XSk7CiAgICAgICAgfQogICAgfQp9