#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400040;
int p[MAXN], ans1[MAXN], ans2[MAXN];
int n, cnt, ans, ansr, ansc;
struct Node {
  int val;
  int num;
} a[MAXN];
map<int, int> m;
bool cmp(Node x, Node y) { return x.num < y.num; }
int id(int x, int y) { return (x - 1) * ansc + y; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p[i]);
    ++m[p[i]];
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= n; ++i) {
    if (p[i] != p[i - 1]) {
      a[cnt].num = m[p[i - 1]];
      a[++cnt].val = p[i];
    }
  }
  a[cnt].num = m[p[n]];
  if (cnt == 0) a[++cnt].num = n, a[cnt].val = p[n];
  int l = sqrt(n);
  for (int r = 1; r <= l; ++r) {
    int tot = 0;
    for (int i = 1; i <= cnt; ++i)
      if (a[i].num > r) tot += a[i].num - r;
    int c = (n - tot) / r;
    if (r > c) continue;
    if (ans < r * c) {
      ans = r * c;
      ansr = r, ansc = c;
    }
  }
  if (ans != 0) {
    printf("%d\n", ans);
    printf("%d %d\n", ansr, ansc);
    sort(a + 1, a + cnt + 1, cmp);
    int x = 0;
    for (int i = 1; i <= cnt; ++i)
      for (int j = 1; j <= min(ansr, a[i].num); ++j) ans1[++x] = a[i].val;
    int x1, x2, cnt1 = x;
    for (int i = 1; i <= ansc; ++i) {
      x1 = 1, x2 = i;
      for (int j = 1; j <= ansr; ++j) {
        ans2[id(x1, x2)] = ans1[cnt1--];
        ++x1, ++x2;
        if (x2 > ansc) x2 -= ansc;
      }
    }
    for (int i = 1; i <= ansr; ++i)
      for (int j = 1; j <= ansc; ++j)
        printf("%d%c", ans2[id(i, j)], (j == ansc) ? '\n' : ' ');
  } else
    printf("1\n1 1\n%d\n", p[n]);
  return 0;
}
