#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return f * x;
}
long long n, m, cnt;
long long sum;
const long long mod = 1e9 + 7;
long long cal(long long n, long long m) {
  long long a = 1, b = 1;
  for (long long i = n - m + 1; i <= n; i++) a = a * i % mod;
  for (long long i = 2; i <= m; i++) b = b * i % mod;
  return (a / b) % mod;
}
struct node {
  long long id, val;
} a[2005];
bool cmp(node x, node y) { return x.val > y.val; }
int main() {
  n = read();
  for (register int i = 1; i <= n; i++) {
    a[i].id = i;
    a[i].val = read();
  }
  int l = 1, r = n;
  sort(a + 1, a + n + 1, cmp);
  for (register int i = 1; i <= n; i++) {
    if (a[i].id < (l + r) / 2) {
      sum += abs(r - a[i].id) * a[i].val;
      r--;
    } else {
      sum += abs(a[i].id - l) * a[i].val;
      l++;
    }
  }
  printf("%lld\n", sum);
  return 0;
}
