#include <stdio.h>
int main(int argc, char *argv[])
{int a,d,j,i,n,t,r[100][100],ans=0;
scanf("%d",&n);
a=1;
j=1;
d=n;
t=n*n;
do
{
for (j=d;j>=a;j--)
{
r[d][j]=t--;
}
for (i=(d-1);i>=a;i--)
{
r[i][a]=t--;
}
for (j=a+1;j<=(n-a);j++)
{
r[a][j]=t--;
}
for (i=a;i<=d-1;i++)
{
r[i][d]=t--;
}
a=a+1;
d=d-1;
}while (a!=n-1);
if (n==3) r[2][2]=1 ;
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%4d
",r[i][j]);
printf("\n");
}
for (i=1;i<=n;i++)
{
ans+=r[i][i];
ans+=r[n+1-i][i];
}
printf("%d",ans-1);
}