#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 + 1][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[n][0][n - 1] = 0;
  for (int p = n; p > 0; p--) {
    for (int i = 0; i < n; i++) {
      for (int j = n - 1; j >= 0; j--) {
        if (dp[p][i][j] != -1) {
          dp[p - 1][i + 1][j] =
              max(dp[p - 1][i + 1][j],
                  dp[p][i][j] + v[p - 1].first * abs(v[p - 1].second - i));
          dp[p - 1][i][j - 1] =
              max(dp[p - 1][i][j - 1],
                  dp[p][i][j] + v[p - 1].first * abs(v[p - 1].second - j));
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) ans = max(ans, dp[0][i][j]);
  cout << ans << endl;
}
