// Arup Guha
// 7/30/2026
// Solution to 1989 UCF HS Programming Contest Problem: Round and Round

import java.util.*;

public class spiral {

	// We'll do (2N+1) by (2N+1) and recenter.
	final public static int N = 20;
	
	// Order of spiral.
	final public static int[] DR = {1,0,-1,0};
	final public static int[] DC = {0,1,0,-1};
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		
		while (stdin.hasNext()) {
			
			// Get number of values.
			int numV = stdin.nextInt();
			
			// Grid.
			int[][] g = new int[2*N+1][2*N+1];
			
			// (x,y) is where we are, d is direction, limit is how
			// many times we want to go in this direction, curSameD
			// is how many times I've gone in this direction so far.
			int x = N, y = N, curSameD = 0, limit = 1, d = 0;
			boolean increment = false;
			
			// Fill in values.
			for (int i=1; i<=numV; i++) {
				
				// Fill it.
				g[x][y] = i;
				
				// Time to change direction.
				if (curSameD == limit) {
					
					// New direction.
					d = (d+1)%DR.length;
					
					// This happens every other time.
					if (increment) limit++;
					
					// This always flips.
					increment = !increment;
					
					// This resets.
					curSameD = 1;
				}
				
				// same direction, less to do.
				else
					curSameD++;
				
				// Go to next square.
				x += DR[d];
				y += DC[d];
			}
			
			// Print the grid.
			print(g);
			
			// Since I am doing data, we're just going to do a blank line after
			// every case, not between cases!!!
			System.out.println();
		}
	}
	
	// Will change...their output format sucks.
	public static void print(int[][] g) {
		
		// Annoying but we have to do this...
		int minR = 2*N, maxR = 0, minC = 2*N, maxC = 0;
		for (int i=0; i<g.length; i++) {
			for (int j=0; j<g[i].length; j++) {
				if (g[i][j] != 0) {
					minR = Math.min(minR, i);
					maxR = Math.max(maxR, i);
					minC = Math.min(minC, j);
					maxC = Math.max(maxC, j);
				}
			}
		}
		
		// Only go through required rows and columns.
		for (int i=minR; i<=maxR; i++) {
			for (int j=minC; j<=maxC; j++) {
				
				// Even then we have to do something like this.
				if (g[i][j] != 0)
					System.out.printf("%-6d",g[i][j]);
				else
					System.out.printf("      ");
			}
			
			// Go to the next line.
			System.out.println();
		}
	}
}