#include using namespace std; namespace { constexpr int PRIME = 1601; constexpr int UNUSED_EDGE_WEIGHT = 300000; int snake_index(int n, int row, int column) { if (row % 2 == 0) return row * n + column; return row * n + (n - 1 - column); } int mark(int index) { return 2 * PRIME * index + index * index % PRIME; } int edge_weight(int n, int r1, int c1, int r2, int c2) { int x = snake_index(n, r1, c1); int y = snake_index(n, r2, c2); if (x > y) swap(x, y); if (y == x + 1) return mark(y) - mark(x); return UNUSED_EDGE_WEIGHT; } } // namespace int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; // Vertical edges. for (int row = 0; row + 1 < n; ++row) { for (int column = 0; column < n; ++column) { if (column) cout << ' '; cout << edge_weight(n, row, column, row + 1, column); } cout << '\n'; } // Horizontal edges. for (int row = 0; row < n; ++row) { for (int column = 0; column + 1 < n; ++column) { if (column) cout << ' '; cout << edge_weight(n, row, column, row, column + 1); } cout << '\n'; } return 0; }