#include <iostream> using namespace std; int a[21][21]; int n; int main() { cin >> n; int x = 0, y = 0; a[x][y] = 1; for (int k = 2; k <= n * n; ) { while (true) { int nx = x, ny = y + 1; if (nx < 0 nx >= n ny < 0 ny >= n a[nx][ny]) { break; } a[x = nx][y = ny] = k++; } while (true) { int nx = x + 1, ny = y; if (nx < 0 nx >= n ny < 0 ny >= n a[nx][ny]) { break; } a[x = nx][y = ny] = k++; } while (true) { int nx = x, ny = y - 1; if (nx < 0 nx >= n ny < 0 ny >= n a[nx][ny]) { break; } a[x = nx][y = ny] = k++; } while (true) { int nx = x - 1, ny = y; if (nx < 0 nx >= n ny < 0 ny >= n a[nx][ny]) { break; } a[x = nx][y = ny] = k++; } } for (int ii = 0; ii < n; ii++) { for (int jj = 0; jj < n; jj++) { cout << a[ii][jj] << " "; } cout << endl; } return 0; }