#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000;
const long long LINF = INF * (long long)INF;
const int MAX = 300007;
const int MOD = 1000000007;
const double Pi = acos(-1.0);
vector<int> res[MAX];
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  vector<pair<int, int> > A;
  for (int i = (0); i < (n); i++) {
    int x;
    cin >> x;
    A.push_back(make_pair(x, i));
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int s = 0;
  for (int i = (1); i < ((int)A.size()); i++) {
    s += A[i].first;
  }
  int cnt = A[0].first;
  vector<int> C;
  for (int i = (0); i < (cnt); i++) {
    C.push_back(i);
  }
  res[A[0].second] = C;
  for (int i = (1); i < (n); i++) {
    int c = 1;
    int nx = (i + 1 < n ? A[i + 1].first : 0);
    while (c < A[i].first - 1 && c < (int)C.size() - 2 &&
           (int)C.size() + A[i].first - 2 * (c + 1) >= nx) {
      ++c;
    }
    int id = A[i].second;
    int nv = A[i].first - 1 - c;
    for (int j = (0); j < (c); j++) {
      res[id].push_back(C.back());
      if (j + 1 < c) C.pop_back();
    }
    for (int j = (0); j < (nv); j++) {
      res[id].push_back(cnt);
      C.push_back(cnt);
      ++cnt;
    }
    res[id].push_back(C[0]);
    if ((int)C.size() <= 4) {
      C.push_back(C[0]);
      C.erase(C.begin());
    }
  }
  cout << cnt << endl;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < ((int)res[i].size()); j++) {
      cout << res[i][j] + 1 << ' ';
    }
    cout << endl;
  }
  cerr << (int)C.size() << endl;
  cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
}
