#include <bits/stdc++.h>
const bool debug = false;
using namespace std;
const long long MOD = 1000000007;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a;
  for (int(i) = 0; (i) < (n); (i)++) {
    long long tmp;
    cin >> tmp;
    a.emplace_back(tmp, i);
  }
  if (n == 2) {
    cout << a[0].first + a[1].first << endl;
    return 0;
  }
  vector<bool> chk(n, true);
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
  sort(begin((a)), end((a)), greater<pair<long long, long long>>());
  for (int(i) = 0; (i) < (n); (i)++) {
    for (int(j) = 0; (j) < (i + 1); (j)++) {
      long long place = a[i].second, value = a[i].first;
      if (place != j) {
        chmax(dp[i + 1][j + 1], dp[i][j] + value * abs(place - j));
      }
      if (place != n - 1 - i + j) {
        chmax(dp[i + 1][j], dp[i][j] + value * abs(n - 1 - i + j - place));
      }
    }
  }
  long long res = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    chmax(res, dp[n][i]);
  }
  cout << res << endl;
  return 0;
}
