#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define X first
#define Y second

int main() {
	int n;cin>>n;
	lld a[n+1];
	for(int i=0;i<n;i++)cin>>a[i+1];
	int visit[n+1]={0};
	int l = 1,r=n;
	lld c=0;int index;
	while(l<=r)
	{
		lld ans = 0;
		for(int i=1;i<=n;i++)
		{
			if(visit[i]==0)
			{
				lld b = max(a[i]*abs(i-l),a[i]*abs(i-r));
				if(b>ans)
				{
					ans=b;
					index = i;
				}
			}
		}
		visit[index]=1;
		if(abs(index-l)>abs(index-r))
		l++;
		else 
		r--;
		c+=ans;
	}
	cout<<c<<endl;
	return 0;
}