Problem: Ujan has finally cleaned up his house and now wants to decorate the interior. He decided to place a beautiful carpet that would really tie the guest room together.

He is interested in carpets that are made up of polygonal patches such that each side of a patch is either a side of another (different) patch, or is an exterior side of the whole carpet. In other words, the carpet can be represented as a planar graph, where each patch corresponds to a face of the graph, each face is a simple polygon. The perimeter of the carpet is the number of the exterior sides. 

Ujan considers a carpet beautiful if it consists of f patches, where the i-th patch has exactly a_i sides, and the perimeter is the smallest possible. Find an example of such a carpet, so that Ujan can order it!

Input

The first line of input contains a single integer f (1 ≤ f ≤ 10^5), the number of patches in the carpet. 

The next line contains f integers a_1, …, a_f (3 ≤ a_i ≤ 3⋅ 10^5), the number of sides of the patches. The total number of the sides of the patches a_1 + … + a_f does not exceed 3⋅10^5.

Output

Output the description of the carpet as a graph. 

First, output a single integer n (3 ≤ n ≤ 3 ⋅ 10^5), the total number of vertices in your graph (the vertices must be numbered from 1 to n). 

Then output f lines containing the description of the faces. The i-th line should describe the i-th face and contain a_i distinct integers v_{i,1}, …, v_{i,a_i} (1 ≤ v_{i,j} ≤ n), which means that the vertices v_{i,j} and v_{i,(j mod{a_i})+1} are connected by an edge for any 1 ≤ j ≤ a_i.

The graph should be planar and satisfy the restrictions described in the problem statement. Its perimeter should be the smallest possible. There should be no double edges or self-loops in the graph. The graph should be connected. Note that a solution always exists; if there are multiple solutions, output any of them.

Examples

Input


2
3 3


Output


4
2 1 4 
1 2 3 


Input


3
5 3 5


Output


6
1 2 3 4 5
4 5 6
1 3 4 6 5

Note

In the first sample, the two triangular faces are connected by a single edge, which results in the minimum perimeter 4.

The figure shows one possible configuration for the second sample. The minimum perimeter in this case is 3. 

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
pair<int, int> compute_range(int x, pair<int, int> prev_range) {
  int prev_l, prev_r;
  tie(prev_l, prev_r) = prev_range;
  int r = x + prev_r - 2;
  if (x > prev_r) {
    return make_pair(x - prev_r + 2, r);
  } else if (x < prev_l) {
    return make_pair(prev_l - x + 2, r);
  } else {
    if ((x - prev_l) % 2 == 0) {
      return make_pair(4, r);
    } else {
      return make_pair(3, r);
    }
  }
}
int get_prev_tgt(int tgt, pair<int, int> prev_range, int x) {
  int prev_l, prev_r;
  tie(prev_l, prev_r) = prev_range;
  if (x > prev_r) {
    return prev_r;
  } else if (x < prev_l) {
    if (prev_l + x - 2 >= tgt) {
      return prev_l;
    } else if (prev_r - x + 2 <= tgt) {
      return prev_r;
    } else {
      return tgt - x + 2;
    }
  } else {
    if ((x - prev_l) % 2 == 0) {
      if (tgt <= 2 * x - 2) {
        return x;
      } else {
        return tgt - x + 2;
      }
    } else {
      if (tgt <= 2 * x - 3) {
        return x - 1;
      } else {
        return tgt - x + 2;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int f;
  cin >> f;
  vector<int> rev_ord(f);
  vector<int> a(f);
  for (int i = 0; i < f; ++i) {
    cin >> a[i];
  }
  {
    vector<pair<int, int>> sort_a(f);
    for (int i = 0; i < f; ++i) {
      sort_a[i] = make_pair(a[i], i);
    }
    sort(sort_a.begin(), sort_a.end());
    for (int i = 0; i < f; ++i) {
      a[i] = sort_a[i].first;
      rev_ord[sort_a[i].second] = i;
    }
  }
  vector<pair<int, int>> range(f);
  range[0] = make_pair(a[0], a[0]);
  for (int i = 1; i < f; ++i) {
    range[i] = compute_range(a[i], range[i - 1]);
  }
  vector<int> rules(f, 0);
  for (int i = f - 1, tgt = range.back().first; i > 0; --i) {
    int prev_tgt = get_prev_tgt(tgt, range[i - 1], a[i]);
    rules[i] = (a[i] + prev_tgt - tgt) / 2;
    tgt = prev_tgt;
  }
  {
    vector<int> bad_rules, good_rules;
    for (int i = 1; i < f; ++i) {
      if (a[i] == 3) continue;
      if (rules[i] == 1) {
        bad_rules.push_back(i);
      } else if (rules[i] > 2) {
        good_rules.push_back(i);
      }
    }
    reverse(good_rules.begin(), good_rules.end());
    while (false && !bad_rules.empty() && !good_rules.empty()) {
      int u = bad_rules.back();
      int v = good_rules.back();
      rules[u]++;
      rules[v]--;
      bad_rules.pop_back();
      if (rules[v] == 2) {
        good_rules.pop_back();
      }
    }
  }
  vector<vector<int>> ans(f);
  int v_cnt = a[0];
  vector<int> cur_hull(a[0]);
  for (int i = 0; i < a[0]; ++i) {
    cur_hull[i] = i;
  }
  ans[0] = cur_hull;
  int idx = 1;
  if (a[0] == 3) {
    int tgt = 3;
    while (idx < f && a[idx] == 3) {
      int del_e = rules[idx];
      tgt = tgt + 3 - 2 * del_e;
      ++idx;
    }
    int cnt = idx - (tgt - 2) + 1;
    for (int i = 1; i < cnt; i += 2) {
      ans[i] = {0, v_cnt - 1, v_cnt};
      ans[i + 1] = {1, v_cnt - 1, v_cnt};
      cur_hull.back() = v_cnt;
      ++v_cnt;
    }
    for (int i = cnt; i < idx; ++i) {
      ans[i] = {0, v_cnt - 1, v_cnt};
      cur_hull.push_back(v_cnt);
      ++v_cnt;
    }
  }
  for (int i = idx; i < f; ++i) {
    ans[i].reserve(a[i]);
    int del_e = rules[i];
    int add_e = a[i] - del_e;
    ans[i].push_back(cur_hull.back());
    for (int j = 0; j < del_e - 1; ++j) {
      cur_hull.pop_back();
      ans[i].push_back(cur_hull.back());
    }
    for (int j = 0; j < add_e - 1; ++j) {
      cur_hull.push_back(v_cnt);
      ans[i].push_back(cur_hull.back());
      v_cnt++;
    }
    ans[i].push_back(0);
  }
  cout << v_cnt << endl;
  for (int i = 0; i < f; ++i) {
    for (int v : ans[rev_ord[i]]) {
      cout << v + 1 << ' ';
    }
    cout << endl;
  }
  return 0;
}