#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
int n;
int a[MAX_N + 9];
int id[MAX_N + 9];
int ans1;
vector<int> ans2[MAX_N + 9];
vector<int> peri;
bool Cmp(int x, int y) { return a[x] > a[y]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    id[i] = i;
  }
  a[n + 1] = 3;
  id[n + 1] = n + 1;
  sort(id + 1, id + n + 1, Cmp);
  ans1 = a[id[1]];
  for (int i = 1; i <= a[id[1]]; i++) {
    peri.push_back(i);
    ans2[id[1]].push_back(i);
  }
  for (int i = 2; i <= n; i++) {
    int x = id[i];
    int xx = id[i + 1];
    if (peri.size() == 4 && a[x] == 3) {
      ans2[x].push_back(peri[1]);
      ans2[x].push_back(peri[2]);
      ans2[x].push_back(peri[3]);
      peri.erase(peri.begin() + 2);
    } else {
      int d = min(((int)peri.size() + a[x] - a[xx]) / 2, a[x] - 1);
      ans2[x].push_back(peri[0]);
      ans2[x].push_back(peri.back());
      for (int j = 3; j <= d + 1; j++) {
        peri.pop_back();
        ans2[x].push_back(peri.back());
      }
      for (int j = d + 2; j <= a[x]; j++) {
        ans1++;
        peri.push_back(ans1);
        ans2[x].push_back(ans1);
      }
    }
  }
  cout << ans1 << "\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < a[i]; j++) {
      cout << ans2[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
