#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e3+5;
int k, n, a[N][N];
int main()
{
    k = read(), n = min(k, 500), k -= n;
    for(int i = 1, j = 0; i <= n; ++i)
    {   
        int u = ++j, v = k>0?++j:j; --k;
        for(int x = 1, y = i; x <= n; ++x, y = y%n+1)
            a[x][y] = x&1?u:v;
    }
    printf("%d\n", n);
    for(int i = 1; i <= n; ++i, puts(""))
        for(int j = 1; j <= n; ++j)
            printf("%d ", a[i][j]);
    return 0;
}