#include <iostream>
#include <vector>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int k;

void solve(int n)
{
    cout << n << "\n";
    vector<vector<int> > a(n, vector<int>(n));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            a[i][j] = (i + j) % n;
            if (i % 2) a[i][j] += n;
            if (a[i][j] >= k) a[i][j] -= n;
            a[i][j]++;
            cout << a[i][j] << " ";
        }
        cout << "\n";
    }
}

signed main()
{
    cin >> k;
    if (k == 1) cout << "1\n1", exit(0);
    for (int n = 2; n <= 500; n += 2)
    {
        if (2 * n >= k)
        {
            solve(n);
            return 0;
        }
    }
}
