#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<ll> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];
  vector<vector<ll>> dp(N + 1, vector<ll>(N + 1));
  for (int l = 0; l < N; l++) {
    for (int r = 0; l + r < N; r++) {
      ll lp = l;
      ll rp = N - r - 1;
      int p = l + r;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + abs(p - lp) * v[p]);
      dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + abs(p - rp) * v[p]);
    }
  }
  ll res = 0;
  for (int i = 0; i <= N; i++) {
    res = max(res, dp[i][N - i]);
  }
  cout << res << endl;
}
