#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
const long long M = 1e9 + 7;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
struct node {
  long long x;
  int pre, now;
} al[maxn * maxn];
long long a[maxn];
int vis[maxn], vis2[maxn];
int _;
bool cmp(node a, node b) { return a.x > b.x; }
int main() {
  fastio();
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int id = (i - 1) * n + j;
      al[id].x = (long long)abs(i - j) * a[i];
      al[id].pre = i;
      al[id].now = j;
    }
  }
  sort(al + 1, al + n * n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= n * n; i++) {
    int pre = al[i].pre, now = al[i].now;
    if (vis[pre] || vis2[now]) continue;
    ans += al[i].x;
    vis[pre] = vis2[now] = 1;
  }
  cout << ans << endl;
  return 0;
}
