#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const int N = 2e3 + 5;
int A[N], P[N];
long long ans, DP[N][N];
bool CMP(int i, int j) { return A[P[i]] > A[P[j]]; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  mt19937 Rnd(time(0));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i], P[i] = i;
  sort(P, P + n, CMP);
  for (int x = 0; x <= n; x++)
    for (int y = 0; x + y <= n; y++) {
      if (!x && !y) continue;
      int i = x + y - 1;
      if (x)
        DP[x][y] =
            max(DP[x][y], DP[x - 1][y] + 1LL * A[P[i]] * ((P[i] + 1) - x));
      if (y)
        DP[x][y] = max(DP[x][y], DP[x][y - 1] + 1LL * A[P[i]] *
                                                    ((n - y + 1) - (P[i] + 1)));
      if (x + y == n) ans = max(ans, DP[x][y]);
    }
  cout << ans << '\n';
  return 0;
}
