#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int matrix[19][19] = {0}; // 最大 n=19
int num = 1;
int top = 0, bottom = n - 1, left = 0, right = n - 1;
while (top <= bottom && left <= right) {
// 从左到右填充上边
for (int i = left; i <= right; i++) {
matrix[top][i] = num++;
}
top++;
// 从上到下填充右边
for (int i = top; i <= bottom; i++) {
matrix[i][right] = num++;
}
right--;
// 从右到左填充下边
if (top <= bottom) {
for (int i = right; i >= left; i--) {
matrix[bottom][i] = num++;
}
bottom--;
}
// 从下到上填充左边
if (left <= right) {
for (int i = bottom; i >= top; i--) {
matrix[i][left] = num++;
}
left++;
}
}
// 输出矩阵
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d", matrix[i][j]);
if (j < n - 1) printf(" ");
}
printf("\n");
}
return 0;
}