#include <bits/stdc++.h>
using namespace std;
const long long MAX = 510000;
const long long MOD = 1000000007;
signed main() {
  long long n;
  cin >> n;
  pair<long long, long long> a[n];
  long long b;
  for (long long i = 0; i < n; i++) {
    cin >> b;
    a[i] = make_pair(b, i);
  }
  sort(a, a + n, greater<pair<long long, long long>>());
  long long dp[n][n];
  for (long long i = 0; i < n; i++) fill(dp[i], dp[i] + n, -1);
  dp[0][0] = 0;
  for (long long i = 1; i < n; i++) {
    if (a[i - 1].second >= i - 1)
      if (dp[i - 1][0] != -1)
        dp[i][0] = dp[i - 1][0] + (a[i - 1].second - (i - 1)) * a[i - 1].first;
    for (long long j = 1; j < i; j++) {
      if (a[i - 1].second >= i - 1 - j)
        if (dp[i - 1][j] != -1)
          dp[i][j] =
              dp[i - 1][j] + (a[i - 1].second - (i - 1 - j)) * a[i - 1].first;
      if (a[i - 1].second <= n - j)
        if (dp[i - 1][j - 1] != -1)
          dp[i][j] =
              max(dp[i][j], dp[i - 1][j - 1] +
                                (n - j - a[i - 1].second) * a[i - 1].first);
    }
  }
  long long ans = dp[n - 1][0] + abs(n - 1 - a[n - 1].second) * a[n - 1].first;
  for (long long i = 1; i < n; i++)
    ans = max(ans,
              dp[n - 1][i] + abs(n - 1 - i - a[n - 1].second) * a[n - 1].first);
  cout << ans << endl;
}
