#include using namespace std; typedef long long ll; typedef long double ld; typedef pair P; typedef pair Pi; #define rep(i,n) for(ll i=0;i inline bool chmax(T &a, T b){if(a inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template ostream& operator<<(ostream& s,const complex& d) {return s<<"("< ostream& operator<<(ostream& s,const pair& d) {return s<<"("< ostream& operator<<(ostream& s, const vector& d){int len=d.size();rep(i,len){s< ostream& operator<<(ostream& s,const vector>& d){int len=d.size();rep(i,len){s< ostream& operator<<(ostream& s,const set& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template ostream& operator<<(ostream& s,const map& m){s<<"{"<>h>>w; Pi st,en; cin>>st.se>>st.fi>>en.se>>en.fi; st.fi--,st.se--,en.fi--,en.se--; vector> g(h,vector(w)); rep(i,h)rep(j,w) cin>>g[i][j]; auto bfs=[&](Pi s,Pi go){ vector dx={1,-1,0,0},dy={0,0,1,-1}; queue que; vector> dist(h,vector(w,INF)); que.push(s); dist[s.fi][s.se]=0; while(!que.empty()){ Pi now=que.front(); que.pop(); rep(i,4){ int nx=now.fi+dx[i],ny=now.se+dy[i]; if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1){ if(g[nx][ny]!='#' && dist[nx][ny]==INF){ dist[nx][ny]=dist[now.fi][now.se]+1; que.push(Pi(nx,ny)); } } } } return dist[go.fi][go.se]; }; cout<