#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
constexpr int MOD = 1000000007;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 2e5 + 5;
int main(void) {
  long long N;
  cin >> N;
  pair<long long, long long> A[N];
  for (int(i) = 0; (i) < (N); (i)++) cin >> A[i].first;
  for (int(i) = 0; (i) < (N); (i)++) A[i].second = i;
  long long ans = 0;
  for (int(k) = 0; (k) < (50); (k)++)
    for (int(i) = 0; (i) < (N); (i)++)
      for (int(j) = 0; (j) < (N); (j)++) {
        if (i == j) continue;
        long long now = A[i].first * abs(A[i].second - i) +
                        A[j].first * abs(A[j].second - j);
        long long swp = A[i].first * abs(A[i].second - j) +
                        A[j].first * abs(A[j].second - i);
        if (now < swp) {
          ans += swp - now;
          swap(A[i], A[j]);
          break;
        }
      }
  cout << ans << "\n";
}
