Problem: You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.

A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different.

What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself.

Input

The first line contains n (1 ≤ n ≤ 4⋅10^5). The second line contains n integers (1 ≤ a_i ≤ 10^9).

Output

In the first line print x (1 ≤ x ≤ n) — the total number of cells of the required maximum beautiful rectangle. In the second line print p and q (p ⋅ q=x): its sizes. In the next p lines print the required rectangle itself. If there are several answers, print any.

Examples

Input


12
3 1 4 1 5 9 2 6 5 3 5 8


Output


12
3 4
1 2 3 5
3 1 5 4
5 6 8 9


Input


5
1 1 1 1 1


Output


1
1 1
1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
unsigned sed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0, 1000000007);
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  int fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
int n;
int a[400005];
map<int, int> cnt;
int sum[400005];
map<int, int> mat[400005];
signed main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
    cnt[a[i]]++;
  }
  vector<pair<int, int>> vec;
  for (auto i : cnt) vec.push_back(make_pair(i.second, i.first));
  sort(vec.begin(), vec.end());
  sum[0] = vec[0].first;
  for (int i = 1; i < vec.size(); ++i) sum[i] = sum[i - 1] + vec[i].first;
  int ans = 0, ansp, ansq;
  for (int p = 1; p <= n; ++p) {
    int id = lower_bound(vec.begin(), vec.end(), make_pair(p, 0)) - vec.begin();
    int val = (id == 0 ? 0 : sum[id - 1]) + p * (vec.size() - id);
    if (val < p * p) break;
    int q = val / p;
    if (p * q > ans) {
      ans = p * q;
      ansp = p;
      ansq = q;
    }
  }
  writeln(ans);
  write(ansp), putchar(' '), writeln(ansq);
  vector<int> chs;
  for (int i = vec.size() - 1; i >= 0; --i)
    if (vec[i].first <= ansp) {
      for (int j = 1; j <= vec[i].first; ++j) {
        chs.push_back(vec[i].second);
        if (chs.size() == ans) break;
      }
      if (chs.size() == ans) break;
    } else {
      for (int j = 1; j <= ansp; ++j) {
        chs.push_back(vec[i].second);
        if (chs.size() == ans) break;
      }
      if (chs.size() == ans) break;
    }
  int id = 0;
  int x = 0, y = 0;
  for (int i = 1; i <= ansp; ++i)
    for (int j = 1; j <= ansq; ++j) {
      x++, y++;
      x = (x - 1) % ansp + 1;
      y = (y - 1) % ansq + 1;
      while (mat[x][y]) {
        y++;
        y = (y - 1) % ansq + 1;
      }
      mat[x][y] = chs[id];
      id++;
    }
  for (int i = 1; i <= ansp; ++i) {
    for (int j = 1; j <= ansq; ++j) write(mat[i][j]), putchar(' ');
    puts("");
  }
  return 0;
}