#include <bits/stdc++.h>
using namespace std;
void max_residual(long arr[], int n, long max_iv[]) {
  long item = 0, value = -1;
  for (int i = 0; i < n; i++) {
    if (arr[i] > value) {
      item = i;
      value = arr[i];
    }
  }
  max_iv[0] = item;
  max_iv[1] = value;
  arr[item] = 0;
}
long ido(long max_iv[], bool is_filled[], long n) {
  long item = max_iv[0], value = max_iv[1];
  long dist = -1, pos = -1;
  for (int i = 0; i < n; i++) {
    if (is_filled[i]) continue;
    if (abs(i - item) > dist) {
      dist = abs(i - item);
      pos = i;
    }
  }
  is_filled[pos] = true;
  return dist * value;
}
int main() {
  long n;
  scanf("%ld", &n);
  long happy[n];
  bool is_filled[n];
  for (int i = 0; i < n; i++) {
    scanf("%ld", &happy[i]);
    is_filled[i] = false;
  }
  long max_iv[2];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    max_residual(happy, n, max_iv);
    ans += ido(max_iv, is_filled, n);
  }
  printf("%d\n", ans);
  return 0;
}
