- 01
 - 02
 - 03
 - 04
 - 05
 - 06
 - 07
 - 08
 - 09
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 - 22
 - 23
 - 24
 - 25
 - 26
 - 27
 - 28
 - 29
 - 30
 - 31
 - 32
 - 33
 - 34
 - 35
 - 36
 - 37
 - 38
 - 39
 - 40
 - 41
 - 42
 - 43
 - 44
 - 45
 - 46
 - 47
 - 48
 - 49
 - 50
 - 51
 - 52
 - 53
 - 54
 - 55
 - 56
 - 57
 - 58
 - 59
 - 60
 - 61
 - 62
 - 63
 - 64
 - 65
 - 66
 - 67
 - 68
 - 69
 - 70
 - 71
 - 72
 - 73
 - 74
 - 75
 - 76
 - 77
 - 78
 - 79
 - 80
 - 81
 - 82
 - 83
 - 84
 - 85
 - 86
 - 87
 - 88
 - 89
 - 90
 - 91
 - 92
 - 93
 - 94
 - 95
 - 96
 - 97
 - 98
 - 99
 
                        #include <iostream>
  
#define LL long long
  
using namespace std;
  
 
  
bool Diagonals(int, int);
  
const int N = 9;
int brd[N][N], x, y, _x, _y;
int W[8][2] = {{-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}, 
                {1, 2}, {2, 1}, {2, -1}, {1, -2}}; 
  
int main()
{
    char c;
    cin >> c >> y;
    x = c - 'A' + 1;
    cin >> c >> _y;
    _x = c - 'A' + 1;
      
    x--; y--; _x--; _y--;
  
    y = N - y  - 1;
    _y = N - _y - 1;
  
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            brd[i][j] = (i + j) % 2;
      
    brd[_y][_x] = 2;
  
    if(x == _x && y == _y)
        cout << 0;
    else
        if((_x + _y) % 2)
            cout << -1;
        else
        {
            if((x + y) % 2)
            {
                int dx, dy;
                for(int k = 0; k < 8; k++)
                {
                    dx = x + W[k][0], dy = y + W[k][1];
                    if((dx >= 0 && dx < N) && (dy >= 0 && dy < N))
                        if(brd[dy][dx] > 1)
                        {
                            cout << 1;
                            return 0;
                        }
                }
  
                for(int k = 0; k < 8; k++)
                {
                    dx = x + W[k][0], dy = y + W[k][1];
                    if((dx >= 0 && dx < N) && (dy >= 0 && dy < N))
                    {
                        if(Diagonals(dx, dy))
                        {
                            cout << 2;
                            return 0;
                        }
                    }
                }
                cout << 3;
            }
            else
                cout << (Diagonals(x, y) ? 1 : 2);
        }
  
    return 0;
}
  
bool Diagonals(int x, int y)
{
    int t = x;
    x = y, y = t;
    int j = y, i = x;
    for(; i < N && j < N; i++, j++){
        if(brd[i][j] > 1)
            return true;
    }
    for(j = y, i = x; i >= 0 && j >= 0; i--, j--){
        if(brd[i][j] > 1)
            return true;
    }
    for(j = y, i = x; i < N && j >= 0; i++, j--){
        if(brd[i][j] > 1)
            return true;
    }
    for(j = y, i = x; i >= 0 && j < N; i--, j++){
        if(brd[i][j] > 1)
            return true;
    }
    return false;
}
                                     
        
            Решение задачи на acmp - после бутылки вина, писал сам не знаю что. настрал.