#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; int main(){ int n; cin >> n; vector vs; FOR(i,0,n) { string s = ""; FOR(j,0,n) { s += "000 "; } vs.push_back(s); } int y = 0, x = 0, num = 1; int d = 0; FOR(i,0,n*n) { int _num = num; FOR(j,0,3) { vs[y][x*4+2-j] = char('0' + _num % 10); _num /= 10; } num++; int nextx = x, nexty = y; if(d%4==0) nextx++; if(d%4==1) nexty++; if(d%4==2) nextx--; if(d%4==3) nexty--; bool notzeros = true; if(nextx < 0 || nextx >= n || nexty < 0 || nexty >= n) d++; else { FOR(j,0,3) { if(vs[nexty][nextx*4+2-j] != '0') notzeros = false; } } if(!notzeros) d++; if(d%4==0) x++; if(d%4==1) y++; if(d%4==2) x--; if(d%4==3) y--; } FOR(i,0,n){ cout << vs[i] << endl; } return 0; }