#include <bits/stdc++.h>
using namespace std;
bool isvowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true;
  return false;
}
long long int isprime(long long int n) {
  long long int ans = 1;
  for (long long int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) ans = i;
  }
  return ans;
}
long long int power(long long int a, long long int b, long long int m) {
  if (b == 0) return 1;
  if (b == 1) return a % m;
  long long int temp = power(a, b / 2, m);
  if (b % 2 == 0)
    return ((temp % m) * (temp % m)) % m;
  else
    return ((((temp % m) * (temp % m)) % m) * a % m) % m;
}
long long int c(long long int n, long long int k) {
  long long int C[n + 1][k + 1];
  long long int i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= min(i, k); j++) {
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j - 1] % 1000000007 + C[i - 1][j]) % 1000000007;
    }
  }
  return C[n][k] % 1000000007;
}
long long int modInverse(long long int a, long long int m) {
  long long int m0 = m;
  long long int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long int func(long long int n) {
  long long int ans = 0;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (i / 10 == 0)
        ans += 1 + func(i) * func(n / i);
      else
        ans += func(i) * func(n / i);
    }
  }
  return ans;
}
long long int dp[2001][2001];
long long int check(vector<pair<long long int, long long int> > v,
                    long long int l, long long int r, long long int i) {
  if (l > r) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  long long int ans = 0;
  long long int p1 = v[i].first;
  long long int p2 = v[i].second;
  ans = max(p1 * (p2 - l) + check(v, l + 1, r, i + 1),
            p1 * (r - p2) + check(v, l, r - 1, i + 1));
  return dp[l][r] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    vector<pair<long long int, long long int> > v;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      pair<long long int, long long int> p = make_pair(a[i], i);
      v.push_back(p);
    }
    memset(dp, -1, sizeof(dp));
    long long int left = 0, right = n - 1;
    sort(v.begin(), v.end(), greater<pair<long long int, long long int> >());
    cout << check(v, left, right, 0);
  }
}
