#include <bits/stdc++.h>
using namespace std;
const long long N = 100010;
long long inf = 1e9;
long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> M;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    M[x]++;
  }
  vector<pair<long long, long long>> temp;
  for (auto it : M) {
    temp.push_back({it.second, it.first});
  }
  sort(temp.begin(), temp.end());
  long long m = (long long)temp.size();
  vector<long long> pref(m);
  for (long long i = 0; i < m; i++) {
    pref[i] = temp[i].first;
    if (i) {
      pref[i] += pref[i - 1];
    }
  }
  pair<long long, long long> ans = {0, 0};
  for (long long i = 1; i <= n; i++) {
    long long val = 0;
    long long E =
        lower_bound(temp.begin(), temp.end(), make_pair(i + 1, -1LL)) -
        temp.begin();
    if (E > 0) {
      val += pref[E - 1];
    }
    val += i * (m - E);
    if (i * i <= val) {
      ans = max(ans, make_pair(val / i * i, i));
    }
  }
  map<long long, long long> T;
  for (auto it : M) {
    T[it.first] = min(it.second, ans.second);
  }
  long long R1 = ans.second, R2 = ans.first / ans.second;
  vector<vector<long long>> fin(R1);
  for (long long i = 0; i < R1; i++) {
    fin[i].resize(R2, 0);
  }
  vector<pair<long long, long long>> pos;
  for (long long j = 0; j < R2; j++) {
    for (long long i = 0; i < R1; i++) {
      pos.push_back({i, (i + j) % R2});
    }
  }
  long long X = 0;
  vector<pair<long long, long long>> EE =
      vector<pair<long long, long long>>(T.begin(), T.end());
  for (long long i = 0; i < (long long)EE.size(); i++) {
    swap(EE[i].first, EE[i].second);
  }
  sort(EE.begin(), EE.end());
  reverse(EE.begin(), EE.end());
  for (auto it : EE) {
    for (long long i = 0; i < it.first; i++) {
      fin[pos[X].first][pos[X].second] = it.second;
      X++;
      if (X == ans.first) {
        break;
      }
    }
    if (X == ans.first) {
      break;
    }
  }
  cout << ans.first << "\n";
  cout << R1 << " " << R2 << "\n";
  for (long long i = 0; i < R1; i++) {
    for (long long j = 0; j < R2; j++) {
      cout << fin[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
