#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include using namespace std; using ll=int64_t; using ull=uint64_t; using lll=__int128_t; using ulll=__uint128_t; using db=double; using ld=long double; using pint=pair; using pill=pair; using pll=pair; using plli=pair; template using unmap=unordered_map; template using unset=unordered_set; template using heap=priority_queue; template using min_heap=priority_queue,greater>; namespace rgs=ranges; #define rep(i,l,r) for(ll i=(ll)(l);i<(ll)(r);i++) #define per(i,r,l) for(ll i=(ll)(r);i>=(ll)(l);i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define ep emplace #define ef emplace_front #define pof pop_front #define eb emplace_back #define pob pop_back #define fi first #define se second #define YES cout<<"Yes\n" #define NO cout<<"No\n" #define YN(flag) (flag) ? YES:NO #define ENDL cout<<'\n' const int INF32=(1<<30)-1; const ll INF64=(1ll<<62)-1; const ll MOD99=998244353; const ll MOD10=1000000007; const ld PI=acosl(-1); const array di={1,0,-1,0,-1,1,-1,1}; const array dj={0,1,0,-1,-1,1,1,-1}; template istream& operator>>(istream &is,pair &x){ return is>>x.fi>>x.se; } template ostream& operator<<(ostream &os,const pair &x){ return os< istream& operator>>(istream &is,vector &vec){ rep(i,0,size(vec)) is>>vec[i]; return is; } template ostream& operator<<(ostream &os,const vector &vec){ rep(i,0,size(vec)) (i==0 ? os< ostream& operator<<(ostream &os,const vector> &vec){ rep(i,0,size(vec)) (i==0 ? os< istream& operator>>(istream &is,array &arr){ rep(i,0,N) is>>arr[i]; return is; } template ostream& operator<<(ostream &os,const array &arr){ rep(i,0,N) (i==0 ? os< ostream& operator<<(ostream &os,const set &st){ size_t i=0; for(T x : st) (i++==0 ? os< ostream& operator<<(ostream &os,const multiset &mst){ size_t i=0; for(T x : mst) (i++==0 ? os< void input(Head &head,Tail&... tail){ cin>>head; input(tail...); } void output(){ 'v'; } template void output(const Head &head,const Tail&... tail){ cout<0) cout<<' '; output(tail...); } void outputln(){ ENDL; } template void outputln(const Head &head,const Tail&... tail){ cout<0) cout<<' '; outputln(tail...); } void outputlines(){ ENDL; } template void outputlines(const Head &head,const Tail&... tail){ cout<0) cout<<'\n'; outputlines(tail...); } void lines(int n=10){ while(n--) cout<<'-'; ENDL; } template bool chmax(T &a,const T &b){ return (a bool chmin(T &a,const T &b){ return (a>b ? (a=b,true):false); } template bool outside(const T &i,const T &j,const T &h,const T &w) { return (i<0 or i>=h or j<0 or j>=w); } template T divfloor(T x,T y ){ if(y<0) x*=(-1),y*=(-1); return(x>=0 ? x/y:(x-y+1)/y); } template T divceil(T x,T y) { if(y<0) x*=(-1),y*=(-1); return(x>=0 ? (x+y-1)/y:x/y); } void flip(bool& b) { b^=1; } //////////////////////////////////////////////////////////////////////////////// bool solve(){ int h,w,a,b,r1,c1,r2,c2,p,q; input(h,w,a,b,r1,c1,r2,c2,p,q); a--,b--,r1--,c1--,p--,q--; auto bfs=[&](int si,int sj,auto goal)->pair { vector> dist(h,vector(w,INF32)); dist[si][sj]=0; queue q; q.ep(si,sj); int gi=-1,gj=-1; while(!q.empty()){ auto [i,j]=q.front(); q.pop(); //outputln(i,j,"|",goal(i,j)); if(goal(i,j)){ gi=i,gj=j; //outputln("(",i,",",j,")","(",gi,",",gj,")"); break; } rep(k,0,4){ int ni=i+di[k],nj=j+dj[k]; if(outside(ni,nj,h,w)) continue; if(chmin(dist[ni][nj],dist[i][j]+1)) q.ep(ni,nj); } } //assert(gi!=-1); assert(gj!=-1); return {dist[gi][gj],{gi,gj}}; }; int ans=0,si=a,sj=b; { auto f=[&](int i,int j)->bool { return (r1<=i and i>t; while(t--) while(solve()); return 0; }