#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
struct Face {
  vector<int> Ver;
  int siz;
  int idx;
  int &operator[](int i) { return Ver[i]; }
} F[N];
int C[N];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int s;
    cin >> s;
    F[i].Ver.resize(s);
    F[i].siz = s;
    F[i].idx = i;
  }
  sort(F, F + n, [&](const Face &a, const Face &b) { return a.siz > b.siz; });
  for (int i = n - 1; i; --i) C[i] = C[i + 1] + F[i].siz - 2;
  iota(F[0].Ver.begin(), F[0].Ver.end(), 1);
  deque<int> Combi;
  for (int x : F[0].Ver) Combi.push_back(x);
  int tot = Combi.size();
  for (int i = 1; i < n; ++i) {
    if (Combi.size() + F[i].siz - 4 < C[i + 1]) {
      int ver = Combi.back();
      Combi.pop_back();
      F[i][0] = Combi.back();
      Combi.pop_back();
      F[i].Ver.back() = ver;
      for (int j = 1; j < F[i].siz - 1; ++j) F[i][j] = ++tot;
      for (int x : F[i].Ver) Combi.push_back(x);
    } else {
      int k = (Combi.size() + F[i].siz - C[i + 1]) / 2;
      if (k >= Combi.size()) k = Combi.size() - 1;
      if (k > F[i].siz) k = F[i].siz;
      for (int j = 0; j < k; ++j) {
        assert(Combi.size());
        F[i][j] = Combi.back();
        if (j < k - 1) Combi.pop_back();
      }
      for (int j = k; j < F[i].siz; ++j) {
        F[i][j] = ++tot;
        Combi.push_back(tot);
      }
      Combi.push_back(F[i][0]);
    }
    Combi.push_front(Combi.back());
    Combi.pop_back();
  }
  sort(F, F + n, [&](const Face &a, const Face &b) { return a.idx < b.idx; });
  cout << tot << "\n";
  for (int i = 0; i < n; ++i) {
    for (int x : F[i].Ver) cout << x << " ";
    cout << "\n";
  }
}
