#include<bits/stdc++.h>
using namespace std;
int n;
int a[15]={0};
int tot=0;
void dfs(int cur){
if(cur==n+1){
tot++;
if(tot<=3){
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
}
else{
for(int i=1;i<=n;i++){
bool ok=1;
a[cur]=i;
for(int j=1;j<cur;j++){
if(a[cur]==a[j]||cur-a[cur]==j-a[j]||cur+a[cur]==j+a[j]){
ok=0;
break;
}
}
if(ok)
dfs(cur+1);
}
}
}
int main(){
cin>>n;
dfs(1);
cout<<tot;
}
TEL