#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpi = vector<pi>;
using vpll = vector<ll>;
using vpld = vector<ld>;
using vti3 = vector<ti3>;
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9 + 7;
ll pow(ll base, ll i, ll mod) {
  ll a = 1;
  while (i) {
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b) {
  while (b) {
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b)
    return a = b, true;
  else
    return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b)
    return a = b, true;
  else
    return false;
}
void solve() {
  ll N;
  cin >> N;
  ll A[2005];
  for (int i = 0; i < int(N); ++i) cin >> A[i];
  ll l = 0, r = N - 1;
  ll ans = 0;
  bool used[2005] = {};
  for (int k = 0; k < int(N); ++k) {
    ll max = 0;
    ll index = 0;
    bool side = false;
    for (int i = 0; i < int(N); ++i) {
      if (used[i]) continue;
      ll lp = A[i] * abs(i - l);
      ll rp = A[i] * abs(i - r);
      if (max < lp) {
        max = lp;
        index = i;
        side = false;
      }
      if (max < rp) {
        max = rp;
        index = i;
        side = true;
      }
      if (max == lp && abs(i - r) < (side ? abs(i - l) : abs(i - r))) {
        max = lp;
        index = i;
        side = false;
      }
      if (max == rp && abs(i - l) < (side ? abs(i - l) : abs(i - r))) {
        max = rp;
        index = i;
        side = true;
      }
    }
    ans += max;
    if (!side)
      l++;
    else
      r--;
    used[index] = true;
  }
  cout << ans << endl;
}
int main() {
  cin.tie(NULL);
  solve();
  return 0;
}
