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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int field[505][505];
int K;

int main() {
    //cout.precision(10);
    cin >> K;
    if(K == 1) {
        cout << "1" << endl << "1" << endl;
        return 0;
    }
    int n = ((K + 3) / 4) * 2;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            field[i][j] = (i + j) % n + 1;
            if((i % 2) == 0) field[i][j] += n;
            if(field[i][j] > K) field[i][j] -= n;
        }
    }
    cout << n << endl;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            cout << field[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
