#include<bits/stdc++.h>
using namespace std;
int n , v[2005];
int main(){
cin >> n;
for(int i = 1 ; i <= n ; i++)
cin >> v[i];
int l = 1 , t = 1 , y = n ;
long long s = 0;
while(l != y){
if(v[l] <= v[y]){
s += v[l] * t;
l++;
}else{
s += v[y] * t;
y--;
}
t++;
}
cout << s + v[l] * t;
}
27大分
玄关求调