#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
long long dp[2000 + 20][2000 + 20];
vector<pair<int, int> > ch;
int n;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    pair<int, int> now;
    cin >> now.first;
    now.first *= -1;
    now.second = i;
    ch.push_back(now);
  }
  sort(ch.begin(), ch.end());
  for (int i = 1; i <= n; ++i) ch[i - 1].first *= -1;
  for (int i = 1; i <= n; ++i) {
    long long now = ch[i - 1].first;
    long long pos = ch[i - 1].second;
    for (int j = 0; j <= i; ++j) {
      if (j != i)
        dp[i][j] =
            max(dp[i][j],
                dp[i - 1][j] + now * (long long)(abs(n - (i - 1 - j) - pos)));
      if (j)
        dp[i][j] =
            max(dp[i][j], dp[i - 1][j - 1] + now * (long long)(abs(j - pos)));
    }
  }
  long long res = 0;
  for (int i = 0; i <= n; ++i) {
    res = max(res, dp[n][i]);
  }
  cout << res << endl;
  return 0;
}
