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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long n;
    cin >> n;
    long long a[n] = {0};
    for (long long i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    long long b[a[n-1]] = {0};
    for (long long i = 0; i < n; i++) b[a[i] - 1]++;
    long long n_c = n;
    long long summ = 0;
   // for (long long i = 0; i < n; i++) cout << b[i] << " ";
    //cout << endl;
    while (n_c > 0) {
        for (long long i = 0; i < n; i++) cout << b[i] << " ";
        cout << endl;
        long long i = a[n-1] - 1;
        while (b[i] == 0) {
            i--;
        }
        cout << i + 1 << " " << b[i] << endl;
        summ += (i + 1) * b[i];
        n_c -= b[i];
        //cout << b[0] << endl;
        for (long long e = 0; e < i; e++) {
            if (e < b[i]) {
                n_c -= b[e];
                b[e] = 0;
            } else {
                b[e-b[i]] = b[e];
                cout << "ok " << b[e-b[i]] << endl;
                b[e] = 0;
            }
        }
        b[i] = 0;
    }
    cout << summ;
}
