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;
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;
}