#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[4][31];
int m[17];
int n;
int num=0;
void dfs(int cur){
if(cur==n+1){
num++;
if(num<=3){
for(int j=1; j<=n; j++){
cout<<m[j]<<" ";
}
}
cout<<endl;
return;
}
else {
for(int i=1; i<=n; i++){
if(!a[1][i]&&!a[2][i+cur]&&!a[3][cur-i+n]){
a[1][i]=1;
a[2][i+cur]=1;
a[3][cur-i+n]=1;
m[cur]=i;
dfs(cur+1);
}
a[1][i]=0;
a[2][i+cur]=0;
a[3][cur-i+n]=0;
}
}
}
int main(){
memset(a,0,sizeof(a));
memset(m,0,sizeof(m));
cin>>n;
dfs(1);
cout<<num;
return 0;
}