#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll N;
vector<P> A;  //(活性度、番号)
vector<vector<ll>> dp(2010, vector<ll>(2010, 0));
ll res = 0;

int main(){
  cin >> N;

  ll a;
  for(ll i = 1; i <= N; i++){ cin >> a; A.push_back({a, i}); }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());  //活性度大きい順

  for(int i = 0; i <= N; i++){  //活性度の高い順かつ合計
      ll ac = A[i].first, n = A[i].second;  //活性度とナンバー
      for(int j = 0; j <= i; j++){
        int k = i - j;
        dp[j+1][k] = max(dp[j+1][k], dp[j][k] + ac * abs(j+1-n));
        dp[j][k+1] = max(dp[j][k+1], dp[j][k] + ac * abs(N-k-n));
    }
  }

  for(int i = 0; i <= N; i++) res = max(res, dp[i][N-i]);
  cout << res << endl;
  return 0;
}


  



