#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> cnt;
vector<int> vec;
bool sorting(int x, int y) { return cnt[x] > cnt[y]; }
int pref1[500000];
int pref2[500000];
int one[500000];
int two[500000];
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    if (cnt[a[i]] == 0) vec.push_back(a[i]);
    cnt[a[i]]++;
  }
  sort(vec.begin(), vec.end(), sorting);
  for (int i = 0; i < 500000; i++) {
    one[i] = 0;
    two[i] = 0;
  }
  for (int i = 0; i < vec.size(); i++) {
    one[cnt[vec[i]]]++;
    two[cnt[vec[i]]] += cnt[vec[i]];
  }
  pref1[0] = 0;
  pref2[0] = 0;
  for (int i = 1; i < 500000; i++) {
    pref1[i] = pref1[i - 1] + one[i];
    pref2[i] = pref2[i - 1] + two[i];
  }
  int m = 1;
  int k = 1;
  for (int i = 1; i <= n; i++) {
    int s = 0;
    s += pref1[n] - pref1[i];
    s += pref2[i] / i;
    int c = pref1[n] - pref1[s];
    c += pref2[s] / s;
    if (s * i >= m * k && c >= i) {
      m = i;
      k = s;
    }
  }
  if (m > k) swap(m, k);
  vector<int> an;
  int mn = min(m, k);
  for (int i = 0; i < vec.size(); i++) {
    for (int j = 0; j < min(mn, cnt[vec[i]]) && an.size() < m * k; j++)
      an.push_back(vec[i]);
  }
  vector<int> ans;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < k; j++) ans.push_back(an[i + m * j]);
  cout << m * k << endl;
  cout << m << " " << k << endl;
  int s[m][k];
  int it2 = -1;
  for (int i = 0; i < ans.size(); i++) {
    if (i % k == 0) it2++;
    s[i / k][it2 % k] = ans[i];
    it2++;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < k; j++) printf("%d ", s[i][j]);
    cout << endl;
  }
  return 0;
}
