#include <bits/stdc++.h>
using namespace std;
long long int dp[2001][2001];
int n, t;
vector<pair<long long int, long long int>> v;
long long int solve(int a, int b) {
  if (dp[a][b] != -1) {
    return dp[a][b];
  }
  if (a > b) {
    dp[a][b] = 0;
    return dp[a][b];
  }
  int idx = a + (n - 1 - b);
  long long int val1 = (v[idx].first) * (abs(v[idx].second - a));
  long long int val2 = (v[idx].first) * (abs(v[idx].second - b));
  dp[a][b] = max(dp[a][b], max(solve(a + 1, b) + val1, solve(a, b - 1) + val2));
  return dp[a][b];
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    v.push_back(make_pair(t, i));
  }
  sort(v.rbegin(), v.rend());
  memset(dp, -1, sizeof(dp));
  cout << solve(0, n - 1) << '\n';
  return 0;
}
