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>
using namespace std;
template <typename T>
struct outputer;
struct outputable {};
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1 &a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 100000;
struct Input {
  int n;
  int a[N];
  bool read() {
    if (!(cin >> n)) {
      return 0;
    }
    for (int i = int(0); i < int(n); ++i) {
      scanf("%d", &a[i]);
    }
    return 1;
  }
  void init(const Input &input) { *this = input; }
};
struct Data : Input {
  int res;
  vector<int> ans[N];
  void write() {
    cout << res << endl;
    for (int i = int(0); i < int(n); ++i) {
      for (int j = int(0); j < int(a[i]); ++j) {
        if (j) {
          printf(" ");
        }
        printf("%d", ans[i][j] + 1);
      }
      puts("");
    }
  }
};
namespace Main {
struct G {
  int n;
  deque<int> r;
  vector<int> nums;
  vector<vector<int> > g;
  G(int num, int s) {
    n = s;
    r.resize(n);
    g.resize(1);
    g[0].resize(n);
    iota((r).begin(), (r).end(), 0);
    iota((g[0]).begin(), (g[0]).end(), 0);
    nums = {num};
  }
};
void unite(G &a, G &b, int m) {
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  int mx = min(((int)(a.r).size()), ((int)(b.r).size()));
  if (((int)(a.r).size()) == ((int)(b.r).size())) {
    mx--;
  };
  vector<int> to(b.n, -1);
  int len = ((int)(a.r).size()) + ((int)(b.r).size());
  int cnt = 0;
  for (int i = int(0); i < int(mx); ++i) {
    if (len <= m) {
      break;
    }
    to[b.r[i]] = a.r[(((int)(a.r).size()) - i) % ((int)(a.r).size())];
    if (i < 2) {
      len--;
    } else {
      len -= 2;
    }
    cnt++;
  };
  ;
  ;
  int n1 = a.n;
  for (int i = int(0); i < int(b.n); ++i) {
    if (to[i] == -1) {
      to[i] = n1++;
    }
  };
  assert(n1 == a.n + b.n - cnt);
  for (auto &v : b.g) {
    for (auto &x : v) {
      x = to[x];
    }
  }
  for (auto &x : b.r) {
    x = to[x];
  }
  a.n = n1;
  for (int i = int(0); i < int(((int)(b.nums).size())); ++i) {
    a.nums.emplace_back(b.nums[i]);
    a.g.emplace_back(b.g[i]);
  }
  assert(cnt >= 2);
  for (int i = int(0); i < int(cnt - 2); ++i) {
    a.r.pop_back();
  }
  for (int i = int(cnt); i < int(((int)(b.r).size())); ++i) {
    a.r.emplace_back(b.r[i]);
  }
  assert(((int)(a.r).size()) == len);
  a.r.emplace_back(a.r.front());
  a.r.pop_front();
  ;
  ;
  ;
  ;
}
struct Solution : Data {
  void solve() {
    vector<G> v;
    for (int i = int(0); i < int(n); ++i) {
      v.emplace_back(G(i, a[i]));
    }
    sort((v).begin(), (v).end(), [&](const G &l, const G &r) {
      return ((int)(l.r).size()) > ((int)(r.r).size());
    });
    for (int i = int(1); i < int(n); ++i) {
      unite(v[0], v[i], (i + 1 < n) ? ((int)(v[i + 1].r).size()) : 0);
    };
    assert(((int)(v[0].nums).size()) == n);
    res = v[0].n;
    for (int i = int(0); i < int(n); ++i) {
      ans[v[0].nums[i]] = v[0].g[i];
    };
  }
  void clear() { *this = Solution(); }
};
}  // namespace Main
Main::Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}