#include<iostream>
using namespace std;
int a[1024][1024];
void Table(int n){
if(n == 2){
a[0][0] = 1; a[0][1] = 2;
a[1][0] = 2; a[1][1] = 1;
return ;
}else{
Table(n / 2);
}
//左下方
for(int i = n / 2; i < n; i++){
for(int j = 0; j < n / 2; j++)
a[i][j] = a[i - n / 2][j] + n / 2;
}
//右上方
for(int i = 0; i < n / 2; i++){
for(int j = n / 2; j < n; j++)
a[i][j] = a[i + n / 2][j - n / 2];
}
//右下方
for(int i = n / 2; i < n; i++){
for(int j = n / 2; j < n; j++)
a[i][j] = a[i - n / 2][j - n /2];
}
}
int main(){
int n;
cout << "Please input the number of competitors:" << endl;
cin >> n;
Table(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
printf("%2d ", a[i][j]);
}
printf("\n");
}
}