#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
void fast() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
}
void build_mas(int a, int b, vector<vector<int>>& vall, int n) {
  cout << a * b << endl;
  cout << a << ' ' << b << endl;
  int x = 0, y = 0;
  vector<vector<int>> ans(a, vector<int>(b, 0));
  for (int i = n; i >= 1; --i) {
    for (auto& el : vall[i]) {
      for (int j = 0; j < min(i, a); j++) {
        if (ans[x][y] != 0) {
          x++;
          x %= a;
        }
        if (ans[x][y] == 0) {
          ans[x][y] = el;
        }
        x = (x + 1) % a;
        y = (y + 1) % b;
      }
    }
  }
  for (auto& el : ans) {
    for (auto& val : el) {
      cout << val << ' ';
    }
    cout << endl;
  }
}
signed main() {
  fast();
  int n;
  cin >> n;
  vector<int> m1(n);
  map<int, int> kol;
  vector<vector<int>> vall(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> m1[i];
    if (kol.count(m1[i])) {
      kol[m1[i]]++;
    } else {
      kol[m1[i]] = 1;
    }
  }
  for (auto& el : kol) {
    vall[el.second].push_back(el.first);
  }
  int pref = 0;
  vector<int> cur(n + 1, 0);
  vector<int> pref1(n + 1, 0);
  for (auto& el : kol) {
    for (int i = 1; i <= el.second; i++) {
      cur[i] += i;
    }
    if (el.second + 1 > n) {
      break;
    }
    pref1[el.second + 1] += el.second;
  }
  for (int i = 1; i <= n; i++) {
    pref1[i] += pref1[i - 1];
  }
  for (int i = 0; i <= n; i++) {
    cur[i] += pref1[i];
  }
  for (int a = 1; a <= n; a++) {
    int val = cur[a];
    int b = val / a;
    if (a * b > pref && a <= b) {
      pref = a * b;
    }
  }
  for (int a = 1; a <= n; a++) {
    int val = cur[a];
    int b = val / a;
    if (a * b == pref && a <= b) {
      build_mas(a, b, vall, n);
      return 0;
    }
  }
  return 0;
}
