#include <bits/stdc++.h>
using namespace std;
template <class T>
void _Print(T &&x) {
  cerr << x << ")"
       << "\n";
}
template <class T, class... S>
void _Print(T &&x, S &&...y) {
  cerr << x << ", ";
  _Print(y...);
}
template <class T>
class compare {
 public:
  bool operator()(pair<T, T> &x, pair<T, T> &y) {
    if (x.first == y.first) {
      return x.second > y.second;
    }
    return x.first > y.first;
  }
};
template <class T>
ostream &operator<<(ostream &os, const pair<T, T> &a) {
  return os << a.first << " " << a.second;
}
long long power(long long a, int b) {
  long long po = 1;
  while (b) {
    if (b & 1) po *= a;
    a *= a;
    b >>= 1;
  }
  return po;
}
template <class T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
  return {a.first + b.first, a.second + b.second};
}
template <class T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
  return {a.first - b.first, a.second - b.second};
}
template <class T>
pair<T, T> operator*(const pair<T, T> &a, const pair<T, T> &b) {
  return {a.first * b.first, a.second * b.second};
}
template <class T>
pair<T, T> operator%(const pair<T, T> &a, const pair<T, T> &b) {
  return {a.first % b.first, a.second % b.second};
}
template <class T, class U>
pair<T, T> operator+(const pair<T, T> &a, const U &b) {
  return {a.first + b, a.second + b};
}
template <class T, class U>
pair<T, T> operator*(const pair<T, T> &a, const U &b) {
  return {a.first * b, a.second * b};
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int ara[n + 1];
  unordered_map<int, int> mpp;
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
    mpp[ara[i]]++;
  }
  queue<pair<int, int> > q;
  for (int i = 1; i <= n; i++) {
    if (mpp[ara[i]]) {
      q.push({mpp[ara[i]], ara[i]});
      mpp[ara[i]] = 0;
    }
  }
  int a = 1, b = 0;
  vector<int> vec;
  for (int i = 1; i * i <= n; i++) {
    int sz = (int)q.size();
    while (sz--) {
      auto x = q.front();
      q.pop();
      vec.emplace_back(x.second);
      x.first--;
      if (x.first > 0) {
        q.push({x.first, x.second});
      }
    }
    if (a * b < i * ((int)vec.size() / i) and (int) vec.size() / i >= i) {
      a = i, b = (int)vec.size() / i;
    }
  }
  while ((int)vec.size() > a * b) {
    vec.pop_back();
  }
  unordered_map<int, int> hmm;
  for (auto &v : vec) {
    hmm[v]++;
  }
  priority_queue<pair<int, int> > pq;
  for (auto &v : vec) {
    if (hmm[v]) {
      pq.push({hmm[v], v});
      hmm[v] = 0;
    }
  }
  vec.clear();
  while (!pq.empty()) {
    auto x = pq.top();
    pq.pop();
    while (x.first--) vec.emplace_back(x.second);
  }
  int i = 0, last = 1, cur = 1, j = 1, mat[a + 1][b + 1];
  while (i < (int)vec.size()) {
    int val = vec[i++];
    mat[cur][j] = val;
    if (cur == a) {
      cur = 1;
      last = last + 1;
      j = last;
    } else if (j == b) {
      cur++;
      j = 1;
    } else {
      cur++;
      j++;
    }
  }
  cout << a * b << "\n";
  cout << a << " " << b << "\n";
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      cout << mat[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
