#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <string> #include <bitset> #include <cstdio> #include <limits> #include <vector> #include <climits> #include <cstring> #include <cstdlib> #include <fstream> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; bool valid(int m,int n,int size){ if(m<0 || m >= size || n<0 || n>=size) return false; else return true; } int knight(int m,int n,vector<vector<int> > &prev,int size,int a,int b){ prev[size-1][size-1]= 1; if(m==0 && n==0) return 0; else if(m<0 || m >= size || n<0 || n>=size) return 100000; int p1=100000,p2=100000,p3=100000,p4=100000,p5=100000,p6=100000,p7=100000,p8=100000; if(valid(m+a,n+b,size)){ if(prev[m+a][n+b] != 1) { prev[m+a][n+b] = 1; p1 = knight(m+a,n+b,prev,size,a,b); prev[m+a][n+b] = -1; prev[size-1][size-1]= 1; } } if(valid(m+a,n-b,size)){ if(prev[m+a][n-b] != 1) { prev[m+a][n-b] = 1; p2 = knight(m+a,n-b,prev,size,a,b); prev[m+a][n-b] = -1; prev[size-1][size-1]= 1; }} if(valid(m-a,n+b,size)){ if(prev[m-a][n+b] != 1) { prev[m-a][n+b] = 1; p3 = knight(m-a,n+b,prev,size,a,b); prev[m-a][n+b] = -1; prev[size-1][size-1]= 1; } } if(valid(m-a,n-b,size)){ if(prev[m-a][n-b] != 1) { prev[m-a][n-b] = 1; p4 = knight(m-a,n-b,prev,size,a,b); prev[m-a][n-b] = -1; prev[size-1][size-1]= 1; } } if(valid(m+b,n+a,size)){ if(prev[m+b][n+a] != 1) { prev[m+b][n+a] = 1; p5 = knight(m+b,n+a,prev,size,a,b); prev[m+b][n+a] = -1; prev[size-1][size-1]= 1; }} if(valid(m+b,n-a,size)){ if(prev[m+b][n-a] != 1) { prev[m+b][n-a] = 1; p6 = knight(m+b,n-a,prev,size,a,b); prev[m+b][n-a] = -1; prev[size-1][size-1]= 1; }} if(valid(m-b,n+a,size)){ if(prev[m-b][n+a] != 1) { prev[m-b][n+a] = 1; p7 = knight(m-b,n+a,prev,size,a,b); prev[m-b][n+a] = -1; prev[size-1][size-1]= 1; } } if(valid(m-b,n-a,size)){ if(prev[m-b][n-a] != 1) { prev[m-b][n-a] = 1; p8 = knight(m-b,n-a,prev,size,a,b); prev[m-b][n-a] = -1; prev[size-1][size-1]= 1; } } return 1 + min(min(min(p1,p2),min(p3,p4)),min(min(p5,p6),min(p7,p8))); } int main(){ int n; cin >> n; // your code goes here for(int i=1;i<n;i++){ for(int j=1;j<n;j++){ vector<int> a(n,-1); vector<vector<int> > prev(n,a); prev[n-1][n-1]= 1; int ans = knight(n-1,n-1,prev,n,i,j); if(ans == 100001) ans = -1; cout<<ans<<" "; } cout<<"\n"; } return 0; }