#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, k;
vector<int> ans[maxn];
deque<int> p;
pair<int, int> a[maxn];
inline vector<int> Maintain(int y, int num) {
  vector<int> q;
  for (int i = (1), _end_ = (y - num); i <= _end_; ++i) {
    q.push_back(p.back());
    p.pop_back();
  }
  p.push_back(q.back());
  for (int i = (1), _end_ = (num); i <= _end_; ++i) {
    q.push_back(++k);
    p.push_back(k);
  }
  p.push_back(q.front());
  p.push_front(p.back());
  p.pop_back();
  return q;
}
int main() {
  scanf("%d", &n);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  for (int i = (1), _end_ = (a[n].first); i <= _end_; ++i) {
    p.push_back(++k);
    ans[a[n].second].push_back(k);
  }
  for (int i = n - 1; i >= 2; --i) {
    if (p.size() - a[i].first + 2 >= a[i - 1].first)
      ans[a[i].second] = Maintain(a[i].first, 0);
    else {
      int num = 0, x = p.size() - a[i].first + 2;
      while (x < a[i - 1].first) {
        x += 2;
        ++num;
      }
      ans[a[i].second] = Maintain(a[i].first, num);
    }
  }
  if (n > 1) ans[a[1].second] = Maintain(a[1].first, p.size() == a[1].first);
  printf("%d\n", k);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    for (auto it : ans[i]) printf("%d ", it);
    puts("");
  }
  return 0;
}
