#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T, class S>
ostream &operator<<(ostream &o, const pair<T, S> &p) {
  return o << '(' << p.first << ", " << p.second << ')';
}
template <template <class, class...> class T, class... A>
typename enable_if<!is_same<T<A...>, string>(), ostream &>::type operator<<(
    ostream &o, T<A...> V) {
  o << '[';
  for (auto a : V) o << a << ", ";
  return o << ']';
}
map<long long int, long long int> ct;
vector<pair<long long int, long long int> > v;
vector<pair<long long int, long long int> > options;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    ct[x]++;
  }
  for (auto a : ct) v.emplace_back(a.second, a.first);
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long int idx = 0;
  for (long long int r = n; r > 0; r--) {
    if (r <= n / r) options.emplace_back(r, n / r);
    while (idx < v.size() && v[idx].first == r) idx++;
    n -= idx;
  }
  long long int rows = 0, cols = 0;
  for (pair<long long int, long long int> p : options)
    if (p.first * p.second > rows * cols) {
      rows = p.first;
      cols = p.second;
    }
  long long int cR = 0, cC = 0;
  long long int grid[rows][cols];
  for (pair<long long int, long long int> p : v)
    for (long long int k = 0; k < min(rows, p.first); k++) {
      grid[cR++][cC++] = p.second;
      if (cR == rows) {
        cR = 0;
        cC = (cC - rows + 1 + cols) % cols;
      } else if (cC == cols)
        cC = 0;
    }
  cout << rows * cols << '\n' << rows << ' ' << cols << '\n';
  for (long long int i = 0; i < rows; i++) {
    for (long long int j = 0; j < cols; j++) cout << grid[i][j] << ' ';
    cout << '\n';
  }
}
