#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int M = 1e9 + 7;
long long mat[2001][2001], val[2001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &val[i]);
  }
  set<pair<long long, pair<int, int>>> s;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      mat[i][j] = abs(i - j) * val[j];
      s.insert({-1 * mat[i][j], {i, j}});
    }
  }
  while (!s.empty()) {
    auto it = *s.begin();
    s.erase(s.begin());
    long long val1 = it.first;
    ans += val1;
    int i = it.second.first, j = it.second.second;
    for (int k = 1; k <= n; k++) {
      auto it = s.find({-1 * mat[i][k], {i, k}});
      if (it != s.end()) s.erase(it);
    }
    for (int k = 1; k <= n; k++) {
      auto it = s.find({-1 * mat[k][j], {k, j}});
      if (it != s.end()) s.erase(it);
    }
  }
  printf("%lld", -1ll * ans);
  return 0;
}
