import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
Max(arr,n);
}
}
//n:数组长度
private static void Max(int[] arr, int n) {
int low=0;
int high=arr.length-1;
int sum=0;
int day=1;
if(arr.length<=0||arr==null){
return;
}
while(low<=high){
if(arr[low]<=arr[high]){
sum+=arr[low]*day;
day++;
low++;
}else{
sum+=arr[high]*day;
day++;
high--;
}
}
System.out.println(sum);
}
}