#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>

using namespace std;

template <class T> inline void chmax(T &x, const T &y) {if (x < y) x = y;}

typedef pair<int, int> P;

int n;
P p[2000];
long long dp[2020][2020];

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    p[i] = make_pair(a, i);
  }

  sort(p, p + n);

  for (int len = 0; len < n; len++) {
    for (int i = 0; i < n-len; i++) {
      chmax(dp[i][len + 1], dp[i][len] + (long long)p[len].first * abs(p[len].second - (i + len)));
      chmax(dp[i][len + 1], dp[i+1][len] + (long long)p[len].first * abs(p[len].second - i));
    }
  }

  cout << dp[0][n] << endl;
  return 0;
}
