#include <iostream>
using namespace std;
void Select(int **pos, int n, int num);
int main (){
int num; //皇后数
cin >> num;
int **pos; //皇后摆放矩阵
pos = new int *[num];
for(int i =0; i<num; i++){
pos[i] = new int [num];
for(int j =0; j<num; j++)
pos[i][j]= 0;
}
Select(pos,1,num);
}
void Select(int **pos, int n, int num){
if(n<=num){
for(int i = 0; i<num; i++){ //每一行进行遍历
bool flag = false;
for(int j = 1; j<n; j++){
if(pos[n-1-j][i] || ((i-j>=0)&&(pos[n-1-j][i-j])) || (i+j<num)&&(pos[n-1-j][i+j])){ //回溯条件,判断同一列 ||左上方 ||右上方
flag = true;
break;
}
}
if(!flag && n==num){ //最后一行输出结果
pos[n-1][i] = 1;
for(int i = 0; i<num; i++){
for(int j = 0; j<num; j++){
cout << pos[i][j] << " ";
}
cout <<endl;
}
cout <<endl;
pos[n-1][i] = 0;
return;
}
if(!flag && n<num){ //无冲突判断下一皇后
pos[n-1][i] = 1;
Select(pos,n+1,num);
pos[n-1][i] = 0;
}
}
}