#include <bits/stdc++.h>
int mtp(int n, int a[]) {
  int i;
  int t[n], head = 0, tail = n - 1;
  long ans = 0;
  for (i = 0; i < n; i++) {
  }
  while (head <= tail) {
    int max = a[0], md = 0;
    for (i = 1; i < n; i++) {
      if (max < a[i]) {
        max = a[i];
        md = i;
      }
    }
    if (md < (head + tail) / 2) {
      t[tail] = max;
      ans += (long)max * abs(tail - md);
      tail--;
      a[md] = 0;
    } else {
      t[head] = max;
      ans += (long)max * abs(md - head);
      head++;
      a[md] = 0;
    }
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  int a[n], i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  long ans;
  ans = mtp(n, a);
  printf("%ld\n", ans);
}
