#include <bits/stdc++.h>
using namespace std;
const long long maxn = 4e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long n;
long long a[maxn];
map<long long, long long> cnt;
set<long long> yes;
vector<pair<long long, long long>> ve;
long long ps[maxn];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (long long i = 1; i <= n; i++)
    if (!yes.count(a[i])) {
      ve.push_back({cnt[a[i]], a[i]});
      yes.insert(a[i]);
    }
  sort(ve.begin(), ve.end());
  for (long long i = 0; i < ve.size(); i++) ps[i] = ps[i - 1] + ve[i].first;
  long long mx = 0, AA = 1, BB = 1;
  for (long long A = 1; A <= n; A++) {
    long long x =
        lower_bound(ve.begin(), ve.end(), make_pair(A, 0ll)) - ve.begin();
    long long sm;
    if (x >= 0)
      sm = ps[x - 1] + A * (ve.size() - x);
    else
      sm = A * ve.size();
    for (long long B = A; A * B <= n; B++)
      if (sm >= A * B && A * B > mx) {
        mx = A * B;
        AA = A;
        BB = B;
      }
  }
  cout << mx << "\n";
  for (long long A = AA; A <= AA; A++) {
    long long x =
        lower_bound(ve.begin(), ve.end(), make_pair(A, 0ll)) - ve.begin();
    long long sm;
    if (x >= 0)
      sm = ps[x - 1] + A * (ve.size() - x);
    else
      sm = A * ve.size();
    for (long long B = BB; B <= BB; B++)
      if (sm >= A * B && mx == A * B) {
        long long ans[A + 1][B + 1];
        vector<pair<long long, long long>> match[B + 1];
        vector<pair<long long, long long>> edge;
        for (long long i = 0; i < A; i++)
          for (long long j = 0; j < B; j++)
            match[(i + j) % B].push_back({i, j});
        for (long long i = B - 1; i >= 0; i--)
          for (auto e : match[i]) edge.push_back(e);
        long long L = 0;
        for (long long i = ve.size() - 1; i >= 0; i--)
          for (long long j = 1; j <= min(A, ve[i].first); j++) {
            if (L >= edge.size()) break;
            ans[edge[L].first][edge[L].second] = ve[i].second;
            L++;
          }
        cout << A << " " << B << "\n";
        for (long long i = 0; i < A; i++) {
          for (long long j = 0; j < B; j++) cout << ans[i][j] << " ";
          cout << "\n";
        }
        return 0;
      }
  }
}
