#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 valid(int x,int y,vector >& visited) { int n = visited.size(); return x >= 0 && x < n && y >= 0 && y < n && visited[x][y] == false; } int minmoves(int startx,int starty,int a,int b,int n) { vector >visited(n,vector(n)); for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < n ; j++) visited[i][j] = false; visited[startx][starty] = true; queue ,int> > q; q.push( make_pair(make_pair(startx,starty),0) ); int dx[] = {a,a,-1*a,-1*a,b,b,-1*b,-1*b}; int dy[] = {b,-1*b,b,-1*b,a,-1*a,a,-1*a}; while(!q.empty()) { int x,y; pair coord = q.front().first; int moves = q.front().second; x = coord.first; y = coord.second; q.pop(); if(x == n-1 && y == n-1) return moves; for(int i = 0 ; i < 8 ; i++) if( valid(x+dx[i],y+dy[i],visited) ) { visited[x+dx[i]][y+dy[i]] = true; q.push( make_pair(make_pair(x+dx[i],y+dy[i]),moves+1) ); } } return -1; } int main() { int n; cin >> n; for(int i = 1 ; i <= n-1 ; i++) { for(int j = 1 ; j <= n-1 ; j++) cout << minmoves(0,0,i,j,n) << " "; cout << "\n"; } return 0; }