#include<iostream>
#include<deque>
using namespace std;
int n;
int sum;
deque<int> dq;
void beat(int a, int b);
int price;
int main()
{
freopen("treats.in","r",stdin);
freopen("treats.out","w",stdout);
cin >> n;
for(int i = 0; i < n; ++i)
{
int t;
cin >> t;
dq.push_back(t);
}
while(price < n)
{
int x = dq.front();
int y = dq.back();
beat(x, y);
}
cout << sum << endl;
return 0;
}
void beat(int a, int b)
{
price++;
if(a * price < b * price)
{
sum += a * price;
dq.pop_front();
}
else
{
sum += b * price;
dq.pop_back();
}
}