#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, l[N], u[N], m;
pair<int, int> a[N];
vector<int> ans[N];
map<pair<int, int>, bool> Map;
inline void upd(int u, int first) {
  Map[pair<int, int>(u, first)] = Map[pair<int, int>(first, u)] = 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].first), a[i].second = i;
  sort(a + 1, a + 1 + n), a[0].first = 3, l[n] = a[n].first;
  for (int i = n - 1; i; i--) {
    int _ = l[i + 1] - a[i].first + 2;
    if (_ == 2) _ = 4;
    l[i] =
        _ < a[i - 1].first ? a[i - 1].first + (a[i - 1].first & 1 ^ _ & 1) : _;
  }
  cerr << l[1] << endl, m = l[1];
  for (int i = 1; i <= m; i++) u[i] = i, upd(i, i % m + 1);
  for (int i = 1; i < n; i++) {
    int ex = l[i + 1] + a[i].first - l[i] - 2 >> 1,
        s = l[i] - a[i].first + ex + 1, tmp = u[l[i]];
    if (!ex) {
      while (Map[pair<int, int>(u[s], u[s + a[i].first - 1])]) s--;
      upd(u[s], u[s + a[i].first - 1]);
      for (int j = s; j < s + a[i].first; j++) ans[a[i].second].push_back(u[j]);
      for (int j = s + a[i].first - 1; j <= l[i]; j++)
        u[j - a[i].first + 2] = u[j];
    } else {
      for (int j = s; j <= l[i]; j++) ans[a[i].second].push_back(u[j]);
      for (int j = m + ex; j > m; j--) ans[a[i].second].push_back(j);
      for (int j = s + 1; j <= s + ex; j++) u[j] = ++m, upd(u[j - 1], u[j]);
      u[s + ex + 1] = tmp, upd(u[s + ex], u[s + ex + 1]);
    }
  }
  for (int i = 1; i <= a[n].first; i++) ans[a[n].second].push_back(u[i]);
  printf("%d\n", m);
  for (int i = 1; i <= n; i++, puts(""))
    for (int j : ans[i]) printf("%d ", j);
  return 0;
}
