#include <bits/stdc++.h>
using namespace std;
long long n;
pair<long long, long long> a[2001];
vector<vector<long long> > dp(2001,
                              vector<long long>(2001, -10000000000000000));
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  dp[0][0] = 0;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= i; j++) {
      long long l = j, r = n - (i - j) + 1;
      if (j != 0)
        dp[i][j] =
            max(dp[i][j], dp[i - 1][j - 1] + a[i].first * abs(a[i].second - l));
      dp[i][j] =
          max(dp[i][j], dp[i - 1][j] + a[i].first * abs(a[i].second - r));
    }
  }
  for (long long i = 0; i <= n; i++) ans = max(ans, dp[n][i]);
  cout << ans << '\n';
}
