#include <bits/stdc++.h>
using namespace std;
const long long maxs = 1e5 + 5;
const long long lmaxs = 20;
long long mod = 1e9 + 7;
long long oo = 1e15;
void pre() {}
const long long N = 2003;
long long dp[N][N];
bool vis[N][N];
pair<long long, long long> a[N];
long long n;
long long go(long long ind, long long i, long long j) {
  if (ind >= n) return 0;
  long long& ans = dp[ind][i];
  if (vis[ind][i]) return dp[ind][i];
  ans = a[i].first * abs(ind - a[i].second) + go(ind + 1, i + 1, j);
  ans = max(ans, a[j].first * abs(ind - a[j].second) + go(ind + 1, i, j - 1));
  return ans;
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long val;
    cin >> val;
    a[i].first = val;
    a[i].second = i;
  }
  sort(a, a + n);
  reverse(a, a + n);
  long long ans = go(0, 0, n - 1);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  pre();
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
