#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W,
    x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long dp[2001][2001];
int main() {
  cin >> N;
  pair<int, int> arr[2000];
  int active, ans = 0;
  for (int i = 0; i < (int)(N); i++) {
    cin >> active;
    arr[i] = make_pair(active, i + 1);
  }
  sort(arr, arr + N);
  reverse(arr, arr + N);
  int front_index = 1, back_index = N;
  long long scoremax = 0;
  dp[0][0] = 0;
  for (int x = 0, y = 0; x < N; x = y, y = 0) {
    for (; x >= 0; x--, y++) {
      dp[y][x + 1] =
          max(dp[y][x + 1],
              dp[y][x] + arr[x + y].first * max((arr[x + y].second - x - 1),
                                                (x + 1 - arr[x + y].second)));
      dp[y + 1][x] =
          max(dp[y + 1][x],
              dp[y][x] + arr[x + y].first * max((N - y - arr[x + y].second),
                                                (arr[x + y].second - N + y)));
      scoremax = max(scoremax, max(dp[y][x + 1], dp[y + 1][x]));
    }
  }
  cout << scoremax;
}
