#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
  int x = a + b;
  if (x >= 1000000007) x -= 1000000007;
  if (x < 0) x += 1000000007;
  return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed() {
  long long a = rng();
  return a;
}
int n;
pair<int, int> val[2002];
long long dp[2002][2002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> val[i].first, val[i].second = i;
  long long ans = 0;
  sort(val + 1, val + n + 1);
  for (int len = n; len >= 1; --len)
    for (int st = 1; st + len - 1 <= n; ++st) {
      if (len == 1)
        ans = max(
            ans, dp[st][st] + 1LL * val[len].first * abs(val[len].second - st));
      else {
        dp[st + 1][st + len - 1] =
            max(dp[st + 1][st + len - 1],
                dp[st][st + len - 1] +
                    1LL * val[len].first * abs(val[len].second - st));
        dp[st][st + len - 2] = max(
            dp[st][st + len - 2],
            dp[st][st + len - 1] +
                1LL * val[len].first * abs(val[len].second - (st + len - 1)));
      }
    }
  cout << ans;
  return 0;
}
