#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long MOD = 1e9 + 7;
long long mpow(long long a, long long b) {
  if (b >= (MOD - 1)) b %= (MOD - 1);
  if (b == 0) return 1;
  long long t1 = mpow(a, b / 2);
  t1 *= t1;
  t1 %= MOD;
  if (b % 2) t1 *= a;
  t1 %= MOD;
  return t1;
}
long long mpow(long long a, long long b, long long p) {
  if (b == 0) return 1;
  long long t1 = mpow(a, b / 2, p);
  t1 *= t1;
  t1 %= p;
  if (b % 2) t1 *= a;
  t1 %= p;
  return t1;
}
long long modinverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long range(long long l, long long r) { return l + rand() % (r - l + 1); }
long long n;
long long m, r, c;
vector<pair<long long, long long> > vec;
vector<long long> pr;
long long check(long long v) {
  long long l1 = 0, r1 = ((long long)(vec).size());
  while (l1 != r1) {
    long long mid = (l1 + r1) / 2;
    if (vec[mid].first < v)
      l1 = mid + 1;
    else
      r1 = mid;
  }
  long long am = (((long long)(vec).size()) - l1) * v + (l1 ? pr[l1 - 1] : 0);
  return am;
}
void solve() {
  cin >> n;
  map<long long, long long> m1;
  for (long long i = 0; i < n; i++) {
    long long t;
    cin >> t;
    m1[t]++;
  }
  for (auto it : m1) {
    vec.push_back(make_pair(it.second, it.first));
  }
  sort((vec).begin(), (vec).end());
  long long pre = 0;
  for (long long i = 0; i < ((long long)(vec).size()); i++) {
    pre += vec[i].first;
    pr.push_back(pre);
  }
  for (int i = 1; i < n + 1; i++) {
    long long l = 0, r1 = i;
    while (l != r1) {
      long long mid = (l + r1 + 1) / 2;
      if (check(mid) >= i * mid)
        l = mid;
      else
        r1 = mid - 1;
    }
    if (i * l > m) {
      m = i * l;
      r = i;
      c = l;
    }
  }
  for (long long i = 0; i < ((long long)(vec).size()); i++)
    vec[i] = make_pair(min(c, vec[i].first), vec[i].second);
  cout << m << "\n";
  cout << r << " " << c << "\n";
  long long a[r][c];
  long long cr = 0, cc = 0;
  long long ci = ((long long)(vec).size()) - 1;
  while (1) {
    a[cr][cc] = vec[ci].second;
    vec[ci].first--;
    if (vec[ci].first == 0) ci--;
    if (cc == c - 1) {
      cr = (cr - cc + 1 + r) % r;
      cc = 0;
    } else {
      cr++;
      cc++;
      cr %= r;
    }
    if (cc == 0 && cr == 0) break;
  }
  for (long long i = 0; i < r; i++) {
    for (long long j = 0; j < c; j++) cout << a[i][j] << " ";
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
