#include <bits/stdc++.h>
using namespace std;
long long a[400100];
map<int, int> m;
int o[400100];
set<int> s;
int sum[400100];
int get(int cr) {
  for (int i = sqrt(cr); i >= 1; i--) {
    if (cr % i == 0) {
      return i;
    }
  }
}
vector<pair<int, int> > k;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  map<int, int>::iterator it2;
  sort(a, a + n);
  for (it2 = m.begin(); it2 != m.end(); it2++) {
    int op = it2->second;
    k.push_back(make_pair(-(it2->second), it2->first));
    for (int i = 1; i <= op; i++) o[i]++;
  }
  sort(k.begin(), k.end());
  int kk = 0;
  for (int i = 0; i < n; i++) {
    k[kk].first *= -1;
    for (int j = i; j <= i + k[kk].first; j++) {
      a[j] = k[kk].second;
    }
    i += k[kk].first - 1;
    kk++;
  }
  for (int i = 1; i <= n; i++) {
    sum[i] = o[i] + sum[i - 1];
  }
  int mx = 1;
  for (int i = 1; i <= n; i++) {
    int y = get(i);
    if (sum[y] >= i) {
      mx = i;
    }
  }
  int x = get(mx), y = mx / x;
  int cr = 0, cr2 = 0, second = 0, cr3 = 0, cr4 = 0, dd = 1;
  int ans[x + 3][y + 3];
  while (second < mx) {
    second++;
    if (cr == x) {
      cr = 0;
      cr2 = dd;
      dd++;
    }
    cr2 %= y;
    if (cr3 > 0 && a[cr3] != a[cr3 - 1]) cr4 = 0;
    if (cr4 == x) {
      int pp = cr3;
      while (a[cr3] == a[pp]) cr3++;
      cr4 = 0;
    }
    ans[cr][cr2] = a[cr3];
    cr4++;
    cr++;
    cr2++;
    cr3++;
  }
  cout << mx << endl << x << ' ' << y << endl;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) cout << ans[i][j] << ' ';
    cout << endl;
  }
  return 0;
}
