#include <iostream>
#include <cmath>
using namespace std;
int N;
int queenPos[100];
//用来储存皇后的位置,最左上角是(0,0)
void NQueen(int k);
int main()
{
cin >> N;
NQueen(0); //从第0行开始摆皇后
return 0;
}
// 让我自己实现一下
void NQueen(int k){
int i;
if (k == N){
for (i = 0;i < N;i ++)
cout << queenPos[i] + 1 << " ";
cout << endl;
return;
}
for (i = 0;i < N;i ++){
int j;
for (j = 0;j < k;j ++){
if (queenPos[j] == i ||
abs(queenPos[j] - i) == abs(k-j)){
break;
}
}
if (j == k){
queenPos[k] = i;
NQueen(k+1);
}
}
}