#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long sum(vector<pair<long, int>> &arr, int n, int i, int j, int c) {
  if (i > j || c < 0 || c >= n) return 0;
  long l = arr[c].first * abs(arr[c].second - i) + sum(arr, n, i + 1, j, c - 1);
  long r = arr[c].first * abs(arr[c].second - j) + sum(arr, n, i, j - 1, c - 1);
  return max(l, r);
}
bool grt(pair<long, int> &a, pair<long, int> &b) { return a.first < b.first; }
void solve() {
  int n;
  cin >> n;
  vector<pair<long, int>> arr(n);
  for (int i = 0; i < (n); ++i) {
    cin >> arr[i].first;
    arr[i].second = i;
  }
  sort(arr.begin(), arr.end(), grt);
  cout << sum(arr, n, 0, n - 1, n - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
