using namespace std;
long long h[10001],l[10001],z[10001],y[10001];
int n;
int total;
int pt(){
if(total<=2){
for(int k=1;k<=n;k++){
cout << h[k] << " ";
}
cout << endl;
}
total++;
}
void dfs(int i)
{
if(i>n){
pt();
return ;
}
else{
for(int j=1;j<=n;j++){
if(!l[j]&&!z[i+j]&&!y[i-j+n]){
h[i]=j;
l[j]=1;
z[i+j]=1;
y[i-j+n]=1;
dfs(i+1);
l[j]=0;
z[i+j]=0;
y[i-j+n]=0;
}
}
}
}
int main(){
cin >> n;
dfs(1);
cout << total;
return 0;
}