#include "bits/stdc++.h" #pragma warning(disable : 4996) typedef long long ll; #define all(x) (x).begin(), (x).end() // sortなどの引数を省略 #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #ifdef _MSC_FULL_VER // デバッグ出力 #define dout cout #define debug() if (true) #define check(x) std::cout << "★" << #x << "の値:" << (x) << endl #define pass(x) std::cout << "☆" << x << endl #else #define dout \ if (false) \ cout #define debug() if (false) #define check(x) \ if (false) \ cout << "★" << #x << "の値:" << (x) << endl #define pass(x) \ if (false) \ cout << "☆" << x << endl #endif using namespace std; // #define int long long; double dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } ll idist(ll x1, ll y1, ll x2, ll y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } signed main() { ll n; cin >> n; ll x = 0,y = 0; ll dir = 0; vector> vv(n,vector(n,-1)); rep(i,n*n){ vv[x][y] = i+1; if(dir == 0){ x++; if(x == n-1 || vv[x+1][y] != -1){ dir = 1; } } else if(dir == 1){ y++; if(y == n-1 || vv[x][y+1] != -1){ dir = 2; } } else if(dir == 2){ x--; if(x == 0 || vv[x-1][y] != -1){ dir = 3; } } else if(dir == 3){ y--; if(y == 0 || vv[x][y-1] != -1){ dir = 0; } } } rep(i,n){ rep(j,n){ if(vv[j][i] < 10) cout << "00" << vv[j][i] << " "; else if(vv[j][i] < 100) cout << 0 << vv[j][i] << " "; else cout << vv[j][i] << " "; } cout << endl; } }