#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
struct node {
  int val, dis, id, st;
};
int a[maxn];
bool cmp(node x, node y) {
  if (x.val * x.dis == y.val * y.dis) {
    return x.dis > y.dis;
  } else
    return x.val * x.dis > y.val * y.dis;
}
bool take[maxn], seat[maxn];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<node> v;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 1; j <= n; j++)
      if (j != i) v.push_back(node{a[i], abs(j - i), i, j});
  }
  sort(v.begin(), v.end(), cmp);
  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (take[v[i].id] || seat[v[i].st]) continue;
    take[v[i].id] = true;
    seat[v[i].st] = true;
    ans += 1ll * v[i].dis * v[i].val;
  }
  cout << ans << '\n';
}
