#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
const long long maxn = 2e3 + 100, inf = 1e9, LOG = 23, mod = 1e9 + 7;
int block = 300, timer = 0;
const long double EPS = 1e-7;
int n, dp[maxn][maxn], ans;
pair<int, int> a[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + 1 + n);
  for (int len = n; len >= 1; --len) {
    for (int l = 1; l <= n - len + 1; ++l) {
      int r = l + len - 1;
      dp[l + 1][r] =
          max(dp[l][r] + a[r - l + 1].first * abs(a[r - l + 1].second - l),
              dp[l + 1][r]);
      dp[l][r - 1] =
          max(dp[l][r] + a[r - l + 1].first * abs(a[r - l + 1].second - r),
              dp[l][r - 1]);
    }
  }
  for (int i = 0; i <= n; ++i) {
    ans = max(ans, dp[i + 1][i]);
  }
  cout << ans;
}
