#include using namespace std; int N; int dx[] = { 1, 0, - 1, 0 }; int dy[] = { 0, 1, 0, - 1 }; int A[ 35 ][ 35 ]; int Line( int &X, int &Y, int iNum, int D ) { int x, y; x = X; y = Y; while( true ) { x += dx[ D ]; y += dy[ D ]; if( x < 1 || x > N ) return iNum; if( y < 1 || y > N ) return iNum; if( A[ y ][ x ] != 0 ) return iNum; iNum++; A[ y ][ x ] = iNum; X = x; Y = y; } } int main() { int i; int j; int iNum; int D; int X; int Y; cin >> N; iNum = 1; A[ 1 ][ 1 ] = iNum; D = 0; X = 1; Y = 1; while( true ) { i = Line( X, Y, iNum, D ); if( iNum == i ) break; iNum = i; D++; if( D >= 4 ) D = 0; } for( i = 1; i <= N; i++ ) { printf( "%03d", A[ i ][ 1 ] ); for( j = 2; j <= N; j++ ) printf( " %03d", A[ i ][ j ] ); printf( "\n" ); } return 0; }