#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  V<int> f(N);
  for (int i = 0; i < (int)(N); i++) cin >> f[i];
  V<int> idx(N);
  for (int i = 0; i < (int)(N); i++) idx[i] = i;
  sort(idx.begin(), idx.end(), [&](int a, int b) { return f[a] > f[b]; });
  sort(f.begin(), f.end(), greater<int>());
  VV<int> ans(N);
  int S = f[0];
  V<int> d(N);
  for (int i = 1; i <= (int)(N - 1); i++) {
    d[i] = -(f[i] - 2);
    S += d[i];
  }
  for (int i = 1; i <= (int)(N - 1); i++) {
    if (S >= 3) break;
    while (d[i] + 2 <= f[i] - 2) {
      if (S >= 3) break;
      S += 2, d[i] += 2;
    }
  }
  true;
  true;
  true;
  using P = pair<int, int>;
  set<P> es;
  int X = f[0];
  V<int> c(X);
  for (int i = 0; i < (int)(X); i++) c[i] = i;
  auto ADD = [&](int i, V<int>& c) {
    ans[idx[i]] = c;
    int K = c.size();
    for (int i = 0; i < (int)(K); i++) {
      es.insert(P(c[i], c[(i + 1) % K]));
      es.insert(P(c[(i + 1) % K], c[i]));
    }
  };
  ADD(0, c);
  for (int i = 1; i <= (int)(N - 1); i++) {
    int n = c.size();
    int y = (f[i] + d[i]) / 2;
    int x = f[i] - y;
    true;
    true;
    true;
    true;
    if (y == 1 && es.count(P(c[n - 1], c[n - 1 - x]))) {
      rotate(c.begin(), c.begin() + 1, c.end());
    }
    if (y == 1 && es.count(P(c[n - 1], c[n - 1 - x]))) {
      assert(0);
    }
    V<int> ci, path;
    for (int j = 0; j < (int)(x + 1); j++) ci.push_back(c[n - 1 - j]);
    for (int j = 0; j < (int)(y - 1); j++) path.push_back(X++);
    ci.insert(ci.end(), path.begin(), path.end());
    ADD(i, ci);
    int LAST = c.back();
    for (int i = 0; i < (int)(x); i++) c.pop_back();
    c.insert(c.end(), path.begin(), path.end());
    c.push_back(LAST);
  }
  cout << X << endl;
  for (int i = 0; i < (int)(N); i++) {
    for (int v : ans[i]) cout << v + 1 << " ";
    cout << '\n';
  }
}
