#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  vector<priority_queue<vll>> v(n);
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      v[j].push({a[i] * abs(i - j), i});
    }
  }
  ll ans = 0;
  vector<bool> done(n, false), done2(n, false);
  for (ll i = 0; i < n; i++) {
    ll x = 0, y, z;
    for (ll j = 0; j < n; j++) {
      if (done[j]) continue;
      if (x < v[j].top()[0]) {
        x = v[j].top()[0];
        y = v[j].top()[1];
        z = j;
      }
    }
    ans += x;
    done[z] = true;
    done2[y] = true;
    for (ll j = 0; j < n; j++) {
      while (v[j].size() && done2[v[j].top()[1]]) v[j].pop();
    }
  }
  cout << ans << endl;
}
