#include<iostream>
using namespace std;
int main()
{
    int arr[19][19] = { 0 };
    int i = 0, j = 0, n;
    int num = 1;    //需要赋值的数
    int d = 0;    //    循环圈数
    cin>> n;
    //    循环条件
    while (num != n * n + 1 )
    {
    //    上行
        for (i = d; i < n-d && num != n * n + 1;)
            arr[d][i++] = num++;
    //    右列
            for (j = 1+d; j < n-d&&num != n * n + 1;)
                arr[j++][i - 1] = num++;
    //    下行
            for (i = n - 2-d; i >= d && num != n * n + 1;)
                arr[j - 1][i--] = num++;
    //    左列
            for (j = n - 2-d; j >= d+1 && num != n * n + 1;)
                arr[j--][d] = num++;
        d++;
    }
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
            cout << arr[i][j] << ' ';
        cout << endl;
    }
    system("pause");
    return 0;
}