#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
long int M = 1e+9 + 7;
int main(void) {
  int n;
  cin >> n;
  vi a(n), mx(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  vi a_cp(n);
  a_cp = a;
  for (int i = 0; i < (n); ++i) {
    int mxj = 0;
    for (int j = 1; j < n; ++j) {
      if (a_cp[j] > a_cp[mxj]) mxj = j;
    }
    mx[i] = mxj;
    a_cp[mxj] = 0;
  }
  vvl dp(n + 1, vl(n));
  for (int i = 0; i < (n); ++i) {
    int pi = mx[i];
    for (int l = 0; l < (i + 1); ++l) {
      int r = i - l;
      (dp[i + 1][l + 1] = max(dp[i + 1][l + 1], dp[i][l] + ll(pi - l) * a[pi]));
      (dp[i + 1][l] =
           max(dp[i + 1][l], dp[i][l] + ll((n - r - 1) - pi) * a[pi]));
    }
  }
  ll ans = 0;
  for (int i = 0; i < (n + 1); ++i) (ans = max(ans, dp[n][i]));
  cout << ans << endl;
  return 0;
}
