#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} ;
// } fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	int r, l;
	int res = 0;
	vector<int> A, ans;
	vector<vector<int>> dp;
	vector<pair<int,pair<int,int>>> hoge;
	
	cin>>N;
	
	r = N-1;
	l = 0;
	
	A.resize(N);
	ans.resize(N);
	hoge.resize(N);
	dp.resize(N+1, vector<int>(N+1));
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		hoge[i] = make_pair(A[i], make_pair((int)max(N-i-1,i), i));
	}
	
	sort(hoge.begin(), hoge.end(), greater<pair<int,pair<int,int>>>());
	
	for(int i = 0; i < N; i++){
		// cout<<endl<<"i = "<<i<<" hoge "<<hoge[i].first<<endl;
		for(int j = 0; j <= i; j++){
			int a = j, b = N + j - i;
			// cout<<"a = "<<a<<" "<<b<<" dp "<<dp[a][b]<<endl;
			dp[a+1][b] = max(dp[a][b] + hoge[i].first * abs(a-hoge[i].second.second), dp[a+1][b]);
			dp[a][b-1] = max(dp[a][b] + hoge[i].first * abs(b-1-hoge[i].second.second), dp[a][b-1]);
		}
	}
	
	for(int j = 0; j <= N; j++){
		int a = j, b = N - j;
			
		res = max(res, dp[a][b]);
	}
	
	cout<<res<<endl;
	
	return 0;
}
