#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
pair<long long int, long long int> p[N + 1];
long long int dp[N][N];
long long int solve1(long long int id, long long int first,
                     long long int last) {
  if (id == 0) return 0;
  long long int crt = p[id].second;
  long long int dif1 = abs(crt - first);
  long long int dif2 = abs(crt - last);
  long long int ans = dp[id][first];
  ans = max((solve1(id - 1, first, last - 1) + p[id].first * dif2),
            (solve1(id - 1, first + 1, last) + p[id].first * dif1));
  return dp[id][first] = ans;
}
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> p[i].first;
    p[i].second = i;
  }
  sort(p + 1, p + n + 1);
  set<long long int> s;
  memset(dp, -1, sizeof(dp));
  long long int ans = solve1(n, 1, n);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
}
