#include #include #include #include #include #include #define MAX 10e10 #define ll long long int using namespace std; int N; class pos{ public: int a,b; pos(int c,int d){a=c;b=d;} }; bool valid(int a,int b) { if(a < 0 || b < 0) return false; if(a >= N || b >= N) return false; return true; } int findMoves(vector > &inp,int L,int B){ queue myqueue; myqueue.push(pos(0,0)); while(myqueue.size() != 0){ pos &c = myqueue.front(); if(c.a == N-1 && c.b == N-1) {myqueue.pop();continue;} int val = inp[c.a][c.b]; if(valid(c.a+L,c.b+B)) if(inp[c.a+L][c.b+B] > val+1 || inp[c.a+L][c.b+B] == 0) {myqueue.push(pos(c.a+L,c.b+B));inp[c.a+L][c.b+B]=val+1;} if(valid(c.a+L,c.b-B)) if(inp[c.a+L][c.b-B] > val+1 || inp[c.a+L][c.b-B] == 0) {myqueue.push(pos(c.a+L,c.b-B));inp[c.a+L][c.b-B]=val+1;} if(valid(c.a-L,c.b+B)) if(inp[c.a-L][c.b+B] > val+1 || inp[c.a-L][c.b+B] == 0) {myqueue.push(pos(c.a-L,c.b+B));inp[c.a-L][c.b+B]=val+1;} if(valid(c.a-L,c.b-B)) if(inp[c.a-L][c.b-B] > val+1 || inp[c.a-L][c.b-B] == 0) {myqueue.push(pos(c.a-L,c.b-B));inp[c.a-L][c.b-B]=val+1;} if(valid(c.a+B,c.b+L)) if(inp[c.a+B][c.b+L] > val+1 || inp[c.a+B][c.b+L] == 0) {myqueue.push(pos(c.a+B,c.b+L));inp[c.a+B][c.b+L]=val+1;} if(valid(c.a+B,c.b-L)) if(inp[c.a+B][c.b-L] > val+1 || inp[c.a+B][c.b-L] ==0 ) {myqueue.push(pos(c.a+B,c.b-L));inp[c.a+B][c.b-L]=val+1;} if(valid(c.a-B,c.b+L)) if(inp[c.a-B][c.b+L] > val+1 || inp[c.a-B][c.b+L] == 0) {myqueue.push(pos(c.a-B,c.b+L));inp[c.a-B][c.b+L]=val+1;} if(valid(c.a-B,c.b-L)) if(inp[c.a-B][c.b-L] > val+1 || inp[c.a-B][c.b-L] == 0) {myqueue.push(pos(c.a-B,c.b-L));inp[c.a-B][c.b-L]=val+1;} myqueue.pop(); } if(inp[N-1][N-1] == 0) return -1; return inp[N-1][N-1]; } void initialize(vector > &inp){ for(int i=0;i my(N,0); inp.push_back(my); } } int main(){ cin>>N; for(int i=1;i > inp; initialize(inp); cout<