#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000007;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    a[i] = make_pair(i, k);
  }
  long long now = 0;
  long long cnt = 0;
  int aa = 0;
  while (true) {
    bool flag = true;
    now = cnt;
    if (now == n) break;
    for (int j = 0; j < (n); j++) {
      if (abs(a[now].first - now) * a[now].second +
              abs(a[j].first - j) * a[j].second <
          abs(a[now].first - j) * a[now].second +
              abs(a[j].first - now) * a[j].second) {
        swap(a[now], a[j]);
        now = j;
        flag = false;
      }
    }
    if (flag) cnt++;
  }
  long long ans = 0;
  for (int i = 0; i < (n); i++) ans += abs(a[i].first - i) * a[i].second;
  cout << ans << endl;
}
