#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("no-stack-protector")
using namespace std;
const long long INF = 1e18;
long long si = 32;
string s;
long long a, b, c, d, n, m, best_ans, best_si;
long long mas[500001], mas2[500001];
vector<long long> vec;
vector<pair<long long, long long>> vec2;
vector<vector<long long>> ans;
vector<long long> ans2;
vector<long long> ord;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second > b.second;
}
signed main() {
  cin >> a;
  for (long long i = 0; i < a; i++) {
    cin >> b;
    vec.push_back(b);
  }
  sort(vec.begin(), vec.end());
  b = 1;
  for (long long i = 1; i <= vec.size(); i++) {
    if (i == vec.size()) {
      vec2.push_back({vec[i - 1], b});
      mas[b]++;
      continue;
    }
    if (vec[i] != vec[i - 1]) {
      vec2.push_back({vec[i - 1], b});
      mas[b]++;
      b = 1;
    } else {
      b++;
    }
  }
  sort(vec2.begin(), vec2.end(), comp);
  n = vec2.size();
  for (long long i = 1; i <= a; i++) {
    mas2[i] = mas2[i - 1] + n;
    n -= mas[i];
  }
  for (long long i = 1; i <= sqrt(a); i++) {
    if (mas2[i] / i >= i && i * (mas2[i] / i) > best_ans) {
      best_ans = i * (mas2[i] / i);
      best_si = i;
    }
  }
  cout << best_ans << '\n';
  cout << best_si << " " << best_ans / best_si << '\n';
  for (long long j = 0; j < best_si; j++) {
    ans2.push_back(-1);
  }
  for (long long i = 0; i < best_ans / best_si; i++) {
    ans.push_back(ans2);
  }
  for (long long i = 0; i < vec2.size(); i++) {
    for (long long j = 0; j < min(vec2[i].second, best_si); j++) {
      ord.push_back(vec2[i].first);
    }
  }
  long long pos = 0;
  for (long long i = 0; i < best_ans / best_si; i++) {
    while (ans[pos % (best_ans / best_si)][0] != -1) {
      pos++;
    }
    for (long long j = 0; j < best_si; j++) {
      ans[(pos + j) % (best_ans / best_si)][j] = ord[i * best_si + j];
    }
    pos += best_si;
  }
  for (long long i = 0; i < best_si; i++) {
    for (long long j = 0; j < best_ans / best_si; j++) {
      cout << ans[j][i] << " ";
    }
    cout << '\n';
  }
  cin >> a;
  return 0;
}
