#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a(2010);
int dp[2010][2010];
template <class T>
inline bool chmax(T &a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    a.push_back(make_pair(x, i));
  }
  sort(a.begin(), a.end(), greater<pair<int, int> >());
  int ans = -1;
  for (int l = 0; l < n; l++) {
    for (int r = 0; r < n; r++) {
      if (l + r == n) {
        chmax(ans, dp[l][r]);
        break;
      } else {
        chmax(dp[l + 1][r],
              dp[l][r] + a[l + r].first * abs(l - a[l + r].second));
        chmax(dp[l][r + 1],
              dp[l][r] + a[l + r].first * abs((n - 1 - r) - a[l + r].second));
      }
    }
  }
  printf("%d\n", ans);
}
