#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 20;
int n, x, dp[N][N];
vector<pair<int, int>> v;
int f(int l, int r) {
  int &ans = dp[l][r];
  if (ans != -1) return ans;
  int i = l + (n - 1 - r);
  int old_pos = v[i].second;
  if (l == r) return ans = v[i].first * abs(l - old_pos);
  return ans = max(v[i].first * abs(l - old_pos) + f(l + 1, r),
                   v[i].first * abs(r - old_pos) + f(l, r - 1));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    v.push_back({x, i});
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dp[i][j] = -1;
  sort(v.rbegin(), v.rend());
  printf("%d", f(0, n - 1));
}
