#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
long long int dp[2010][2010];
int main(void) {
  long long int n;
  long long int ans = 0;
  cin >> n;
  vector<pair<long long int, long long int> > act;
  for (long long int i = 0; i < (n); i++) {
    long long int tmp;
    cin >> tmp;
    act.push_back(make_pair(tmp, (i + 1)));
  }
  sort(begin(act), end(act), greater<pair<long long int, long long int> >());
  dp[1][0] = (act[0].first) * abs((act[0].second - 1));
  dp[0][1] = (act[0].first) * abs((act[0].second - n));
  for (long long int i = 2; i <= n; i++) {
    for (long long int y = 0; y <= i; y++) {
      long long int x = i - y;
      if (y == 0) {
        dp[i][0] =
            dp[i - 1][0] + (act[i - 1].first) * abs(act[i - 1].second - i);
      }
      if (x == 0) {
        dp[0][i] = dp[0][i - 1] +
                   (act[i - 1].first) * abs(act[i - 1].second - (n - i));
      } else {
        dp[x][y] = max(
            dp[x - 1][y] + (act[i - 1].first) * abs((act[i - 1].second - (x))),
            dp[x][y - 1] +
                (act[i - 1].first) * abs((act[i - 1].second - (n - (y - i)))));
      }
      ans = max(ans, dp[x][y]);
    }
  }
  cout << ans << endl;
  return 0;
}
