// Arup Guha
// 6/23/2016
// Program that generates a magic square of odd size.

import java.util.*;

public class MagicSquareGenerator {

	public static void main(String[] args) {

		// Get the user input.
    	Scanner input = new Scanner(System.in);
    	System.out.println("How many rows do you want in your Magic square(odd ints only)?");
    	int n = input.nextInt();

		// Set up our square and starting position (top middle).
    	int[][] square = new int[n][n];
    	int r = 0, c = n/2;

    	// Fill in each number, from 1 to n*n...
    	for (int i=1; i<=n*n; i++) {

			// We put i in te current square.
    		square[r][c] = i;

			// Default movement is up and to the right.
    		r--;
    		c++;

    		// This is the case where either where we went is filled in or off the top right corner.
    		if ( (r<0 && c>=n) || (r>=0 && r<n && c>=0 && c<n && square[r][c] != 0) ) {

    			// We must go back to the old square (c--,r++) and drop down one (r++)
    			r+=2;
    			c--;
    		}

    		// We go off the top of the grid, so wrap around to the bottom.
    		else if (r < 0) r += n;

    		// We go off the right of the grid, so wrap around to the left.
    		else if (c >= n) c -=n;
    	}

		// Print our square.
    	for (int i=0; i<n; i++) {
    		for (int j=0; j<n; j++)
    			System.out.print(square[i][j]+"\t");
    		System.out.println();
    	}
	}
}