1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 903 - Spiral of Numbers
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=844
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
* @version 1.0 19.04.2009
*
* Status : Accepted
* Runtime: 2.090
*/

import java.util.*;

public class SpiralOfNumbers
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

while(sc.hasNext())
{
int index = sc.nextInt();

switch(index)
{
case 1:
{
System.out.println((7)+";"+(8)+";"+(9)+";");
System.out.println((6)+";"+(1)+";"+(2)+";");
System.out.println((5)+";"+(4)+";"+(3)+";");
break;
}
case 2:
{
System.out.println((8)+";"+(9)+";"+(10)+";");
System.out.println((1)+";"+(2)+";"+(11)+";");
System.out.println((4)+";"+(3)+";"+(12)+";");
break;
}
case 3:
{
System.out.println((1)+";"+(2)+";"+(11)+";");
System.out.println((4)+";"+(3)+";"+(12)+";");
System.out.println((15)+";"+(14)+";"+(13)+";");
break;
}
case 4:
{
System.out.println((6)+";"+(1)+";"+(2)+";");
System.out.println((5)+";"+(4)+";"+(3)+";");
System.out.println((16)+";"+(15)+";"+(14)+";");
break;
}
case 5:
{
System.out.println((19)+";"+(6)+";"+(1)+";");
System.out.println((18)+";"+(5)+";"+(4)+";");
System.out.println((17)+";"+(16)+";"+(15)+";");
break;
}
case 6:
{
System.out.println((20)+";"+(7)+";"+(8)+";");
System.out.println((19)+";"+(6)+";"+(1)+";");
System.out.println((18)+";"+(5)+";"+(4)+";");
break;
}
}
if(index <= 6) continue;

int start = 3;

int differenz = 0;

int isEven = 0;


// Auffinden des Startindexes
int i = 0;
for(i = 2; start < index; i++)
{
start += 2*i;
}


i -= 1;

// start is momentan größer als index...

differenz = start - index;

isEven = i%2;

/**********************************
* HÄSSLICH UND SEHR EFFIZIENT!! *
* HÄSSLICH UND SEHR EFFIZIENT!! *
**********************************/

switch(isEven)
{
case 0:
{
if(differenz == 0)
{
//genau links oben (Algorithmus funktioniert!)
System.out.println((index+4*i+6)+";"+(index+4*i+7)+";"+(index+4*i+8)+";");
System.out.println((index+4*i+5)+";"+(index)+";"+(index+1)+";");
System.out.println((index+4*i+4)+";"+(index-1)+";"+(index-4*i+2)+";");
break;
}
if(differenz == 1)
{
// Algorithmus funktioniert
System.out.println((index+4*i+6)+";"+(index+1)+";"+(index+2)+";");
System.out.println((index+4*i+5)+";"+(index)+";"+(index-4*i+3)+";");
System.out.println((index+4*i+4)+";"+(index-1)+";"+(index-4*i+2)+";");
break;
}

if(differenz > 1 && differenz < i-1)
{
// Algorithmus funktioniert
System.out.println((index+4*i+6)+";"+(index+1)+";"+(index-4*i+4)+";");
System.out.println((index+4*i+5)+";"+(index)+";"+(index-4*i+3)+";");
System.out.println((index+4*i+4)+";"+(index-1)+";"+(index-4*i+2)+";");
break;
}
if(differenz == i-1)
{
// Algorithmus funktioniert
System.out.println((index+4*i+6)+";"+(index+1)+";"+(index-4*i+4)+";");
System.out.println((index+4*i+5)+";"+(index)+";"+(index-4*i+3)+";");
System.out.println((index+4*i+4)+";"+(index-1)+";"+(index-2)+";");
break;
}

if(differenz == i)
{
System.out.println((index+4*i+6)+";"+(index+1)+";"+(index-4*i+4)+";");
System.out.println((index+4*i+5)+";"+(index)+";"+(index-1)+";");
System.out.println((index+4*i+4)+";"+(index+4*i+3)+";"+(index+4*i+2)+";");
break;
}

if(differenz == i+1)
{
System.out.println((index+2)+";"+(index-4*i+5)+";"+(index-4*i+4)+";");
System.out.println((index+1)+";"+(index)+";"+(index-1)+";");
System.out.println((index+4*i+4)+";"+(index+4*i+3)+";"+(index+4*i+2)+";");
break;
}

if(differenz > i && differenz <2*i-1)
{
System.out.println((index-4*i+6)+";"+(index-4*i+5)+";"+(index-4*i+4)+";");
System.out.println((index+1)+";"+(index)+";"+(index-1)+";");
System.out.println((index+4*i+4)+";"+(index+4*i+3)+";"+(index+4*i+2)+";");
break;
}

if(differenz == 2*i-1)
{
System.out.println((index-4*i+6)+";"+(index-4*i+5)+";"+(index-2)+";");
System.out.println((index+1)+";"+(index)+";"+(index-1)+";");
System.out.println((index+4*i+4)+";"+(index+4*i+3)+";"+(index+4*i+2)+";");
break;
}
}
default:
{
if(differenz == 0)
{
//genau rechts unten (Algorithmus funktioniert!)
System.out.println((index-4*i+2)+";"+(index-1)+";"+(index+4*i+4)+";");
System.out.println((index+1)+";"+(index)+";"+(index+4*i+5)+";");
System.out.println((index+4*i+8)+";"+(index+4*i+7)+";"+(index+4*i+6)+";");
break;
}

if(differenz == 1)
{

System.out.println((index-4*i+2)+";"+(index-1)+";"+(index+4*i+4)+";");
System.out.println((index-4*i+3)+";"+(index)+";"+(index+4*i+5)+";");
System.out.println((index+2)+";"+(index+1)+";"+(index+4*i+6)+";");
break;
}

if(differenz > 1 && differenz < i-1)
{
// Algorithmus funktioniert
System.out.println((index-4*i+2)+";"+(index-1)+";"+(index+4*i+4)+";");
System.out.println((index-4*i+3)+";"+(index)+";"+(index+4*i+5)+";");
System.out.println((index-4*i+4)+";"+(index+1)+";"+(index+4*i+6)+";");
break;
}

if(differenz == i-1)
{
// Algorithmus funktioniert
System.out.println((index-2)+";"+(index-1)+";"+(index+4*i+4)+";");
System.out.println((index-4*i+3)+";"+(index)+";"+(index+4*i+5)+";");
System.out.println((index-4*i+4)+";"+(index+1)+";"+(index+4*i+6)+";");
break;
}

if(differenz == i)
{
System.out.println((index+4*i+2)+";"+(index+4*i+3)+";"+(index+4*i+4)+";");
System.out.println((index-1)+";"+(index)+";"+(index+4*i+5)+";");
System.out.println((index-4*i+4)+";"+(index+1)+";"+(index+4*i+6)+";");
break;
}

if(differenz == i+1)
{
System.out.println((index+4*i+2)+";"+(index+4*i+3)+";"+(index+4*i+4)+";");
System.out.println((index-1)+";"+(index)+";"+(index+1)+";");
System.out.println((index-4*i+4)+";"+(index-4*i+5)+";"+(index+2)+";");
break;
}

if(differenz > i && differenz <2*i-1)
{
System.out.println((index+4*i+2)+";"+(index+4*i+3)+";"+(index+4*i+4)+";");
System.out.println((index-1)+";"+(index)+";"+(index+1)+";");
System.out.println((index-4*i+4)+";"+(index-4*i+5)+";"+(index-4*i+6)+";");
break;
}

if(differenz == 2*i-1)
{
// stimmt
System.out.println((index+4*i+2)+";"+(index+4*i+3)+";"+(index+4*i+4)+";");
System.out.println((index-1)+";"+(index)+";"+(index+1)+";");
System.out.println((index-2)+";"+(index-4*i+5)+";"+(index-4*i+6)+";");
break;

}
}

}
}
}
}