#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, cn;
struct ky {
  int x, id;
  bool operator<(const ky &p) const { return x ^ p.x ? x > p.x : id > p.id; }
} a[N];
vector<int> g[N];
deque<int> q;
inline int Min(const int p, const int q) { return p < q ? p : q; }
int main() {
  scanf("%d", &n);
  register int i;
  for (i = 1; i <= n; ++i) scanf("%d", &a[i].x), a[i].id = i;
  std::sort(a + 1, a + 1 + n);
  for (i = 1; i <= a[1].x; ++i) q.push_back(++cn), g[a[1].id].push_back(cn);
  for (i = 2; i <= n; ++i) {
    register int x = Min(a[i].x - 1,
                         (q.size() + a[i].x - (i == n ? 3 : a[i + 1].x)) >> 1),
                 j;
    for (j = 1; j < x; ++j) g[a[i].id].push_back(q.back()), q.pop_back();
    g[a[i].id].push_back(q.back());
    for (j = x + 1; j < a[i].x; ++j)
      g[a[i].id].push_back(++cn), q.push_back(cn);
    g[a[i].id].push_back(q.front()), q.push_back(q.front()), q.pop_front();
  }
  printf("%d\n", cn);
  for (i = 1; i <= n; puts(""), ++i)
    for (const int &x : g[i]) printf("%d ", x);
  return 0;
}
