#include <bits/stdc++.h>
using namespace std;
const int N = 2010, size = 1 << 20;
template <class o>
void qr(o &x) {
  char c = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o>
void pr1(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  puts("");
}
int n, g[N];
long long a[N], ans;
long long C(long long x, long long y) { return a[x] * abs(x - y); }
int main() {
  qr(n);
  for (int i = 1; i <= n; i++) qr(a[i]), g[i] = i;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (C(i, g[i]) + C(j, g[j]) < C(i, g[j]) + C(j, g[i])) swap(g[i], g[j]);
  }
  for (int i = 1; i <= n; i++) ans += C(i, g[i]);
  pr2(ans);
  return 0;
}
