#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>h>>w; Int a,sy,sx; cin>>a>>sy>>sx; Int b,gy,gx; cin>>b>>gy>>gx; vector st(h); for(Int i=0;i>st[i]; using T = tuple; queue q; memset(dp,0,sizeof(dp)); dp[a][sy][sx]=1; q.emplace(a,sy,sx); auto in=[&](Int y,Int x){return 0<=y&&y