#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<pii> a(n);
	rep(i, n){ cin >>a[i].first; a[i].second = i; }
	sort(a.rbegin(), a.rend());
	ll ans = 0;
	vector<VL> dp(n+1, VL(n+1));
	rep(i, n) rep(j, n){
		if(i+j == n){
			ans = max(ans, dp[i][j]);
			break;
		}
		amax(dp[i+1][j], dp[i][j] + abs(a[i+j].second - i) * (ll)a[i+j].first );
		amax(dp[i][j+1], dp[i][j] + abs(a[i+j].second - (n-1-j)) * (ll)a[i+j].first );
	}
	cout << ans <<"\n";
	return 0;
}

        dp[l+1][r] = max(dp[l+1][r], dp[l][r] + abs(ind - l) * activeness)
        dp[l][r+1] = max(dp[l][r+1], dp[l][r] + abs(ind - (n-1-r)) * activeness)
