#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
inline int add(int a, int b) {
  if ((a += b) >= P) a -= P;
  return a;
}
inline int sub(int a, int b) {
  if ((a -= b) < 0) a += P;
  return a;
}
inline int mul(int a, int b) { return 1ll * a * b % P; }
inline int kpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a)) {
    if (b & 1) r = mul(r, a);
  }
  return r;
}
const int N = 404040;
int n;
vector<pair<int, int> > b;
int main() {
  scanf("%d", &n);
  map<int, int> cnt;
  for (int i = (0); i < (n); i++) {
    int t;
    scanf("%d", &t);
    cnt[t]++;
  }
  b = vector<pair<int, int> >(cnt.begin(), cnt.end());
  for (int i = (0); i < ((int)b.size()); i++) swap(b[i].first, b[i].second);
  sort(b.begin(), b.end());
  int pre = 0, p = 0;
  int mxn = 0, mxm = 0;
  for (int i = (1); i < (n + 1); i++) {
    while (p < (int)b.size() && b[p].first <= i) {
      pre += b[p].first;
      p++;
    }
    int col, row;
    row = i;
    col = (pre + ((int)b.size() - p) * i) / i;
    if (col >= row && row * col > mxn * mxm) mxn = row, mxm = col;
  }
  p = (int)b.size() - 1;
  int use = 0;
  vector<int> ans(mxn * mxm, 0);
  for (int i = (0); i < (mxm); i++) {
    for (int j = (0); j < (mxn); j++) {
      b[p].first--;
      ans[j * mxm + (i + j) % mxm] = b[p].second;
      use++;
      if (b[p].first == 0 || use == mxn) {
        p--;
        use = 0;
      }
    }
  }
  printf("%d\n%d %d\n", mxn * mxm, mxn, mxm);
  for (int i = (0); i < (mxn); i++)
    for (int j = (0); j < (mxm); j++)
      printf("%d%c", ans[i * mxm + j], " \n"[j == mxm - 1]);
  return 0;
}
