#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T, class U>
using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vll a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll ans = 0;
  int left = 0, right = n - 1;
  V<bool> used(n, false);
  for (int i = 0; i < n; i++) {
    ll tmpdiff = -1;
    int ai;
    int lr = -1;
    for (int j = 0; j < n; j++) {
      if (used[j]) continue;
      if (chmax(tmpdiff, a[j] * (ll)abs(j - left))) {
        ai = j;
        lr = 0;
      }
      if (chmax(tmpdiff, a[j] * (ll)abs(j - right))) {
        ai = j;
        lr = 1;
      }
    }
    used[ai] = true;
    ans += tmpdiff;
    if (lr == 0)
      left++;
    else
      right--;
  }
  cout << ans << '\n';
  return 0;
}
