#include using namespace std; #include using namespace atcoder; using ll = long long; using mint = modint1000000007; int main() { int N; cin >> N; using P = pair; vector

seq; for(int n = N; n >= 2; n -= 2) { const int p = N - n + 1; seq.push_back(P{p, p}); seq.push_back(P{p + 1, p}); for(int r = p + 2; r <= N; r++) { seq.push_back(P{r, p + 1}); seq.push_back(P{r, p}); } for(int c = N; c >= p + 1; c--) { seq.push_back(P{p, c}); seq.push_back(P{p + 1, c}); } } if(N % 2 == 1) { seq.push_back(P{N, N}); } const int K = N * N; vector ans(N, vector(N)); for(int i = 0; i < K; i++) { auto [r, c] = seq[i]; ans[r - 1][c - 1] = i + 1; } for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { cout << ans[i][j] << " \n"[j == N - 1]; } } }