#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
const int mod = 1e9 + 7;
int a[maxn];
long long dp[maxn][maxn];
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v.push_back(make_pair(a[i], i));
  }
  sort(v.begin(), v.end(), cmp);
  dp[1][n] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      int l = j + 1, r = n - i + j;
      if (l - 1 >= 1)
        dp[l][r] =
            max(dp[l][r],
                dp[l - 1][r] + v[i - 1].first * abs(v[i - 1].second - l + 1));
      if (r + 1 <= n)
        dp[l][r] =
            max(dp[l][r],
                dp[l][r + 1] + v[i - 1].first * abs(v[i - 1].second - r - 1));
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[i][i] + v[n - 1].first * abs(i - v[n - 1].second));
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
