#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1 << 62;
const long long MOD = 1e9 + 7;
const int iINF = 1 << 30;
const double PI = 3.14159265359;
vector<vector<int> > form(vector<pair<int, int> > a, int p, int q) {
  vector<int> b;
  for (int i = a.size() - 1; (int)b.size() < p * q && i >= 0; i--) {
    for (int j = 0; j < min(p, a[i].first); j++) {
      b.push_back(a[i].second);
      if ((int)b.size() == p * q) break;
    }
  }
  vector<vector<int> > ans(p, vector<int>(q, -1));
  int x = 0, y = 0;
  for (int i = 0; i < (int)b.size(); i++) {
    if (ans[x][y] != -1) {
      y = (y + 1) % q;
    }
    ans[x][y] = b[i];
    x = (x + 1) % p;
    y = (y + 1) % q;
  }
  return ans;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) cin >> x;
  sort(a.begin(), a.end());
  vector<pair<int, int> > b;
  for (int i = 0; i < n;) {
    int j = i;
    for (; j < n && a[j] == a[i]; j++)
      ;
    b.push_back({j - i, a[i]});
    i = j;
  }
  sort(b.begin(), b.end());
  int m = b.size();
  vector<int> pre(m);
  for (int i = 0; i < m; i++) {
    pre[i] = b[i].first;
    if (i) pre[i] += pre[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    for (int f = 1; f * f <= n; f++) {
      if (i % f == 0) {
        int p = min(f, i / f);
        int q = max(f, i / f);
        int idx =
            lower_bound(b.begin(), b.end(), make_pair(p, iINF)) - b.begin();
        int num = 0;
        if (idx == m)
          num = n;
        else
          num = pre[idx] - b[idx].first + p * (m - idx);
        if (num >= i) {
          cout << i << " " << p << " " << q << endl;
          vector<vector<int> > ans = form(b, p, q);
          for (vector<int> row : ans) {
            for (int col : row) cout << col << " ";
            cout << "\n";
          }
          return;
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
