题目
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#define ll long long
#define ing int
#define gets(S) fgets(S,sizeof(S),stdin)
#define ot cout
#define in cin
using namespace std;
ing n;
ing a[30];
ing b[30];
ing c[30];
ing d[30];
ing ans;
void dfs(ing i) {
if (i == n + 1) {
ans++;
if (ans <= 3) {
for (int i = 1; i <= n; i++) {
cout << a[i] << " ";
}
cout << endl;
}
return;
}
for (ing j = 1; j <= n; j++) {
if (!b[j] && !c[i - j + n] && !d[i + j]) {
a[i] = j;
b[j] = 1;
c[i - j + n] = 1;
d[i + j] = 1;
dfs(i + 1);
b[j] = 0;
c[i - j + n] = 0;
d[i - j ] = 0;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
in >> n;
dfs(1);
cout << ans;
return 0;
}