#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef std::pair<int, double> Result;
std::vector<Result> endings;
void addResult(const Result& result){
if (std::find(endings.begin(), endings.end(), result) == endings.end()){
endings.push_back(result);
}
}
bool customLess(const Result& a, const Result& b)
{
return (a.first != b.first) ? a.first < b.first : a.second < b.second;
}
void turn(int n, char pawn_x, char pawn_y, char pony_x, char pony_y){
//printf("%d %c%c-%c%c\n", n, pawn_x, pawn_y, pony_x, pony_y);
//если ходит пешка(белые)
if (n % 2 != 0){
//если пешка дошла в ферзи
if (pawn_y == '8'){
//если на следующем ходу ферзя может побить конь
if (((pony_y == '7') && ((pawn_x - 2) == pony_x)) ||
((pony_y == '7') && ((pawn_x + 2) == pony_x)) ||
((pony_y == '6') && ((pawn_x - 1) == pony_x)) ||
((pony_y == '6') && ((pawn_x + 1) == pony_x)))
{
//то победа негров
addResult(Result(n, -1));
}
else {
//иначе победа белых
addResult(Result(n, 1));
}
}
//если пешка может побить пони на текущем ходу
else if ((pawn_y+1 == pony_y) && ((pawn_x+1 == pony_x) || (pawn_x-1 == pony_x))){
//победа белых
addResult(Result(n, 1));
}
//если пешке преграждает путь пони
else if ((pawn_x == pony_x) && (pawn_y+1 == pony_y)){
//то ничья
addResult(Result(n, 0.5));
}
//иначе просто ходим пешкой
else {
//если стоит на второй клетке и ничто не мешает прыгнуть на 2
if (pawn_y == '2' && !(pony_y == '4' && pony_x == pawn_x)){
turn(n + 1, pawn_x, pawn_y + 2, pony_x, pony_y);
}
turn(n + 1, pawn_x, pawn_y + 1, pony_x, pony_y);
}
}
//если ходит пони(черные)
else {
char pony_turns[8][2] = {
{(char)(pony_x-1), (char)(pony_y-2)},
{(char)(pony_x-2), (char)(pony_y-1)},
{(char)(pony_x-1), (char)(pony_y+2)},
{(char)(pony_x-2), (char)(pony_y+1)},
{(char)(pony_x+1), (char)(pony_y+2)},
{(char)(pony_x+2), (char)(pony_y+1)},
{(char)(pony_x+1), (char)(pony_y-2)},
{(char)(pony_x+2), (char)(pony_y-1)}
};
for (int i=0; i<8; ++i){
//если конь может побить пешку
if ((pony_turns[i][0] == pawn_x) && (pony_turns[i][1] == pawn_y)){
addResult(Result(n, -1));
}
// а если не может, но ход в пределах шахматной доски
else if ((pony_turns[i][0] <= 'h') && (pony_turns[i][0] >= 'a') && (pony_turns[i][1] <= '8') && (pony_turns[i][1] >= '1')){
//то пусть сцуко ходит
turn(n + 1, pawn_x, pawn_y, pony_turns[i][0], pony_turns[i][1]);
}
}
}
}
int main()
{
string pawn;
string pony;
cin >> pawn;
cin >> pony;
turn(1, pawn[0], pawn[1], pony[0], pony[1]);
std::sort(endings.begin(), endings.end(), customLess);
/*for (const Result &r: endings){
cout << r.first << ' ' << r.second << endl;
}*/
cout << endings.front().second << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgc3RkOjpwYWlyPGludCwgZG91YmxlPiBSZXN1bHQ7CnN0ZDo6dmVjdG9yPFJlc3VsdD4gZW5kaW5nczsKCnZvaWQgYWRkUmVzdWx0KGNvbnN0IFJlc3VsdCYgcmVzdWx0KXsKICAgIGlmIChzdGQ6OmZpbmQoZW5kaW5ncy5iZWdpbigpLCBlbmRpbmdzLmVuZCgpLCByZXN1bHQpID09IGVuZGluZ3MuZW5kKCkpewogICAgICAgIGVuZGluZ3MucHVzaF9iYWNrKHJlc3VsdCk7CiAgICB9Cn0KCmJvb2wgY3VzdG9tTGVzcyhjb25zdCBSZXN1bHQmIGEsIGNvbnN0IFJlc3VsdCYgYikKewogICAgcmV0dXJuIChhLmZpcnN0ICE9IGIuZmlyc3QpID8gYS5maXJzdCA8IGIuZmlyc3QgOiBhLnNlY29uZCA8IGIuc2Vjb25kOwp9Cgp2b2lkIHR1cm4oaW50IG4sIGNoYXIgcGF3bl94LCBjaGFyIHBhd25feSwgY2hhciBwb255X3gsIGNoYXIgcG9ueV95KXsKICAgIC8vcHJpbnRmKCIlZCAlYyVjLSVjJWNcbiIsIG4sIHBhd25feCwgcGF3bl95LCBwb255X3gsIHBvbnlfeSk7CgogICAgLy/QtdGB0LvQuCDRhdC+0LTQuNGCINC/0LXRiNC60LAo0LHQtdC70YvQtSkKICAgIGlmIChuICUgMiAhPSAwKXsKCiAgICAgICAgLy/QtdGB0LvQuCDQv9C10YjQutCwINC00L7RiNC70LAg0LIg0YTQtdGA0LfQuAogICAgICAgIGlmIChwYXduX3kgPT0gJzgnKXsKICAgICAgICAgICAgLy/QtdGB0LvQuCDQvdCwINGB0LvQtdC00YPRjtGJ0LXQvCDRhdC+0LTRgyDRhNC10YDQt9GPINC80L7QttC10YIg0L/QvtCx0LjRgtGMINC60L7QvdGMCiAgICAgICAgICAgIGlmICgoKHBvbnlfeSA9PSAnNycpICYmICgocGF3bl94IC0gMikgPT0gcG9ueV94KSkgfHwKICAgICAgICAgICAgICAgICgocG9ueV95ID09ICc3JykgJiYgKChwYXduX3ggKyAyKSA9PSBwb255X3gpKSB8fAogICAgICAgICAgICAgICAgKChwb255X3kgPT0gJzYnKSAmJiAoKHBhd25feCAtIDEpID09IHBvbnlfeCkpIHx8CiAgICAgICAgICAgICAgICAoKHBvbnlfeSA9PSAnNicpICYmICgocGF3bl94ICsgMSkgPT0gcG9ueV94KSkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIC8v0YLQviDQv9C+0LHQtdC00LAg0L3QtdCz0YDQvtCyCiAgICAgICAgICAgICAgICBhZGRSZXN1bHQoUmVzdWx0KG4sIC0xKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICAvL9C40L3QsNGH0LUg0L/QvtCx0LXQtNCwINCx0LXQu9GL0YUKICAgICAgICAgICAgICAgIGFkZFJlc3VsdChSZXN1bHQobiwgMSkpOwogICAgICAgICAgICB9CiAgICAgICAgfQoKCiAgICAgICAgLy/QtdGB0LvQuCDQv9C10YjQutCwINC80L7QttC10YIg0L/QvtCx0LjRgtGMINC/0L7QvdC4INC90LAg0YLQtdC60YPRidC10Lwg0YXQvtC00YMKICAgICAgICBlbHNlIGlmICgocGF3bl95KzEgPT0gcG9ueV95KSAmJiAoKHBhd25feCsxID09IHBvbnlfeCkgfHwgKHBhd25feC0xID09IHBvbnlfeCkpKXsKICAgICAgICAgICAgLy/Qv9C+0LHQtdC00LAg0LHQtdC70YvRhQogICAgICAgICAgICBhZGRSZXN1bHQoUmVzdWx0KG4sIDEpKTsKICAgICAgICB9CgogICAgICAgIC8v0LXRgdC70Lgg0L/QtdGI0LrQtSDQv9GA0LXQs9GA0LDQttC00LDQtdGCINC/0YPRgtGMINC/0L7QvdC4CiAgICAgICAgZWxzZSBpZiAoKHBhd25feCA9PSBwb255X3gpICYmIChwYXduX3krMSA9PSBwb255X3kpKXsKICAgICAgICAgICAgLy/RgtC+INC90LjRh9GM0Y8KICAgICAgICAgICAgYWRkUmVzdWx0KFJlc3VsdChuLCAwLjUpKTsKICAgICAgICB9CgogICAgICAgIC8v0LjQvdCw0YfQtSDQv9GA0L7RgdGC0L4g0YXQvtC00LjQvCDQv9C10YjQutC+0LkKICAgICAgICBlbHNlIHsKICAgICAgICAgICAgLy/QtdGB0LvQuCDRgdGC0L7QuNGCINC90LAg0LLRgtC+0YDQvtC5INC60LvQtdGC0LrQtSDQuCDQvdC40YfRgtC+INC90LUg0LzQtdGI0LDQtdGCINC/0YDRi9Cz0L3Rg9GC0Ywg0L3QsCAyCiAgICAgICAgICAgIGlmIChwYXduX3kgPT0gJzInICYmICEocG9ueV95ID09ICc0JyAmJiBwb255X3ggPT0gcGF3bl94KSl7CiAgICAgICAgICAgICAgICB0dXJuKG4gKyAxLCBwYXduX3gsIHBhd25feSArIDIsIHBvbnlfeCwgcG9ueV95KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0dXJuKG4gKyAxLCBwYXduX3gsIHBhd25feSArIDEsIHBvbnlfeCwgcG9ueV95KTsKICAgICAgICB9CiAgICB9CgogICAgLy/QtdGB0LvQuCDRhdC+0LTQuNGCINC/0L7QvdC4KNGH0LXRgNC90YvQtSkKICAgIGVsc2UgewogICAgICAgIGNoYXIgcG9ueV90dXJuc1s4XVsyXSA9IHsKICAgICAgICAgICAgeyhjaGFyKShwb255X3gtMSksIChjaGFyKShwb255X3ktMil9LAogICAgICAgICAgICB7KGNoYXIpKHBvbnlfeC0yKSwgKGNoYXIpKHBvbnlfeS0xKX0sCiAgICAgICAgICAgIHsoY2hhcikocG9ueV94LTEpLCAoY2hhcikocG9ueV95KzIpfSwKICAgICAgICAgICAgeyhjaGFyKShwb255X3gtMiksIChjaGFyKShwb255X3krMSl9LAogICAgICAgICAgICB7KGNoYXIpKHBvbnlfeCsxKSwgKGNoYXIpKHBvbnlfeSsyKX0sCiAgICAgICAgICAgIHsoY2hhcikocG9ueV94KzIpLCAoY2hhcikocG9ueV95KzEpfSwKICAgICAgICAgICAgeyhjaGFyKShwb255X3grMSksIChjaGFyKShwb255X3ktMil9LAogICAgICAgICAgICB7KGNoYXIpKHBvbnlfeCsyKSwgKGNoYXIpKHBvbnlfeS0xKX0KICAgICAgICB9OwoKICAgICAgICBmb3IgKGludCBpPTA7IGk8ODsgKytpKXsKICAgICAgICAgICAgLy/QtdGB0LvQuCDQutC+0L3RjCDQvNC+0LbQtdGCINC/0L7QsdC40YLRjCDQv9C10YjQutGDCiAgICAgICAgICAgIGlmICgocG9ueV90dXJuc1tpXVswXSA9PSBwYXduX3gpICYmIChwb255X3R1cm5zW2ldWzFdID09IHBhd25feSkpewogICAgICAgICAgICAgICAgYWRkUmVzdWx0KFJlc3VsdChuLCAtMSkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vINCwINC10YHQu9C4INC90LUg0LzQvtC20LXRgiwg0L3QviDRhdC+0LQg0LIg0L/RgNC10LTQtdC70LDRhSDRiNCw0YXQvNCw0YLQvdC+0Lkg0LTQvtGB0LrQuAogICAgICAgICAgICBlbHNlIGlmICgocG9ueV90dXJuc1tpXVswXSA8PSAnaCcpICYmIChwb255X3R1cm5zW2ldWzBdID49ICdhJykgJiYgKHBvbnlfdHVybnNbaV1bMV0gPD0gJzgnKSAmJiAocG9ueV90dXJuc1tpXVsxXSA+PSAnMScpKXsKICAgICAgICAgICAgICAgIC8v0YLQviDQv9GD0YHRgtGMINGB0YbRg9C60L4g0YXQvtC00LjRggogICAgICAgICAgICAgICAgdHVybihuICsgMSwgcGF3bl94LCBwYXduX3ksIHBvbnlfdHVybnNbaV1bMF0sIHBvbnlfdHVybnNbaV1bMV0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpCnsKICAgIHN0cmluZyBwYXduOwogICAgc3RyaW5nIHBvbnk7CgogICAgY2luID4+IHBhd247CiAgICBjaW4gPj4gcG9ueTsKCgogICAgdHVybigxLCBwYXduWzBdLCBwYXduWzFdLCBwb255WzBdLCBwb255WzFdKTsKICAgIHN0ZDo6c29ydChlbmRpbmdzLmJlZ2luKCksIGVuZGluZ3MuZW5kKCksIGN1c3RvbUxlc3MpOwoKCgogICAgLypmb3IgKGNvbnN0IFJlc3VsdCAmcjogZW5kaW5ncyl7CiAgICAgICAgY291dCA8PCByLmZpcnN0IDw8ICcgJyA8PCByLnNlY29uZCA8PCBlbmRsOwogICAgfSovCgoKICAgIGNvdXQgPDwgZW5kaW5ncy5mcm9udCgpLnNlY29uZCA8PCBlbmRsOwoKICAgIHJldHVybiAwOwp9Cgo=