#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int curr;
    cin >> curr;
    mp[curr]++;
  }
  vector<int> nums(mp.size());
  int counter = 0;
  vector<pair<int, int> > sorted(mp.size());
  for (auto i : mp) {
    sorted[counter].first = i.second;
    sorted[counter].second = i.first;
    nums[counter] = i.second;
    counter++;
  }
  sort(sorted.begin(), sorted.end());
  sort(nums.begin(), nums.end());
  vector<int> sums(nums.size());
  sums[nums.size() - 1] = nums.back();
  for (int i = sums.size() - 2; i >= 0; i--) {
    sums[i] = sums[i + 1] + nums[i];
  }
  int sqr = (int)sqrt(n);
  int mx = 0;
  pair<int, int> dimensions;
  for (int i = sqr; i > 0; i--) {
    int low = 0;
    int high = nums.size() - 1;
    while (low <= high) {
      int mid = (low + high) >> 1;
      if (nums[mid] <= i) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    int res = n;
    if (i < nums.back()) {
      res -= sums[low] - (nums.size() - low) * i;
    }
    low = i;
    high = n;
    if (res < i * i) {
      continue;
    }
    while (low <= high) {
      int mid = (low + high) >> 1;
      if (mid * i < res) {
        low = mid + 1;
      } else if (mid * i > res) {
        high = mid - 1;
      } else {
        high = mid;
        break;
      }
    }
    if (mx < i * high) {
      mx = i * high;
      dimensions.first = i;
      dimensions.second = high;
    }
  }
  cout << mx << "\n";
  cout << dimensions.first << " " << dimensions.second << "\n";
  int arr[dimensions.first][dimensions.second];
  auto itr = sorted.rbegin();
  counter = min((*itr).first, dimensions.first);
  for (int i = 0; i < dimensions.second; i++) {
    int start = i;
    for (int a = 0; a < dimensions.first; a++) {
      if (counter == 0) {
        itr++;
        counter = min((*itr).first, dimensions.first);
      }
      arr[a][start] = (*itr).second;
      counter--;
      start = (start + 1) % dimensions.second;
    }
  }
  for (int i = 0; i < dimensions.first; i++) {
    for (int a = 0; a < dimensions.second - 1; a++) {
      cout << arr[i][a] << " ";
    }
    cout << arr[i][dimensions.second - 1] << "\n";
  }
}
