#include <bits/stdc++.h>
using namespace std;
void print() { cout << "\n"; }
template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " ";
  print(args...);
}
long long llipowerp(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long binarySearch(vector<int> arr, int l, int r, int x) {
  if (r >= l) {
    long long mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
    return binarySearch(arr, mid + 1, r, x);
  }
  return -1;
}
template <typename T>
inline void printvec(vector<T> inp) {
  for (auto it : inp) cout << it << " ";
  cout << "\n";
}
int dp[2001][2001];
int n;
vector<pair<long long, long long>> a;
long long fill(long long l, long long r) {
  if (dp[l][r] != -1) return dp[l][r];
  int i = n - 1 - (r - l);
  if (l == r) {
    dp[l][r] = abs(l - a[i].second) * a[i].first;
    return dp[l][r];
  }
  dp[l][r] = max(fill(l + 1, r) + abs(l - a[i].second) * a[i].first,
                 fill(l, r - 1) + abs(r - a[i].second) * a[i].first);
  return dp[l][r];
}
int main() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  a.resize(n);
  long long x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[i] = make_pair(x, i);
  }
  sort(a.rbegin(), a.rend());
  cout << fill(0, n - 1) << "\n";
}
