#include <iostream>
#include <iomanip>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cstring>
#include <map>
#include <cmath>
#include <queue>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N 1010
#define ll long long
#define mx INT_MAX
using namespace std;
struct moxi
{
string s;
}ans[20];
int n;
int mapp[20][20];
int inndex;
bool cmp(moxi a,moxi b)
{
return a.s<b.s;
}
void dfs(int y,int dep)
{
if(dep==n)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(mapp[i][j]==1) ans[inndex].s+=to_string(j+1)+" ";
}
}
inndex++;
return ;
}
for(int i=1;i<=n;i++)
{
if(mapp[i][y]==0)
{
for(int j=1;j<=n;j++) mapp[i][j]=1;
for(int j=1;j<=n;j++) mapp[j][y]=1;
int k=n-max(i,y);
for(int j=1;j<=k;j++) mapp[i+j][k+j]=1;
for(int j=1;j<=k;j++) mapp[i-j][k+j]=1;
dfs(y+1,dep+1);
for(int j=1;j<=n;j++) mapp[i][j]=0;
for(int j=1;j<=n;j++) mapp[j][y]=0;
for(int j=1;j<=k;j++) mapp[i+j][k+j]=0;
for(int j=1;j<=k;j++) mapp[i-j][k+j]=0;
}
}
}
int main()
{
IOS
int t=1;
while(t--)
{
cin>>n;
dfs(1,0);
sort(ans,ans+inndex,cmp);
for(int i=0;i<min(3,inndex);i++)
cout<<ans[i].s<<endl;
cout<<inndex<<endl;
}
return 0;
}