#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int N, M = 500, K; cin >> K;
  N = min(M, K);
  cout << N << endl;;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int num = (i + j) % N;
      if ((K > M) && (num < K-M) && !(i & 1)) num += M;
      cout << num + 1 << " \n"[j==N-1];
    }
  }
  return 0;
}
