import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i=0; i<n; i++){
            arr[i]=in.nextInt();
 //           System.out.println(arr[i]);
        }
        int cost = 0;
        int num = 1;
        int anum=0;
        int max = arr[n-1];
        while (max>0){
        anum+=num;
        if(anum<n){
        max = arr[n-1-anum];
        num = 0;
        for (int i=0; i<n; i++){
            if(arr[n-i-1]==max){
                num++;
                arr[n-i-1]=0;
            }
//            System.out.println(arr[n-1-i]);
        }
 //      System.out.println("n"+num);
        for(int i =0; i<n; i++){
            if(arr[i]>0){
                arr[i]-=num;
                if(arr[i]<0){
                    arr[i]=0;
                }
            }
        
        }
        int t=num*max;
//      System.out.println(t);
        cost+=t;}
        else{
            break;
        }
        }
        System.out.println(cost);
    }
}
