离开中山路
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define PII pair<int,int >
#define int long long
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);using namespace std;const int N = 1e6+10,M = 2000;int n,m;
int stx,sty,edx,edy;
char va[M][M];
int vis[M][M];
int dist[M][M];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};void bfs()
{queue<pair<int,int> > q;vis[stx][sty] = 1;dist[stx][sty] = 0;q.push({stx,sty});while(q.size()>=1){pair<int,int> now = q.front();q.pop();int x = now.first,y = now.second;for(int i=0;i<=3;i++){int xx = x+dx[i],yy = y+dy[i];if(xx>=1&&xx<=n&&yy>=1&&yy<=n&&vis[xx][yy]==0&&va[xx][yy]=='0'){vis[xx][yy] = 1;dist[xx][yy] = dist[x][y]+1;q.push({xx,yy});}}}
}signed main()
{IOS;cin>>n;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)cin>>va[i][j];}cin>>stx>>sty>>edx>>edy;bfs();cout<<dist[edx][edy];return 0;
}