#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& v) {
  out << "[";
  for (int i = 0; i < (int)v.size(); i++) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "]";
}
const int maxn = 2005;
long long dp[maxn][maxn];
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<pair<int, int> > b;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b.push_back(make_pair(a[i], i));
  }
  long long res = 0;
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) dp[0][i] = b[0].first * abs(i - b[0].second);
  for (int i = 1; i < n; i++) {
    int v = b[i].first, idx = b[i].second;
    for (int j = 0; j + i < n; j++) {
      dp[i][j] = max(dp[i - 1][j] + v * abs(j + i - idx),
                     dp[i - 1][j + 1] + v * abs(j - idx));
    }
  }
  cout << dp[n - 1][0] << '\n';
  return 0;
}
