#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e6+5;
struct node{
int x;
int y;
}va[N];
int n;
int res = 0,sum = 0;
bool check(int x,int y)
{
for(int i = 1;i<=x-1;i++)
{
if(va[i].y==y) return false;
}
for(int i =1;i<=x-1;i++)
{
if(abs(y-va[i].y)==abs(x-va[i].x)) return false;
}
return true;
}
void dfs(int now)
{
if(now==n+1)
{
if(res<3)
{
res++;
for(int i = 1;i<=n;i++) cout<<va[i].y<<" ";
cout<<"\n";
}
sum++;
return;
}
for(int j= 1;j<=n;j++)
{
if(check(now,j)==1)
{
va[now] = {now,j};
dfs(now+1);
}
}
}
int main()
{
IOS;
cin>>n;
dfs(1);
cout<<sum;
}