#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
template <class T>
inline bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
ll A[2000];
pair<ll, ll> C[2000];
bool used[2000];
bool val(ll x1, ll x2) {
  ll pre = C[x1].first * abs(C[x1].second - x1) +
           C[x2].first * abs(C[x2].second - x2),
     sw = C[x1].first * abs(C[x1].second - x2) +
          C[x2].first * abs(C[x2].second - x1);
  return sw > pre;
}
int main() {
  init();
  ll N;
  cin >> N;
  for (ll i = 0; i < (N); i++) cin >> A[i];
  for (ll i = 0; i < (N); i++) C[i] = {A[i], i};
  for (ll i = 0; i < (N); i++) {
    for (ll j = 0; j < (N - 1); j++) {
      if (val(j, j + 1)) swap(C[j], C[j + 1]);
    }
  }
  ll ans = 0;
  for (ll i = 0; i < (N); i++) {
    ans += C[i].first * abs(C[i].second - i);
  }
  cout << ans << endl;
}
