#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (size_t i = 0; i < v.size(); i++)
    os << v[i] << (i + 1 == v.size() ? "" : ", ");
  os << "}";
  return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
long long dp[2222][2222];
int main() {
  int N;
  cin >> N;
  vector<pair<long long, long long>> A(N);
  for (int(i) = 0; (i) < (N); (i)++) {
    long long a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end(), greater<pair<long long, long long>>());
  vector<vector<long long>> dp(2222, vector<long long>(2222, -(1LL << 60)));
  dp[0][N] = 0;
  for (int i = 0; i < N; i++) {
    long long x = A[i].first;
    long long pos = A[i].second;
    for (int l = 0; l < N; l++) {
      int r = l + N - i;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + x * abs(pos - l));
      dp[l][r - 1] = max(dp[l][r - 1], dp[l][r] + x * abs(pos - (r - 1)));
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) ans = max(ans, dp[i][i]);
  cout << ans << endl;
  return 0;
}
