#include <bits/stdc++.h>
using namespace std;
inline int input() {
  int o;
  char c = getchar();
  while (c > 57 || c < 48) c = getchar();
  for (o = 0; c > 47 && c < 58; c = getchar()) o = (o << 1) + (o << 3) + c - 48;
  return o;
}
struct node {
  int i, edge;
} Poly[101234];
bool comp(node a, node b) { return a.edge > b.edge; }
vector<int> res[101234], now;
int main() {
  int n = input();
  for (int i = 1; i <= n; i++) Poly[i] = (node){i, input()};
  sort(Poly + 1, Poly + n + 1, comp);
  int ni = Poly[1].i, cnt = 0, overlay, edge = Poly[1].edge, wait = 0;
  for (int i = 1; i <= Poly[1].edge; i++)
    now.push_back(++cnt), res[ni].push_back(cnt);
  for (int i = 2, comp; i <= n; i++) {
    if (i == n)
      comp = edge - 3;
    else
      comp = min(edge - 3, (edge + Poly[i].edge - 2 - Poly[i + 1].edge) / 2);
    overlay = min(Poly[i].edge - 2, comp);
    ni = Poly[i].i;
    for (int j = 1; j <= overlay; j++) {
      res[ni].push_back(now.back());
      now.pop_back();
    }
    res[ni].push_back(now.back());
    for (int j = 1; j <= Poly[i].edge - overlay - 2; j++) {
      res[ni].push_back(++cnt);
      now.push_back(cnt);
    }
    if (wait) {
      res[ni].push_back(wait);
      now.push_back(wait);
      wait = 0;
    } else
      res[ni].push_back(now[0]);
    if (Poly[i].edge == 3 && overlay == 0) {
      wait = now.back();
      now.pop_back();
    }
    edge = edge + Poly[i].edge - (overlay << 1) - 2;
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++) {
    for (auto j : res[i]) printf("%d ", j);
    putchar('\n');
  }
}
