#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void prn(Arg1&& arg1) {
  cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void prn(Arg1&& arg1, Args&&... args) {
  cout << arg1 << " ";
  prn(args...);
}
template <typename Arg1>
void prs(Arg1&& arg1) {
  cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void prs(Arg1&& arg1, Args&&... args) {
  cout << arg1 << " ";
  prs(args...);
}
template <typename Arg1>
void read(Arg1&& arg1) {
  cin >> arg1;
}
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) {
  cin >> arg1;
  read(args...);
}
inline void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int tc = 1; tc <= t; ++tc) {
    solve();
  }
  return 0;
}
int n;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
inline void solve() {
  read(n);
  unordered_map<long long, int, custom_hash> f;
  for (int i = 0; i < n; ++i) {
    int x;
    read(x);
    ++f[x];
  }
  vector<int> atF(n + 1, 0);
  for (auto i : f) {
    for (int j = 1; j <= i.second; ++j) {
      ++atF[j];
    }
  }
  int ai = 0, aj = 0, have = 0;
  for (int i = 1; i * i <= n; ++i) {
    have += atF[i];
    if (have < i * i) continue;
    int bi = i, bj = have / i;
    if (bi * bj > ai * aj) ai = bi, aj = bj;
  }
  vector<int> vals;
  for (auto i : f) {
    int tak = min(ai, i.second);
    for (int j = 0; j < tak; ++j) {
      vals.push_back(i.first);
    }
  }
  sort(vals.begin(), vals.end(), [&](int i1, int i2) {
    if (f[i1] == f[i2]) return i1 < i2;
    return f[i1] > f[i2];
  });
  vals.resize(ai * aj);
  vector<vector<int> > ans(ai, vector<int>(aj));
  prn(ai * aj);
  prn(ai, aj);
  int ctr = 0;
  for (int j = 0; j < aj; ++j) {
    int cj = j;
    for (int i = 0; i < ai; ++i) {
      ans[i][cj % aj] = vals[ctr++];
      ++cj;
    }
  }
  for (int i = 0; i < ai; ++i) {
    for (int j = 0; j < aj; ++j) {
      prs(ans[i][j]);
    }
    prn("");
  }
}
