#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
const long long MOD = 1e9 + 7;
const int MAX_N = 2005;
int n;
vector<pair<long long, int>> A(MAX_N);
vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_N));
void dfs(int x, int l) {
  if (x == n) return;
  dp[x + 1][l + 1] =
      max(dp[x + 1][l + 1], dp[x][l] + A[x].first * abs(A[x].second - l));
  dfs(x + 1, l + 1);
  dp[x + 1][l] =
      max(dp[x + 1][l],
          dp[x][l] + A[x].first * abs(A[x].second - (n - 1 - (x - l))));
  dfs(x + 1, l);
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    long long a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  dfs(0, 0);
  long long ans = 0;
  for (int i = 0; i < (n); ++i) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << "\n";
  return 0;
}
