#include using namespace std; const int maxi=1e6+10; #define pb push_back int x1,y1,x2,y2; int n,k; int d[2][1002][1002]; int a[1002][1002]; int tim[2][1002][1002]; int inside(int x, int y) { if (x>0 && x<=n && y>0 && y<=n) return 1; return 0; } void bfs(int x, int y, int par) { queue, int>> q; d[par][x][y]=1; q.push({{x,y},0}); while(!q.empty()) { pair, int> node = q.front(); q.pop(); int xi=node.first.first; int yi=node.first.second; int pari=node.second; for (int i=-2; i<=2; i++) for (int j=-2; j<=2; j++) { if (abs(i)==abs(j) || i==0 || j==0) continue; if (inside(xi-i,yi-j) && !a[xi-i][yi-j] && !d[1-pari][xi-i][yi-j]) { d[1-pari][xi-i][yi-j]=1; tim[1-pari][xi-i][yi-j]=tim[pari][xi][yi]+1; q.push({{xi-i,yi-j},1-pari}); } } } return; } int main() { freopen("chess.in","r",stdin); cin>>n>>k>>x1>>y1>>x2>>y2; for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) scanf("%d",&a[i][j]); bfs(x1,y1,0); fclose(stdin); freopen("chess.out","w",stdout); // cout<