int main()
{
int a[50][50],n,i,j
cin>>n;
for(i=1;i<=n;i++)
for(j=1;<=n;j++)
if(i%2!=0)
a[i][j]=i+j;
else
{
if((a[i-1][j-1]<a[i-1][j])&&(a[i-1][j-1]<a[i-1][j+1]))
a[i][j]=a[i-1][j-1];
if((a[i-1][j-1]>a[i-1][j])&&(a[i-1][j]<a[i-1][j+1]))
a[i][j]=a[i-1][j];
if((a[i-1][j-1]>a[i-1][j+1])&&(a[i-1][j]>a[i-1][j+1]))
a[i][j]=a[i-1][j+1];
}
for(i=1;i<=n;i++)
{
cout<<endl;
for(j=1;<=n;j++)
cout<<a[i][j]<<" ";
}
}