#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n;
long long a[2010];
pair<long long, long long> p[2010];
long long dp[2010][2010];
bool memo[2010][2010];
long long f(int x, int y) {
  if (x == y) return p[n].first * abs(p[n].second - x);
  if (memo[x][y]) return dp[x][y];
  long long ans = 0;
  int pos = p[n - (y - x)].second;
  int val = p[n - (y - x)].first;
  ans = max(ans, val * abs(pos - x) + f(x + 1, y));
  ans = max(ans, val * abs(pos - y) + f(x, y - 1));
  memo[x][y] = 1;
  dp[x][y] = ans;
  return ans;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= int(n); i++) {
    cin >> a[i];
    p[i] = make_pair(a[i], i);
  }
  sort(p + 1, p + 1 + n, greater<pair<long long, long long> >());
  cout << f(1, n) << endl;
}
