#include <cstdio>

int n, k;

int main() {
  scanf("%d", &k);
  if (k == 1) {
    printf("1\n1\n");
    return 0;
  }
  n = ((k - 1) / 4 + 1) * 2;
  printf("%d\n", n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int c = (i + j) % n;
      if ((i & 1) && c + n < k) {
        c += n;
      }
      printf("%d%c", c + 1, " \n"[j == n - 1]);
    }
  }
  return 0;
}
