#include <bits/stdc++.h>
using namespace std;
using vll = vector<long long>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
long long llpow(long long x, T n) {
  long long ans = 1;
  if (x == 0) ans = 0;
  while (n) {
    if (n & 1) ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
template <class T>
inline T gcd(T x, T y) {
  if (y == 0)
    return x;
  else {
    return gcd(y, x % y);
  }
}
template <class T>
inline T lcm(T x, T y) {
  return x / gcd(x, y) * y;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long INF = 1LL << 60;
int main() {
  int n;
  cin >> n;
  vi a(n);
  for (long long i = (long long)0; i < (long long)n; i++) cin >> a[i];
  vb used(n, false);
  vb movedto(n, false);
  priority_queue<pair<long long, pii>> q;
  for (long long i = (long long)0; i < (long long)n; i++) {
    for (long long j = (long long)0; j < (long long)n; j++) {
      pii pindex = make_pair(i, j);
      long long happiness = a[i] * abs(i - j);
      pair<long long, pii> t = make_pair(happiness, pindex);
      q.push(t);
    }
  }
  int usedcnt = 0;
  long long res = 0;
  while (usedcnt < n) {
    auto p = q.top();
    q.pop();
    pii ind = p.second;
    if (used[ind.first] == false && movedto[ind.second] == false) {
      used[ind.first] = true;
      movedto[ind.second] = true;
      usedcnt++;
      res += p.first;
    }
  }
  cout << res << endl;
  return 0;
}
