Problem: Ujan has finally cleaned up his house and now wants to decorate the interior. He decided to place a beautiful carpet that would really tie the guest room together.

He is interested in carpets that are made up of polygonal patches such that each side of a patch is either a side of another (different) patch, or is an exterior side of the whole carpet. In other words, the carpet can be represented as a planar graph, where each patch corresponds to a face of the graph, each face is a simple polygon. The perimeter of the carpet is the number of the exterior sides. 

Ujan considers a carpet beautiful if it consists of f patches, where the i-th patch has exactly a_i sides, and the perimeter is the smallest possible. Find an example of such a carpet, so that Ujan can order it!

Input

The first line of input contains a single integer f (1 ≤ f ≤ 10^5), the number of patches in the carpet. 

The next line contains f integers a_1, …, a_f (3 ≤ a_i ≤ 3⋅ 10^5), the number of sides of the patches. The total number of the sides of the patches a_1 + … + a_f does not exceed 3⋅10^5.

Output

Output the description of the carpet as a graph. 

First, output a single integer n (3 ≤ n ≤ 3 ⋅ 10^5), the total number of vertices in your graph (the vertices must be numbered from 1 to n). 

Then output f lines containing the description of the faces. The i-th line should describe the i-th face and contain a_i distinct integers v_{i,1}, …, v_{i,a_i} (1 ≤ v_{i,j} ≤ n), which means that the vertices v_{i,j} and v_{i,(j mod{a_i})+1} are connected by an edge for any 1 ≤ j ≤ a_i.

The graph should be planar and satisfy the restrictions described in the problem statement. Its perimeter should be the smallest possible. There should be no double edges or self-loops in the graph. The graph should be connected. Note that a solution always exists; if there are multiple solutions, output any of them.

Examples

Input


2
3 3


Output


4
2 1 4 
1 2 3 


Input


3
5 3 5


Output


6
1 2 3 4 5
4 5 6
1 3 4 6 5

Note

In the first sample, the two triangular faces are connected by a single edge, which results in the minimum perimeter 4.

The figure shows one possible configuration for the second sample. The minimum perimeter in this case is 3. 

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long MAX = 100100;
long long n;
long long t[MAX];
long long pocz[MAX];
vector<long long> daj(long long x) {
  vector<long long> res(t[x]);
  for (long long i = (0); i <= ((long long)(t[x]) - 1); i++) {
    res[i] = i + pocz[x];
  }
  return res;
}
vector<long long> f;
vector<long long> res;
long long find(long long a) { return f[a] == a ? a : f[a] = find(f[a]); }
long long sum = 0;
void uni(long long a, long long b) {
  (a, b);
  a = find(a);
  b = find(b);
  f[a] = b;
  sum--;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n;
  vector<long long> p(n);
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    cin >> t[i];
    pocz[i] = sum;
    sum += t[i];
    p[i] = i;
  }
  f.resize(sum);
  res.resize(sum);
  for (long long i = (0); i <= ((long long)(((long long)(f).size())) - 1); i++)
    f[i] = i;
  sort((p).begin(), (p).end(),
       [&](long long x, long long y) { return t[x] > t[y]; });
  vector<long long> xxx = daj(p[0]);
  deque<long long> ak(((long long)(xxx).size()));
  for (long long i = (0); i <= ((long long)(((long long)(xxx).size())) - 1);
       i++) {
    ak[i] = xxx[i];
  }
  for (long long _ = 1; _ < n; _++) {
    long long i = p[_];
    long long nast = _ == n - 1 ? 3 : t[p[_ + 1]];
    vector<long long> pom = daj(i);
    (pom);
    long long ost = ak.back();
    uni(pom.back(), ak.back());
    pom.pop_back();
    ak.pop_back();
    uni(pom.back(), ak.back());
    while (((long long)(pom).size()) > 1 &&
           ((long long)(pom).size()) + ((long long)(ak).size()) - 2 >= nast) {
      pom.pop_back();
      ak.pop_back();
      uni(pom.back(), ak.back());
    }
    pom.pop_back();
    for (long long j = ((long long)(pom).size()) - 1; j >= 0; j--) {
      ak.push_back(pom[j]);
    }
    ak.push_front(ost);
  }
  cout << sum << "\n";
  long long ver = 1;
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    for (long long j = (0); j <= ((long long)(t[i]) - 1); j++) {
      long long kt = find(pocz[i] + j);
      if (res[kt] == 0) {
        res[kt] = ver;
        ver++;
      }
      cout << res[kt] << " ";
    }
    cout << "\n";
  }
}