#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 1e9+7;
const long double pi = acos(-1);

// FOR DEBUGGING
// vector<string> vec_splitter(string s) {
// 	s += ',';
// 	vector<string> res;
// 	while(!s.empty()) {
// 		res.push_back(s.substr(0, s.find(',')));
// 		s = s.substr(s.find(',') + 1);
// 	}
// 	return res;
// }

// void debug_out(
// vector<string> __attribute__ ((unused)) args,
// __attribute__ ((unused)) int idx, 
// __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
// template <typename Head, typename... Tail>
// void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
// 	if(idx > 0) cerr << ", ";
// 	else cerr << "Line(" << LINE_NUM << ") ";
// 	stringstream ss; ss << H;
// 	cerr << args[idx] << " = " << ss.str();
// 	debug_out(args, idx + 1, LINE_NUM, T...);
// }

// #ifndef XOX
// #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
// #else
// #define debug(...) 42
// #endif

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	int n;
	cin >> n;
	vector <ll> a(n);
	rep0(i,n){
		cin >> a[i];
	}
	
	ll ans = 0;
	int it1 = 0, it2 = n-1;
	vector <int> vis(n,0);
	rep0(i,n){
		ll mx = -1, it = -1;
		rep0(j,n){
			if(!vis[j]){
				ll tmp = max(abs(j-it1),abs(j-it2));
				tmp *= a[j];
				if(tmp>mx){
					mx = tmp;
					it = j;
				}
			}
		}
		ans += mx;
		vis[it] = 1;
		if(abs(it-it1)>=abs(it-it2)) it1++;
		else it2--;
	}
	cout << ans;

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}