#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = (0); i < (N); ++i) cin >> A[i];
  vector<ll> index(N);
  for (ll i = (0); i < (N); ++i) index[i] = i;
  for (ll i = (0); i < (N); ++i) {
    for (ll j = (1); j < (N); ++j) {
      if (A[j - 1] * abs(j - 1 - index[j - 1]) + A[j] * abs(j - index[j]) <
          A[j - 1] * abs(j - index[j - 1]) + A[j] * abs(j - 1 - index[j])) {
        swap(A[j - 1], A[j]);
        swap(index[j - 1], index[j]);
      }
    }
  }
  ll sum = 0;
  for (ll i = (0); i < (N); ++i) {
    sum += A[i] * abs(i - index[i]);
  }
  cout << sum;
  return 0;
}
