#include using namespace std; int n, st[3], afisari; struct point{ int x, y; }; void find_solution(int a, int b) { int dx[8] = {-a, -a, a, a, -b, -b, b, b}; int dy[8] = {-b, b, -b, b, -a, a, -a, a}; point q[625]; int p, u, m[25][25]; for (int i = 0; i < 25; ++i) for (int j = 0; j < 25; ++j) m[i][j] = 0; m[0][0] = 1; p = 1; u = 1; while(p <= u) { for (int k = 0; k < 8; ++k) { int x = q[p].x + dx[k]; int y = q[p].y + dy[k]; if (x >= 0 && x < n && y >= 0 && y < n) { if (m[x][y] == 0) { u++; q[u].x = x; q[u].y = y; m[x][y] = m[q[p].x][q[p].y] + 1; } } } p++; } cout << m[n-1][n-1] - 1 << " "; afisari++; if (afisari == (n - 1)) cout << "\n"; afisari %= n - 1; } void generate_pairs(int k, int n) { for (int i = 1; i < n; ++i) { st[k] = i; if (k == 2) { find_solution(st[1], st[2]); } else { generate_pairs(k + 1, n); } } } int main(){ cin >> n; generate_pairs(1, n); return 0; }