#include <bits/stdc++.h>
const int N = 2e3 + 10;
using namespace std;
const long long mod = 1e9 + 7;
template <typename T>
inline T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <typename T>
inline T q_pow(T a, T x) {
  T ans = 1, tmp = a;
  while (x) {
    if (x & 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    x >>= 1;
  }
  return ans;
}
template <typename T>
inline void re(T &N) {
  int f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f = -1;
  N = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') N = N * 10 + c - '0';
  N *= f;
}
int m, n, t = 1;
long long d[N][N];
pair<long long, long long> a[N];
long long dfs(int l, int r) {
  if (l == r) return a[l].first * abs(a[l].second - l);
  if (d[l][r] != -1) return d[l][r];
  {
    long long ma = l;
    for (int i = l; i <= r; i++)
      if (a[ma].first * abs(a[ma].second - l) <
          a[i].first * abs(a[i].second - l))
        ma = i;
    swap(a[l], a[ma]);
    d[l][r] = max(d[l][r], dfs(l + 1, r) + a[l].first * abs(a[l].second - l));
    swap(a[l], a[ma]);
  }
  {
    long long ma = l;
    for (int i = l; i <= r; i++)
      if (a[ma].first * abs(a[ma].second - r) <
          a[i].first * abs(a[i].second - r))
        ma = i;
    swap(a[r], a[ma]);
    d[l][r] = max(d[l][r], dfs(l, r - 1) + a[r].first * abs(a[r].second - r));
    swap(a[r], a[ma]);
  }
  return d[l][r];
}
int main() {
  memset(d, -1, sizeof(d));
  re(n);
  for (int i = 1; i <= n; i++) re(a[i].first), a[i].second = i;
  printf("%lld\n", dfs(1, n));
  return 0;
}
