#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  long long int ans = 0;
  map<long long int, long long int, greater<long long int> > count;
  for (long long int i = 0; i < n; i++) cin >> a[i], count[a[i]]++;
  long long int cmin = INT_MAX;
  for (auto it = count.begin(); it != count.end(); it++) {
    long long int t = 0;
    long long int a = max(t, min(it->first, cmin));
    long long int fir = a * (a + 1) / 2;
    long long int b = max(t, min(a - it->second, cmin));
    long long int sec = (b + 1) * (b) / 2;
    cmin = b;
    ans += fir - sec;
  }
  cout << ans;
}
