#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
const int inf = 1e9;
const int mod = 1000000007;
map<int, int> Map;
multiset<int> Set;
int a[N], n, back[N], s[N];
pair<int, int> f[N];
vector<vector<int> > A;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int cnt = 0;
  for (int i = (0), iE = (n); i < iE; i++) {
    cin >> a[i];
    if (!Map.count(a[i])) {
      Map[a[i]] = ++cnt;
      back[cnt] = a[i];
    }
    a[i] = Map[a[i]];
    f[a[i]].second = a[i];
    f[a[i]].first++;
  }
  Map = map<int, int>();
  sort(f, f + n + 1, greater<pair<int, int> >());
  s[0] = f[0].first;
  for (int i = (1), iE = (n + 1); i < iE; i++)
    s[i] = f[i].first, s[i] += s[i - 1];
  int p = 0, ans = 0, ansp, ansi;
  for (int i = (n + 1) - 1, iE = (1); i >= iE; i--) {
    while (f[p].first > i) p++;
    int sum;
    if (p == 0)
      sum = n;
    else
      sum = p * i + n - s[p - 1];
    if ((sum / i) < i) continue;
    if ((sum / i) * i > ans) {
      ans = (sum / i) * i;
      ansp = p;
      ansi = i;
    }
  }
  int i = ansi;
  p = ansp;
  int j = ans / i;
  int x = 0, y = 0;
  A.resize(i);
  for (int ii = (0), iE = (i); ii < iE; ii++) A[ii].resize(j);
  int pi = 0, ti = 0, xypi = 0, xyti = 0;
  for (int iii = (0), iE = (ans); iii < iE; iii++) {
    A[x][y] = back[f[pi].second];
    x++, y = (y + 1) % j;
    xyti++;
    if (xyti == i) {
      xyti = x = 0;
      y = ++xypi;
    }
    ti++;
    if (ti == min(i, f[pi].first)) {
      pi++;
      ti = 0;
    }
  }
  cout << ans << endl;
  cout << i << ' ' << j << endl;
  for (int ii = (0), iE = (i); ii < iE; ii++)
    for (int jj = (0), iE = (j); jj < iE; jj++)
      cout << A[ii][jj] << " \n"[jj == j - 1];
  return 0;
}
