#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; int main(){ int n; cin >> n; int table[n-1][n-1]; for(int a = 1; a<n; a++) { for(int b=a; b<n; b++) { queue<int> qx; queue<int> qy; int xPot[] = {a,a,-a,-a,b,b,-b,-b}; int yPot[] = {b,-b,b,-b,a,-a,a,-a}; bool board[n][n]; memset(board, 0, sizeof(board)); board[0][0] = true; qx.push(0); qy.push(0); int steps = 0; while (!qx.empty()) { int size = qx.size(); for (int i=0; i<size; i++) { int x = qx.front(); qx.pop(); int y = qy.front(); qy.pop(); for(int j=0; j<8; j++){ int newX = x + xPot[j]; int newY = y + yPot[j]; if (newX == n-1 && newY == n-1) { table[a-1][b-1] = steps+1; table[b-1][a-1] = steps+1; goto continueOuterLoop; } if (newX>=0 && newX<n && newY>=0 && newY<n && !board[newX][newY]){ board[newX][newY] = true; qx.push(newX); qy.push(newY); } } } steps++; } table[a-1][b-1] = -1; table[b-1][a-1] = -1; continueOuterLoop:; } } for(int a = 0; a<n-1; a++) { for(int b=0; b<n-1-1; b++) { cout << table[a][b] << " "; } cout << table[a][n-2] << "\n"; } return 0; }