#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long int a[400005], pre[400005], pre2[400005];
long long int h, l, r, n;
pair<long long int, long long int> arr[2005];
long long int dp[2005][2005];
long long int go(long long int l, long long int r, long long int i) {
  if (l > r) return 0;
  if (dp[i][l] != -1) return dp[i][l];
  long long int c1 =
      go(l + 1, r, i + 1) + arr[i].first * abs(arr[i].second - l);
  long long int c2 =
      go(l, r - 1, i + 1) + arr[i].first * abs((r - arr[i].second));
  long long int& cnt = dp[i][l];
  cnt = max(c1, c2);
  return cnt;
}
void solve() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i].first;
    arr[i].second = i;
  }
  sort(arr, arr + n);
  reverse(arr, arr + n);
  cout << go(0, n - 1, 0) << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  ;
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
