import java.util.*;

public class Baloons {

        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int number = scanner.nextInt();
            int sum = 0;
            int [] arr = new int[number];
            for (int i = 0; i < number; i++) {
                arr[i]=scanner.nextInt();
            }
            for (int i = number - 1; 0 <= i; i--) {
                if (arr[i] > 1) {
                    sum += arr[i];
                    for (int j = i ; 0 < j; j--) {
                        if (arr[j - 1] > 1 & j >= 1 &arr[i]!=arr[j-1]) {
                            arr[j - 1] -= 1;
                        }
                    }
                }
            }
            System.out.println(sum);
        }

}
