#include <bits/stdc++.h>
using namespace std;
#define int long long

int xin(){
    int n = 0;
    scanf("%lld", &n);
    return n;
}
void exxa() {
    int n;
    cin >> n;
    multiset<int>s;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    int res = 0;
    while (*max_element(s.begin(), s.end()) > 0) {
        //int mx = *max_element(s.begin(), s.end());
        //s.erase(s.find(mx));
        //auto mx = *(s.begin()+s.size());
        //int mx = *s.end();
        int mx = *max_element(s.begin(), s.end());
        res += mx;
        auto mxf = s.find(mx);
        s.erase(mxf);
        multiset <int> ::iterator it = s.begin();
        int n=s.size();
        for (int i = 0; i < n; i++) {
            
            int c = *it;
            if(c == mx) break;
            s.erase(it);
            s.insert(c-1);
            it++;
            cout<<c<<' ';
            for(auto i : s) cout<<i<<' ';
            cout<<endl;
        }
        cout<<endl;
        
    }
    cout << res;
}
int32_t main()
{
    //int t = xin();
    int t = 1;
    while (t--) exxa();
}