#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
#ifndef ONLINE_JUDGE
    #define my_dbg
#endif
 
#define speed_up ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define open_files freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#define all(x) x.begin(), x.end()
 
typedef long long ll;
 
using namespace std;
 
void solve() {
    int n;
    cin >> n;
    vector<int> vec(n);
    map<int, int> cnt;
    ll total = 0;
    for (int i = 0; i < n; ++i) {
        cin >> vec[i];  
        cnt[vec[i]]++;
    }
    reverse(vec.begin(), vec.end());
    int shift = 0;
    for (int i : vec) {
        if (i - shift < 1) break;
        total += max(i - shift, 1) * cnt[i];
        cnt[i] = 0;
        shift++;
    }
    cout << total << "\n";
}   
 
signed main() {
 
    speed_up
 
#ifdef my_dbg
    open_files
    clock_t processor_time = clock();
#endif
 
    signed t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
 
#ifdef my_dbg
    cout << "\nTIME : " << (clock() - processor_time) / (double)CLOCKS_PER_SEC;
#endif
 
}