#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)1e9 + 7;
const double EPS = 1e-9;
struct BIT {
  vector<long long> node;
  long long mn;
  BIT(long long mn) {
    this->mn = mn;
    node.resize(mn + 1, 0);
  }
  void add(long long i, long long x) {
    while (i <= mn) {
      node[i] += x;
      i += (i & -i);
    }
  }
  long long sum(long long i) {
    long long res = 0;
    while (i > 0) {
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<pair<long long, long long>> A(N);
  vector<vector<long long>> DP(N + 1, vector<long long>(N + 1, 0));
  for (long long i = (0), i_len = (N); i < i_len; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(begin(A), end(A), greater<pair<long long, long long>>());
  long long ans = 0;
  for (long long i = (0), i_len = (N); i < i_len; i++) {
    for (long long j = (0), j_len = (i + 1); j < j_len; j++) {
      DP[j + 1][i - j] = DP[j][i - j] + A[i].first * abs(A[i].second - j);
      DP[j][i - j + 1] =
          DP[j][i - j] + A[i].first * abs(A[i].second - (N - 1 - (i - j)));
      chmax(ans, DP[j + 1][i - j]);
      chmax(ans, DP[j][i - j + 1]);
    }
  }
  cout << ans << endl;
  return 0;
}
