#include <bits/stdc++.h>
using namespace std;
int st[25], n;
int viz[25], dp[50], ds[50];
int C;
ifstream fin ("damesah.in");
ofstream fout ("damesah.out");
void Print()
{
C++;
if(C == 1)
{
for(int i = 1; i <= n; i++)
fout << st[i] << " ";
fout << "\n";
}
}
inline int Check(int i, int j)
{
if(viz[j] == 1) return 0;
if(dp[n - j + i] == 1) return 0;
if(ds[j + i - 1] == 1) return 0;
return 1;
}
void Back(int top)
{
if(top == n + 1) Print();
else for(int j = 1; j <= n; j++)
if(Check(top, j) )
{
st[top] = j;
viz[j] = 1;
dp[n - j + top] = 1;
ds[j + top - 1] = 1;
Back(top + 1);
viz[j] = 0;
dp[n - j + top] = 0;
ds[j + top - 1] = 0;
}
}
int main()
{
fin >> n;
Back(1);
fout << C;
return 0;
}