#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int n; void nextstep(int i, int j, int a, int b, vector> &s){ if(i+a=0&&j+b>=0){ if(s[i+a][j+b]<=s[i][j]+1) return; else{ //cout<<999; s[i+a][j+b]=s[i][j]+1; nextstep(i+a,j+b,a,b,s); nextstep(i+a,j+b,-a,b,s); nextstep(i+a,j+b,a,-b,s); nextstep(i+a,j+b,-a,-b,s); nextstep(i+a,j+b,b,a,s); nextstep(i+a,j+b,-b,a,s); nextstep(i+a,j+b,b,-a,s); nextstep(i+a,j+b,-b,-a,s); } } /*if(i-a>=0&&j+b<=n){ if(s[i-a][j+b]<=s[i][j]+1) return; else{ s[i-a][j+b]=s[i][j]+1; } } if(i+a<=n&&j-b>=0){ if(s[i+a][j-b]<=s[i][j]+1) return; else{ s[i+a][j-b]=s[i][j]+1; } } if(i-a>=0&&j-b>=0){ if(s[i-a][j-b]<=s[i][j]+1) return; else{ s[i-a][j-b]=s[i][j]+1; } } if(i+b<=n&&j+a<=n){ if(s[i+b][j+a]<=s[i][j]+1) return; else{ s[i+b][j+a]=s[i][j]+1; } } if(i-b>=0&&j+a<=n){ if(s[i-b][j+a]<=s[i][j]+1) return; else{ s[i-b][j+a]=s[i][j]+1; } } if(i-b>=0&&j-a>=0){ if(s[i-b][j-a]<=s[i][j]+1) return; else{ s[i-b][j-a]=s[i][j]+1; } } if(i+b<=n&&j-a>=0){ if(s[i+b][j-a]<=s[i][j]+1) return; else{ s[i+b][j-a]=s[i][j]+1; } } */ return; } int nextab(int a, int b){ vector> s(n,vector(n,n*n+1)); s[0][0]=0; nextstep(0,0,a,b,s); if (s[n-1][n-1]>n*n) return -1; else return s[n-1][n-1]; //return s[2][2]; } int main(){ cin >> n; // your code goes here for(int i=1;i