#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 100;
pair<int, int> p[N];
int n;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
long long dp[N][N];
long long clac(int cnt, int l, int r) {
  if (l > r) return 0;
  if (~dp[l][r]) return dp[l][r];
  long long ans =
      p[cnt].first * abs(p[cnt].second - l) + clac(cnt + 1, l + 1, r);
  ans =
      max(ans, p[cnt].first * abs(p[cnt].second - r) + clac(cnt + 1, l, r - 1));
  return dp[l][r] = ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    p[i] = {x, i};
  }
  sort(p + 1, p + n + 1, cmp);
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", clac(1, 1, n));
  return 0;
}
