#include using namespace std; struct cell { int x, y; int dis; cell() {} cell(int x, int y, int dis) : x(x), y(y), dis(dis) {} }; bool isInside(int x, int y, int N) { if (x >= 0 && x <= N && y >= 0 && y <= N) return true; return false; } bool visit[7 + 1][7 + 1]; int minStepToReachTarget(int knightPos[], int targetPos[], int N) { int dx[] = {-2,-2,0,0,2,2}; int dy[] = {1,-1,-2,2,-1,1}; queue q; q.push(cell(knightPos[0], knightPos[1], 0)); cell t; int x, y; for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) visit[i][j] = false; visit[knightPos[0]][knightPos[1]] = true; while (!q.empty()) { t = q.front(); q.pop(); visit[t.x][t.y] = true; if (t.x == targetPos[0] && t.y == targetPos[1]) return t.dis; for (int i = 0; i <6; i++) { x = t.x + dx[i]; y = t.y + dy[i]; if (isInside(x, y, N) && !visit[x][y]){ q.push(cell(x, y, t.dis + 1)); } } // v1.push_back(t.x); // v2.push_back(t.y); } return 0; } int main() { int N,sx,sy,dx,dy; cin>>N; int knightPos[2]; int targetPos[2]; cin>>sx; cin>>sy; cin>>dx; cin>>dy; knightPos[0]=sx;knightPos[1]=sy; targetPos[0]=dx;targetPos[1]=dy; if(minStepToReachTarget(knightPos, targetPos, N)==0){ cout<<"Impossible"; } /* for(int i=0;i