#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
int n, z;
int w[maxn];
vector<pair<int, int> > v;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 1; i <= 400000; i++) {
    int x = sqrt(i) + 2;
    for (;; x--) {
      if (i % x == 0 && x <= i / x) {
        w[i] = x;
        break;
      }
    }
  }
  vector<int> uu;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> z;
    uu.push_back(z);
  }
  sort((uu).begin(), (uu).end());
  int last = 0, cnt = 0;
  for (int i : uu) {
    if (i != last) last = i, cnt = 0;
    v.push_back(make_pair(++cnt, i));
  }
  sort((v).begin(), (v).end());
  int tar;
  for (int i = n; i >= 1; i--) {
    if (v[i - 1].first <= w[i]) {
      tar = i;
      break;
    }
  }
  cout << tar << '\n' << w[tar] << ' ' << tar / w[tar] << '\n';
  vector<int> vv;
  vector<vector<int> > M2;
  for (int i = 0; i < tar; i++) vv.push_back(v[i].second);
  int p = w[tar], q = tar / w[tar], x = 0, y = 0;
  for (int i = 0; i < p; i++) {
    M2.push_back(vector<int>());
    for (int j = 0; j < q; j++) M2[i].push_back(0);
  }
  if (p != q) {
    sort((vv).begin(), (vv).end());
    for (int i = 0; i < tar; i++) {
      M2[x][y] = vv[i];
      if (x == p - 1)
        x = 0, y = (y + q - p) % q;
      else
        x = (x + 1) % p, y = (y + 1) % q;
    }
    for (int i = 0; i < p; i++) {
      for (int j = 0; j < q; j++) cout << M2[i][j] << ' ';
      cout << '\n';
    }
  } else {
    vv.clear();
    set<int> tmp;
    for (int i = tar - 1; i >= 0; i--) {
      if (tmp.find(v[i].second) == tmp.end()) {
        tmp.insert(v[i].second);
        for (int j = 0; j < v[i].first; j++) vv.push_back(v[i].second);
      }
    }
    for (int i = 0; i < tar; i++) {
      M2[x][y] = vv[i];
      if (x == p - 1)
        x = 0, y = (y + q - (p - 2)) % q;
      else
        x = (x + 1) % p, y = (y + 1) % q;
    }
    for (int i = 0; i < p; i++) {
      for (int j = 0; j < q; j++) cout << M2[i][j] << ' ';
      cout << '\n';
    }
  }
}
