#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0;i < n;i++) {
cin >> arr[i];
}
int cnt = 0;
int cnt_i = 0;
for (int i = n-1;i >= 0;i--) {
cnt_i++;
if (arr[i] < cnt_i) {
cnt+=arr[i];
cnt_i = arr[i];
}
else {
cnt+=cnt_i;
}
}
cout << cnt;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: