#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; typedef pair cell_type; deque pending; int n; int* a; void process(cell_type& start, int x, int y) { cell_type q = { start.first + x, start.second + y}; if (q.first >= 0 && q.first = 0 && q.second < n) { if (a[q.first + n * q.second] == -1) { a[q.first + n * q.second] = a[start.first + n * start.second] + 1; pending.push_back(q); } } } int main(){ cin >> n; int nn = n*n; a = new int[nn]; int result[nn]; for (int i = 0; i < nn; ++i) { result[i] = -1; } for (int x = 1; x < n; ++x) { for (int y = x; y < n; ++y) { for (int i = 0; i < nn; ++i) { a[i] = -1; } a[0] = 0; pending.clear(); pending.push_back({0,0}); while (a[nn-1] == -1 && !pending.empty()) { cell_type p = pending.front(); pending.pop_front(); process(p, x, y); process(p, x,-y); process(p,-x, y); process(p,-x,-y); process(p, y, x); process(p, y,-x); process(p,-y, x); process(p,-y,-x); } result[x + n * y] = a[nn-1]; result[y + n * x] = a[nn-1]; } } for (int x = 1; x < n; ++x) { for (int y = 1; y < n; ++y) { cout << result[x + n * y] << ' '; } cout << '\n'; } return 0; }