#include <iostream>
using namespace std;
const int N = 50;
int n;
int tt, a[N];
bool b[N], c[N], d[N];
int ans[100][10];
void dfs(int x){
if (x > n){
tt++;
for (int i = 1; i <= n; i++) ans[tt][i] = a[i];
return ;
}
for (int y = 1; y <= n; y++){
if (!b[y] && !c[x + y] && !d[x - y + n]){
a[x] = y, b[y] = c[x + y] = d[x - y + n] = 1;
dfs(x + 1);
b[y] = c[x + y] = d[x - y + n] = 0;
}
}
}
int main(){
cin >> n;
dfs(1);
for (int i = 1; i <= 3; i++) {
for (int j =1 ; j <= n; j++)
cout << ans[i][j] << ' ';
puts("");
}
cout << tt;
return 0;
}