#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int M = 1e9 + 7;
long long mat[2001][2001], val[2001];
bool vis1[2001], vis2[2001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &val[i]);
  }
  long long ans = 0;
  vector<pair<long long, pair<long long, long long>>> v;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      mat[i][j] = abs(i - j) * val[j];
      v.push_back({-1ll * mat[i][j], {i, j}});
    }
  }
  int cnt = 0;
  sort(v.begin(), v.end());
  for (auto it : v) {
    long long val = it.first;
    long long i = it.second.first;
    long long j = it.second.second;
    if (vis1[i] || vis2[j]) {
      continue;
    }
    ans = ans + val;
    vis1[i] = 1;
    vis2[j] = 1;
    cnt++;
    if (cnt == n) {
      break;
    }
  }
  printf("%lld", -1ll * ans);
  return 0;
}
