#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7LL;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long pwr(long long x, long long n) {
  long long ans = 1;
  while (n) {
    ans *= x;
    n--;
  }
  return ans;
}
void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long dp[n][n];
  memset(dp, -1, sizeof dp);
  vector<pair<long long, long long> > v;
  for (int i = 0; i < n; i++) {
    long long val;
    cin >> val;
    v.push_back(make_pair(val, i));
  }
  sort((v).begin(), (v).end());
  dp[0][n - 1] = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= i; j--) {
      int p = j - i;
      if (p == 0) {
        dp[i][j] += v[0].first * abs(v[0].second - i);
        ans = max(ans, dp[i][j]);
        continue;
      }
      dp[i + 1][j] =
          max(dp[i + 1][j], dp[i][j] + v[p].first * abs(v[p].second - i));
      dp[i][j - 1] =
          max(dp[i][j - 1], dp[i][j] + v[p].first * abs(v[p].second - j));
    }
  }
  cout << ans << endl;
}
