#include <bits/stdc++.h>
using namespace std;
using int32 = int32_t;
using str = string;
using cstr = const str;
using ll = long long;
using ull = unsigned long long;
using cint = const ll;
using cll = const ll;
using vi = vector<ll>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using psl = pair<string, ll>;
using tiii = tuple<ll, ll, ll>;
using tlll = tuple<ll, ll, ll>;
static const ll MGN = 10;
static const ll ARYSZ_MAX = (ll)1e7;
static const ll LINF = LLONG_MAX / 2;
static const ll INF = LINF;
static double EPS = 1e-9;
static inline bool DBLEQ(double a, double b) { return abs(a - b) < EPS; }
static inline void EPR(str msg) { cerr << msg << endl; }
static inline void AST(bool exp, str msg) {
  if (!exp) {
    EPR(msg);
  }
  assert(exp);
}
static inline void TAST(bool exp, str msg) {
  if (!exp) {
    EPR(msg);
  }
  while (!exp) {
  }
}
int32 main(int32 argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  ;
  ll N;
  cin >> N;
  vi A(N);
  for (ll i = ll(0); i < ll(N); ++i) cin >> A[i];
  priority_queue<pii> pq;
  for (ll i = ll(0); i < ll(N); ++i)
    pq.push(make_pair(A[i] * max(i - 0, N - i), i));
  vb fixed(N, false);
  ll ans = 0;
  while (not pq.empty()) {
    auto pr = pq.top();
    pq.pop();
    ll x = pr.second;
    ll y = x;
    for (ll i = ll(0); i < ll(N); ++i) {
      if (not fixed[i] and abs(i - x) > abs(y - x)) {
        y = i;
      }
    }
    ans += A[x] * abs(x - y);
    fixed[y] = true;
  }
  cout << ans << endl;
  return 0;
}
