#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<long long> a; long long last = 0, uge = 0, potratili = 0;
long long pred, aaaa;

void pristrii() {
	aaaa = 1;
	potratili += a[a.size()-1];
	uge++;
	pred = a[a.size() - 1];
	a.pop_back();
	if (a.size() != 0) {
		while (pred == a[a.size() - 1]) {
			a.pop_back();
			if (a.size() == 0) {
				break;
			}
			aaaa++;
		}
		potratili += (aaaa * pred);
		uge += aaaa;
		for (int i = 0; i < a.size(); i++) {
			if (a[i] == 1) {
				uge += a[i];
				a[i] = 0;
			}
			else if (a[i] == 0) {}
			else {
				a[i] -= aaaa;
			}
		}
	}
	

}

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

	long long n, sum = 0;
	cin >> n;
	a.resize(n);
	for (long long i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (long long i = 0; i < n; i++) {
		sum += a[i];
	}
	sort(a.begin(), a.end());
	for (uge; uge < sum && a[a.size()-1] != 0; uge) {
		pristrii();
		if (a.size() == 0) {
			break;
		}
	}
	cout << potratili << '\n';
}