#include <bits/stdc++.h>
using namespace std;

const int N = 505;

int k;
int res[N][N];
int id[2*N], cur = 1;

int get(int i){
    if(id[i] == 0) return id[i] = cur++;
    else return id[i];
}

int main(){
    cin >> k;
    if(k == 1) return !printf("1\n1\n");
    int n = (k + 1) / 2;
    if(n % 2 != 0) n++;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i % 2 == 1) res[i][j] = (i + j) % n;
            else res[i][j] = (i + j) % n + n;
        }
    }
    int cnt = 0;
    while(k < 2 * n){
        for(int i = 0; i < n; i++) res[i][(cnt-i + n) % n] = cnt;
        k++;
        cnt++;
    }
    cout << n << endl;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) cout << get(res[i][j]) << "\t";
        cout << endl;
    }
}