#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n;
pair<int, int> a[N];
long long dp[N][N];
int main() {
  long long ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].first, a[i].second = i;
  sort(a + 1, a + 1 + n, greater<pair<int, int>>());
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      dp[i][j] =
          max(dp[i - 1][j] + a[i].first * abs(n - (i - j) + 1 - a[i].second),
              (j > 0 ? dp[i - 1][j - 1] : -(1LL << 60)) +
                  a[i].first * abs(a[i].second - j));
    }
    dp[i][i] = dp[i - 1][i - 1] + a[i].first * abs(a[i].second - i);
    dp[i][0] = dp[i - 1][0] + a[i].first * abs(n - i + 1 - a[i].second);
  }
  for (int i = 0; i <= n; i++) ans = max(ans, dp[n][i]);
  cout << ans;
  return 0;
}
