#include #include #include #include #include #include #include #include //#include using namespace std; #define f(i,n) for(int i=0;i=0;--i) #define rfab(i,a,b) for(int i=a;i>=b;--i) #define itf(it,m) for(typeof(m.begin()) it=m.begin();it!=m.end();++it) #define ll long long #define li long #define sf(x) scanf("%d",&x); #define sfc(x) scanf("%c",&x); #define sfl(x) scanf("%ld",&x); #define sfll(x) scanf("%lld",&x); #define pf(x) printf("%d",(int)x); #define pfl(x) printf("%ld",(long)x); #define pfll(x) printf("%lld",(long long)x); #define pfs(x) printf(x); #define pfnl printf("\n"); #define pii pair #define ms(a,val,size) memset(a,val,size*sizeof(typeof(*a))) #define Mod (ll)(1e9+7) #define INF 0x3f3f3f3f #define pb push_back #define MKSTR( x ) #x #define seti(x) __builtin_popcount(x) //No of Bits Set #define setli(x) __builtin_popcountl(x) #define setll(x) __builtin_popcountll(x) #define numOfTrailingZeros(x) __builtin_ctz(x) #define numOfLeadingZeros(x) __builtin_clz(x) #define LSSetBit(x) __builtin_ffs(x) //Returns position of least significant Set Bit in x eg 1 for 1 #define powi(x,y) __builtin_powi(x,y) //double,int : faster than pow; powif,powil #define toBinary(x,noOfBits) std::bitset(x) #define ispow2(x) ((x&(x-1)) == 0) //Fails just for x==0 //#define ispow2(x) (x && !(x & (x - 1))) #define modIfPow2(n,d) (n&(d-1)) // n%d if ispow2(d)==1 #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //#define DEBUG #ifdef DEBUG // debug here ; use cerr #endif ll modPow(ll n, ll exp) { if(exp==0) return 1; if(exp==1 || n==0 || n==1 ) return n%Mod; if(exp%2){ ll ans=modPow(n,(exp-1)/2); return ((ans*ans)%Mod * (n%Mod))%Mod; } else{ ll ans=modPow(n,exp/2); return (ans*ans)%Mod; } } ll Pow(ll n, ll exp) { if(exp==0) return 1; if(exp==1 || n==0 || n==1 ) return n; if(exp%2){ ll ans=Pow(n,(exp-1)/2); return ((ans*ans) * (n)); } else{ ll ans=Pow(n,exp/2); return (ans*ans); } } ll modPow(ll n, ll exp, ll mod = Mod) { ll ans = 1; while(exp) { if (exp & 1) ans = ans * n % mod; n = n * n % mod; exp>>=1; } return ans; } #define pp pair #define PP pair int main() { fastIO int n; cin>>n; int si,sj,di,dj; cin>>si>>sj>>di>>dj; bool v[n][n]; pp par[n][n]; // si-=1;sj-=1;di-=1;dj-=1; f(i,n) f(j,n) v[i][j]=0,par[i][j]={i,j}; v[si][sj]=1; queue q; q.push({{si,sj},0}); int ti,tj; int dis; int ans=-1; while(!q.empty()) { PP cur=q.front(); q.pop(); ti=cur.first.first; tj=cur.first.second; dis=cur.second; if(ti>=2) { if(tj>0 && !v[ti-2][tj-1]){ v[ti-2][tj-1]=1; par[ti-2][tj-1]={ti,tj}; q.push({{ti-2,tj-1},dis+1}); if(ti-2==di && tj-1==dj){ ans=dis+1; break; } } if(tj0 && !v[ti+2][tj-1]){ v[ti+2][tj-1]=1; par[ti+2][tj-1]={ti,tj}; q.push({{ti+2,tj-1},dis+1}); if(ti+2==di && tj-1==dj){ ans=dis+1; break; } } } if(tj>=2 && !v[ti][tj-2]){ v[ti][tj-2]=1; par[ti][tj-2]={ti,tj}; q.push({{ti,tj-2},dis+1}); if(ti==di && tj-2==dj){ ans=dis+1; break; } } } if(ans==-1) cout<<"Impossible"; else{ cout<