#include <bits/stdc++.h>
using namespace std;
vector<long long> v(500001), f(500001), pre(500001), suff(500001);
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  map<long long, long long> m, rm;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]] = 1;
  }
  long long c = 0;
  for (auto& it : m) {
    c++;
    it.second = c;
    rm[c] = it.first;
  }
  for (long long i = 0; i < n; i++) {
    v[m[arr[i]]]++;
  }
  for (long long i = 1; i <= c; i++) {
    f[v[i]]++;
  }
  for (long long i = 1; i <= n; i++) {
    long long c = f[i] * i;
    pre[i] = pre[i - 1] + c;
  }
  for (long long i = n; i >= 1; i--) {
    suff[i] = suff[i + 1] + f[i];
  }
  long long ans = 0;
  long long r, cl;
  for (long long rows = 1; rows <= n; rows++) {
    long long lo = 0;
    long long hi = n;
    while (lo < hi) {
      long long mid = (lo + hi + 1) >> 1;
      long long threshold = min(mid, rows);
      long long tot = pre[threshold] + suff[threshold + 1] * threshold;
      if (tot >= rows * mid)
        lo = mid;
      else
        hi = mid - 1;
    }
    if (ans < rows * lo) {
      ans = rows * lo;
      r = rows;
      cl = lo;
    }
  }
  long long a = min(r, cl);
  long long b = max(r, cl);
  cout << ans << "\n" << a << " " << b << "\n";
  vector<vector<long long>> h(a, vector<long long>(b, -1));
  long long aplha = min(a, b);
  long long row = 0;
  long long col = 0;
  long long start = 0;
  for (long long i = 1; i <= c; i++) {
    if (v[i] >= min(a, b)) {
      for (long long j = 0; j < aplha; j++) {
        if (h[row][col] != -1) {
          break;
        }
        h[row][col] = i;
        row = (row + 1) % a;
        col = (col + 1) % b;
        if (row == 0) {
          start = (start + 1) % b;
          col = start;
        }
      }
    }
  }
  for (long long i = 1; i <= c; i++) {
    if (v[i] < aplha) {
      for (long long j = 0; j < v[i]; j++) {
        if (h[row][col] != -1) {
          break;
        }
        h[row][col] = i;
        row = (row + 1) % a;
        col = (col + 1) % b;
        if (row == 0) {
          start = (start + 1) % b;
          col = start;
        }
      }
    }
  }
  for (long long i = 0; i < a; i++) {
    for (long long j = 0; j < b; j++) cout << rm[h[i][j]] << " ";
    cout << "\n";
  }
  return 0;
}
