#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--) using namespace std; using ll = long long; int main() { int n; cin >> n; vector> ans(n, vector(n, -1)); int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int y[] = {0, n - 1, 0, n - 1}; int x[] = {0, n - 1, n - 1, 0}; for (int i = 0; i < n * n; i++) { int j = i % 4; ans[y[j]][x[j]] = i; int ny = y[j] + dy[j]; int nx = x[j] + dx[j]; if (ans[ny][nx] != -1) { int ty = dy[j]; int tx = dx[j]; dy[j] = tx; dx[j] = -ty; } y[j] += dy[j]; x[j] += dx[j]; } rep(i, n) { rep(j, n) { cout << ans[i][j]+1 << ' '; } cout << '\n'; } }