/**
 *    author:  tourist
 *    created: 17.10.2022 00:01:00       
**/
#undef _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  mt19937 rng(58);
  int n;
  cin >> n;
  const int k = 120;
  while (true) {
    vector<vector<int>> a(n);
    int ptr = 0;
    for (int rep = 0; rep < k / 2; rep++) {
      vector<int> b(n);
      iota(b.begin(), b.end(), 0);
      shuffle(b.begin(), b.end(), rng);
      for (int x : b) {
        a[x].push_back(ptr++);
      }
      reverse(b.begin(), b.end());
      for (int x : b) {
        a[x].push_back(ptr++);
      }
    }
    vector<pair<int, int>> all;
    for (int i = 0; i < n; i++) {
      for (int x : a[i]) {
        all.emplace_back(x, i);
      }
    }
    sort(all.begin(), all.end());
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    vector<long long> counts;
    do {
      vector<long long> dp(n + 1);
      dp[0] = 1;
      for (auto& p : all) {
        int i = p.second;
        for (int j = 0; j < n; j++) {
          if (order[j] == i) {
            dp[j + 1] += dp[j];
          }
        }
      }
      counts.push_back(dp[n]);
    } while (next_permutation(order.begin(), order.end()));
    sort(counts.begin(), counts.end());
    double ratio = (double) (counts.back() - counts[0]) / (double) counts.back();
    if (ratio <= 0.002) {
      debug(ratio);
      cout << k << '\n';
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < k; j++) {
          cout << a[i][j] + 1 << " \n"[j == k - 1];
        }
      }
      break;
    }
  }
  return 0;
}
