#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	map <ll,ll> m;
	cin >> n;
	for(int x, i=0;i<n;i++) {
		cin >> x;
		m[x]++;
	}
	ll k=1, ans=0, h = m.size();
	while(h>0) {
		ll b[3]={0};
		for(auto x : m) {
			if(x.second != 0) {
				if(b[0] < x.first) {
					b[0] = x.first;
					b[1] = x.second;
				}
			}
		}
		k=1;
		for(auto x : m) {
			if(x.second != 0) {
				if(k==h) {
					ans += x.first * x.second;
					m[x.first] = 0;
					h--;
				}
				else {
					if(x.first-b[1] <= 0) {
						m[x.first] = 0;
						k--; h--;
					}
					else {
						m[x.first-b[1]] = x.second;
						m[x.first] = 0;
					}
					k++;
				}
			}
		}
	}
	cout << ans;
	return 0;
}