
import java.util.Scanner;

public class Main {

    private static int n;

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

        int[] mas = new int[n];
        int money = 0;

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


        for(int i=n-1; i>=0; i--){
            money+=mas[i];
            for (int j = 0; j < i; j++) {
                if(mas[j]!=mas[i] && mas[j]!=0) mas[j]--;
            }

            mas[i]=0;
        }
        System.out.println(money);

    }
}
