#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=0,shuchu = 0,w;
vector<ll> hc;
ll hcsize = 0;
ll zheng(ll d){
if(d>0) return d;
return -d;
}
bool cangoto(ll z,ll h){
for(int i = 0;i < hcsize;i++) if((hc[i] == z) || zheng(i-h) == zheng(hc[i]-z)) return false;
return true;
}
ll qwq(ll hang){
if(hang == w){
if(shuchu < 3){
for(int i = 0;i < hang;i++) printf("%lld ",hc[i]+1);
printf("\n");
shuchu++;
}
return 1;
}
ll an = 0;
for(int i = 0;i < w;i++){
if(cangoto(i,hang)){
hc.push_back(i);
hcsize++;
an=an + qwq(hang+1);
hcsize--;
hc.pop_back();
}
}
return an;
}
int main(){
scanf("%lld",&w);
printf("%lld",qwq(0));
return 0;
}