//#define _GLIBCXX_DEBUG #include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair; template bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;} template bool chmax(T &a,T b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } template ostream &operator<<(ostream &os, pair&p){ return os << p.first << " " << p.second; } struct z{ ll x,y,d; z(ll a,ll b,ll c):x(a),y(b),d(c){}; }; vector>dist(5005,vector(5005,INF)); void bfs(ll h,ll w,ll sx,ll sy,vector&a){ rep(i,0,h)rep(j,0,w)dist[i][j]=INF; queueque; que.emplace(sx,sy,0); while(!que.empty()){ auto pos = que.front(); que.pop(); if(dist[pos.x][pos.y]!=INF||a[pos.x][pos.y]=='#')continue; dist[pos.x][pos.y]=pos.d; for(ll i=0;i<4;i++){ ll x=pos.x+dx[i],y=pos.y+dy[i],d=pos.d+1; if(x<0||x>=h||y<0||y>=w)continue; que.emplace(x,y,d); } } } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll r,c;cin>>r>>c; ll sy,sx,gy,gx;cin>>sy>>sx>>gy>>gx;sy--;sx--;gy--;gx--; vectora(r); rep(i,0,r)cin>>a[i]; bfs(r,c,sx,sy,a); cout<