#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e3 + 4;
vector<pair<int, int>> v;
int n;
long long dp[N][N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int val;
    scanf("%d", &val);
    v.emplace_back(val, i);
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dp[i][j] = (-1e18);
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (j <= i) {
        int right = j + (n - 1 - i);
        dp[i + 1][j + 1] =
            max(dp[i + 1][j + 1], dp[i][j] + v[i].first * abs(v[i].second - j));
        dp[i + 1][j] =
            max(dp[i + 1][j], dp[i][j] + v[i].first * abs(v[i].second - right));
      }
  }
  long long ans = 0;
  for (int i = 0; i < n + 1; i++) ans = max(ans, dp[n][i]);
  printf("%lld", ans);
  return 0;
}
