#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; int r[50][50]; int main() { int n; cin >> n; int s = 1; int p = n-1; int x = 0, y = 0, d = 0; if (n == 1) { cout << "001" << endl; return 0; } while (s <= n*n) { d %= 4; for (int i = 0; i < p; i++) { if (r[y][x])break; if (d == 0)r[y][x] = s, x++; if (d == 1)r[y][x] = s, y++; if (d == 2)r[y][x] = s, x--; if (d == 3)r[y][x] = s, y--; s++; // cout << x << " " << y << endl; } if (r[y][x]) { if(d==3)y++, x++; if (d == 2)y--, x++; if (d == 1)y--, x--; if (d == 0)y++, x--; } d++; if (d == 4)p--; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j)cout << " "; if (r[i][j] < 10)cout << "00"; else if (r[i][j] < 100)cout << 0; printf("%d",r[i][j]); } cout << endl; } return 0; }