#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long ans = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return ans * f;
}
const long long N = 2005;
long long n, a[N], h[N], l[N], tot, ans;
struct Node {
  long long x, y, z;
  bool operator<(const Node &t) const { return t.z < z; }
} b[N * N];
int main() {
  n = read();
  for (long long i = 1; i <= n; ++i) a[i] = read();
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= n; ++j) {
      long long k = a[j] * fabs(i - j);
      b[++tot] = (Node){i, j, k};
    }
  sort(b + 1, b + 1 + tot);
  for (long long i = 1; i <= tot; ++i)
    if (!h[b[i].x] && !l[b[i].y]) {
      ans += b[i].z;
      h[b[i].x] = 1;
      l[b[i].y] = 1;
    }
  printf("%lld\n", ans);
  return 0;
}
