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;
const int mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mul(int a, int b) { return ((a)*1ll * (b)) % mod; }
void add(int& a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) {
    a += mod;
  }
  return a;
}
int powz(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = mul(res, a);
    }
    b /= 2;
    a = mul(a, a);
  }
  return res;
}
template <typename A, typename B>
istream& operator>>(istream& input, pair<A, B>& x) {
  input >> x.first >> x.second;
  return input;
}
template <typename A>
istream& operator>>(istream& input, vector<A>& x) {
  for (auto& i : x) input >> i;
  return input;
}
template <typename A>
ostream& operator<<(ostream& output, vector<A>& x) {
  for (auto& i : x) output << i << ' ';
  return output;
}
const int N = 1000002;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  map<int, int> cnt;
  for (auto i : a) {
    cnt[i]++;
  }
  vector<int> val;
  int mx = 0, lst = 0;
  for (auto j : cnt) {
    val.push_back(j.second);
  }
  sort(val.begin(), val.end());
  vector<int> pref(val.size());
  int nw = 0;
  pref[0] = val[0];
  nw += val[0];
  for (int i = 1; i < val.size(); i++) {
    nw += val[i];
    pref[i] = nw;
  }
  int cur = 0;
  42;
  for (int i = 1; i <= n; i++) {
    int ind = upper_bound(val.begin(), val.end(), i) - val.begin();
    int now = (val.size() - ind) * i;
    if (ind) now += pref[ind - 1];
    42;
    if ((now / i) >= i) {
      if ((now / i) * i > cur) {
        cur = (now / i) * i;
        mx = i;
      }
    }
  }
  42;
  if (mx == 0) {
    cout << 1 << '\n';
    cout << 1 << ' ' << 1 << '\n';
    cout << a[0];
    return;
  }
  int rr = mx;
  int c = cur / mx;
  42;
  cout << rr * c << '\n';
  cout << rr << ' ' << c << '\n';
  vector<vector<int>> ans(rr, vector<int>(c));
  int row = 0, col = 0, used = 0;
  vector<pair<int, int>> zz;
  for (auto i : cnt) {
    zz.push_back({min(i.second, mx), i.first});
  }
  sort(zz.begin(), zz.end(), greater<pair<int, int>>());
  42;
  int tot = rr * c;
  for (auto& i : zz) {
    for (int j = 0; j < i.first; j++) {
      tot--;
      ans[row][col] = i.second;
      row++;
      col++;
      row %= rr;
      col %= c;
      if (ans[row][col]) {
        row++;
        row %= rr;
      }
      if (tot == 0) {
        break;
      }
    }
    if (tot == 0) {
      break;
    }
  }
  for (int i = 0; i < rr; i++) {
    for (int j = 0; j < c; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc = 1;
  for (int _ = 0; _ < tc; _++) {
    solve();
    if (_ != tc - 1) cout << "\n";
  }
}