#include <iostream>
using namespace std;
#include <iomanip>
const int MAX = 1000;
int board[MAX][MAX] = {0, };
int N;
void PrintBoard()
{
int digit = 0;
int temp = N*N;
while (temp > 0)
{
temp /= 10;
digit++;
}
for (int i = 0; i < N; i++)
{
cout << endl;
for (int j = 0; j < N; j++)
cout << setfill('0') << setw(digit) << board[i][j] << " ";
}
cout << endl;
}
enum DIR {RIGHT, DOWN, LEFT, UP};
bool CanGo(int y, int x)
{
if (y < 0 || y >= N)
return false;
if (x < 0 || x >= N)
return false;
if (board[y][x] != 0)
return false;
return true;
}
void MakeBoard()
{
int dir = RIGHT;
int x = 0;
int y = 0;
int num = 1;
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};
int nextY;
int nextX;
while (true)
{
board[y][x] = num;
if (num == N * N)
break;
nextY = y + dy[dir];
nextX = x + dx[dir];
if (CanGo(nextY, nextX))
{
y = nextY;
x = nextX;
num++;
}
else
{
dir = (dir + 1) % 4;
}
}
}
int main()
{
cin >> N;
MakeBoard();
PrintBoard();
return 0;
}