#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e9;
const long double PI = acos((long double)-1);
const long double EPS = 1e-12;
inline bool isPrime(long long x) {
  if (x <= 1) return 0;
  if (x <= 3) return 1;
  if (!(x % 2) || !(x % 3)) return 0;
  long long s = sqrt(1.0 * x) + EPS;
  for (long long i = 5; i <= s; i += 6) {
    if (!(x % i) || !(x % (i + 2))) return 0;
  }
  return 1;
}
inline long long fpow(long long n, long long k, long long p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
inline int inv(int a, long long p = MOD) { return fpow(a, p - 2, p); }
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline void onbit(long long &a, int i) { a |= 1LL << i; }
inline void offbit(long long &a, int i) { onbit(a, i), a -= (1LL << i); }
const int N = 3e3 + 5;
int n, m, k;
long long a[N], b[N];
long long f[N][N][3];
void solve() {
  cin >> n;
  std::vector<pair<int, int>> b(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = {a[i], i};
  }
  b[0] = {INF, INF};
  sort((b).begin(), (b).end(), greater<pair<int, int>>());
  long long res = 0;
  for (int k = 1; k <= n; k++) {
    int x = b[k].first;
    int y = b[k].second;
    int len = n - k + 1;
    for (int i = 1; i + len - 1 <= n; i++) {
      f[i][len][0] =
          max(f[i - 1][len + 1][0] + b[k].first * abs(b[k].second - i),
              f[i][len + 1][1] + b[k].first * abs(b[k].second - i));
      f[i][len][1] = max(
          f[i - 1][len + 1][0] + b[k].first * abs(b[k].second - (i + len - 1)),
          f[i][len + 1][1] + b[k].first * abs(b[k].second - (i + len - 1)));
      res = max(max((long long)(res), (long long)(f[i][len][0])),
                (long long)(f[i][len][1]));
    }
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int query = 1;
  int start = 1000 * clock() / CLOCKS_PER_SEC;
  while (query--) solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC - start
       << "ms\n";
}
