#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long mx = 1e9 + 9, r = 0;     for (int i = n - 1; i >= 0; i--) {       a[i] = min(mx, a[i]);       r += a[i];       mx = min(mx, max(0ll, a[i] - 1));     }     cout << r <<   n ;     return 0;   }   