#include <bits/stdc++.h>
using namespace std;
inline void normal(long long &a) { a = (a + 998244353) % 998244353; }
inline long long modMul(long long a, long long b) {
  a %= 998244353, b %= 998244353;
  normal(a), normal(b);
  return (a * b) % 998244353;
}
inline long long modAdd(long long a, long long b) {
  a %= 998244353, b %= 998244353;
  normal(a), normal(b);
  return (a + b) % 998244353;
}
inline long long modSub(long long a, long long b) {
  a %= 998244353, b %= 998244353;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInv(long long a) { return modPow(a, 998244353 - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInv(b));
}
const long long N = 4e5 + 1;
vector<long long> V;
long long n, x, R, C, cntt[N];
map<long long, long long> M;
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    M[x]++;
  }
  for (auto u = (M).begin(); u != (M).end(); u++) {
    cntt[u->second]++;
  }
  x = n;
  for (long long i = n; i > 0; i--) {
    if (R * C < (x / i * i) && i <= x / i) {
      R = i, C = x / i;
    }
    x -= cntt[i];
    cntt[i - 1] += cntt[i];
  }
  cout << R * C << endl;
  cout << R << " " << C << endl;
  if (!(R * C)) return;
  long long ans[R][C];
  x = min(R, C);
  vector<pair<long long, long long> > p;
  for (auto u = (M).begin(); u != (M).end(); u++) {
    p.push_back({min(u->second, x), u->first});
  }
  sort((p).rbegin(), (p).rend());
  while ((long long)((p).size())) {
    while (p.back().first) {
      V.push_back(p.back().second), p.back().first--;
    }
    p.pop_back();
  }
  long long i = 0, j = 0, cnt = 0;
  for (long long i = 0; i < C; i++) {
    for (long long j = 0; j < R; j++) {
      ans[j][(i + j) % C] = V.back(), V.pop_back();
    }
  }
  for (long long i = 0; i < R; i++) {
    for (long long j = 0; j < C; j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  clock_t start, end;
  start = clock();
  cout << fixed << setprecision(18);
  ;
  while (t--) {
    solve();
  }
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
}
