#include <bits/stdc++.h>
using namespace std;
std::vector<pair<int, int> > v;
int n;
int arr[200005];
std::vector<pair<int, int> > ans(200005);
long long int val = 0;
long long int sol = 0;
int dp(int l, int r, int k) {
  if (l == r) {
    return v[k].first * abs(r - v[k].second);
  } else {
    return max(v[k].first * abs(l - v[k].second) + dp(l + 1, r, k - 1),
               v[k].first * abs(r - v[k].second) + dp(l, r - 1, k - 1));
  }
}
int main() {
  memset(arr, -1, sizeof(arr));
  int y;
  cin >> n;
  v.push_back(make_pair(INT_MIN, 0));
  for (int i = 1; i <= n; i++) {
    cin >> y;
    v.push_back(make_pair(y, i));
  }
  sort(v.begin(), v.end());
  cout << dp(1, n, n);
}
