#include <bits/stdc++.h>
using namespace std;
const double h = 1e-6;
const int MAX_ = 200005;
inline long long int mul(long long int a, long long int b) {
  return (a * 1ll * b) % 1000000007;
}
inline long long int sub(long long int a, long long int b) {
  long long int c = a - b;
  if (c < 0) c += 1000000007;
  return c;
}
inline long long int add(long long int a, long long int b) {
  long long int c = a + b;
  if (c > 1000000007) c -= 1000000007;
  return c;
}
long long int sqr(long long int x) { return x * x; }
const int nax = 2005;
struct node {
  int id, val;
};
node arr[nax];
int n;
int dp[nax][nax];
bool rule(node a, node b) { return a.val > b.val; }
int get_ac(int cur, int l, int r) {
  if (cur >= n) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  int go_left = get_ac(cur + 1, l + 1, r) + arr[cur].val * abs(l - arr[cur].id);
  int go_right =
      get_ac(cur + 1, l, r - 1) + arr[cur].val * abs(r - arr[cur].id);
  dp[l][r] = max(go_right, go_left);
  return dp[l][r];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i].val;
    arr[i].id = i;
  }
  sort(arr, arr + n, rule);
  memset(dp, -1, sizeof(dp));
  cout << get_ac(0, 0, n - 1);
}
