import java.io.*;
class magic
{
public static void main(String args[])throws IOException
{
int m,n,f,i,j,row,col,total=0;
int a[][]=new int[10][10];
DataInputStream ip=new DataInputStream(System.in);
System.out.println("Enter the row and col of the matrix");
m=Integer.parseInt(ip.readLine());
n=Integer.parseInt(ip.readLine());
if(m!=n)
System.out.println("matrix not possible");
if((m==n)&&(m%2==0))
System.out.println("matrix not possible");
else
{
f=m*n;
for(i=0;i {
for(j=0;j {
a[i][j]=0;
}
}
row=1;
col=(n+1)/2;
for(i=1;i<=f;i++)
{
a[row][col]=i;
if((row-1==0)&&(col-1==0))
{
row=row+1;
col=col;
continue;
}
if(a[row-1][col-1]!=0)
{
row=row+1;
col=col;
continue;
}
if(row-1==0)
row=n;
else
row=row-1;
if(col-1==0)
col=n;
else
col=col-1;
continue;
}
}

for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{


System.out.print("\t"+a[i][j]);
if(i==j)
total=total+a[i][j];
}
System.out.print("\n");

}
System.out.println("Sum of the diagonal is "+total);
}
}