#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[2000];
  for (int i = 0; i < (N); i++) cin >> A[i];
  pair<int, int> B[2020];
  for (int i = 0; i < (N); i++) {
    B[i] = make_pair(A[i], i);
  }
  for (int p = 0; p < (N); p++)
    for (int i = 0; i < (N - 1); i++) {
      long long kari = 0;
      kari += long long(abs(B[i].second - i)) * B[i].first;
      kari += long long(abs(B[i + 1].second - i - 1)) * B[i + 1].first;
      swap(B[i], B[i + 1]);
      long long kari2 = 0;
      kari2 += long long(abs(B[i].second - i)) * B[i].first;
      kari2 += long long(abs(B[i + 1].second - i - 1)) * B[i + 1].first;
      if (kari2 < kari) {
        swap(B[i], B[i + 1]);
      }
    }
  long long kotae = 0;
  for (int i = 0; i < (N); i++) {
    kotae += long long(abs(B[i].second - i)) * B[i].first;
  }
  cout << (kotae) << "\n";
  return 0;
}
