#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[10];
ll n,cnt,sum=1;
bool check(ll x,ll y)
{
for(ll i=1;i<=x;i++)
{
if(a[i]==y)return false;
else if(i+a[i]==x+y)return false;
else if(i-a[i]==x-y)return false;
}
return true;
}
void print()
{
for(ll i=1;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
void dfs(ll row)
{
if(row==n+1)
{
print();
cnt++;
return;
}
for(ll j=1;j<=n;j++)
{
if(check(row,j))
{
a[row]=j;
dfs(row+1);
a[row]=0;
}
}
}
int main()
{
cin>>n;
dfs(1);
cout<<cnt;
return 0;
}