#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > A(2002);
  for (long long i = 1; i <= n; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(A.begin(), A.end());
  long long dp[2002][2002], ans = 0;
  memset(dp, 0, sizeof(dp));
  for (long long l = n; l >= 1; l--) {
    for (long long i = 1; i <= n - l + 1; i++) {
      long long j = i + l - 1;
      if (l == 1) {
        ans = max(ans, dp[i][j] + (long long)A[l].first * abs(A[l].second - i));
      } else {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + (long long)A[l].first *
                                                        abs(A[l].second - i));
        dp[i][j - 1] = max(dp[i][j - 1], dp[i][j] + (long long)A[l].first *
                                                        abs(A[l].second - j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
