#include <bits/stdc++.h>
using namespace std;
int a[100000];
vector<int> faces[100000];
int num = 0;
priority_queue<pair<int, int> > H;
set<pair<int, int> > edges;
int main() {
  int i;
  int f;
  scanf("%d", &f);
  for (i = 0; i < f; i++) scanf("%d", &a[i]), H.push(make_pair(a[i], i));
  int j;
  for (i = 0; i < H.top().first; i++) faces[H.top().second].push_back(++num);
  int p = H.top().second;
  deque<int> curr;
  for (i = 0; i < faces[p].size(); i++) curr.push_back(faces[p][i]);
  H.pop();
  for (i = 1; i < f; i++) {
    int u = H.top().second;
    H.pop();
    int want;
    if (i == f - 1)
      want = 3;
    else
      want = H.top().first;
    if (curr.size() - a[u] + 2 > want + 1) {
      for (j = 0; j < a[u]; j++)
        faces[u].push_back(curr.back()), curr.pop_back();
      curr.push_back(faces[u].back()), curr.push_back(faces[u][0]);
    } else {
      if (((curr.size() + a[u]) & 1) == (want & 1)) {
        int over = (curr.size() + a[u] - want) / 2;
        "case1", over;
        for (j = 0; j < over + 1; j++)
          faces[u].push_back(curr.back()), curr.pop_back();
        curr.push_back(faces[u].back());
        for (j = 0; j < a[u] - over - 1; j++)
          faces[u].push_back(++num), curr.push_back(num);
        curr.push_back(faces[u][0]);
      } else {
        int over = (curr.size() + a[u] - want - 1) / 2;
        "case2", over;
        for (j = 0; j < over + 1; j++)
          faces[u].push_back(curr.back()), curr.pop_back();
        curr.push_back(faces[u].back());
        for (j = 0; j < a[u] - over - 1; j++)
          faces[u].push_back(++num), curr.push_back(num);
        curr.push_back(faces[u][0]);
      }
    }
    curr.push_back(curr[0]), curr.pop_front();
    ;
  }
  printf("%d\n", num);
  for (i = 0; i < f; i++) {
    for (j = 0; j < faces[i].size(); j++) printf("%d ", faces[i][j]);
    printf("\n");
  }
  for (i = 0; i < f; i++) {
    for (j = 0; j < faces[i].size(); j++) {
      int a = faces[i][j], b = faces[i][(j + 1) % faces[i].size()];
      if (a > b) swap(a, b);
      assert(a <= num);
      assert(b <= num);
      if (edges.count(make_pair(a, b)))
        edges.erase(make_pair(a, b));
      else
        edges.insert(make_pair(a, b));
    }
  }
  edges.size();
  return 0;
}
