#include<bits/stdc++.h>
using namespace std;
ifstream fi("NCONHAU.inp");
ofstream fo("NCONHAU.out");
int cnt=0,a[100],n;

int xuat() {
   int i;
   cnt++; fo<<cnt<<endl;
   for (i=1; i<=n;i++){
   for(int j=1;j<=n;++j){
        if(j!=a[i])fo<<' '<<0;
        else fo<<' '<<i;
   }
    fo<<endl;
   }
}

int ucv(int x ,int y){//x-cot, y-dong
   for(int i=1;i<y;++i)if( x==a[i] ||  abs(x-a[i]) == abs(y-i) )return 0;
   return 1;
}

int q(int x){
    for(int i=1;i<=n;++i){
        if(ucv(i,x)){
            a[x]=i;
        if(x==n)xuat();
        else q(x+1);
    }
}

}

int main(){
  fi>>n;
  q(1);
}
