import java.util.Scanner;

import java.util.Scanner;

public class Balls {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[] ballBoxes = new int[n];
        for (int i = 0; i < n; i++) {
            ballBoxes[i] = in.nextInt();
        }

        int last = n - 1;
        int took = 0;
        int price = 0;
        int nextPrice = ballBoxes[last];
        for (int i = last; i > 0; i--) {
            int currentBox = ballBoxes[i];
            int nextBox = ballBoxes[i - 1];

            price += nextPrice;
            took++;

            if (nextBox != currentBox) {
                nextPrice = nextBox - took;
            }

            if (nextPrice <= 0) {
                break;
            }
        }
        System.out.println(price);
    }
}
