#include <bits/stdc++.h>
using namespace std;
int a[2001], ff, x, n, b[2001];
long long s, max1;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (ff == 1) {
      max1 = 9999999999999;
      for (int j = 1; j <= i; j++) {
        if (b[j] == 0) {
          if (a[j] * (i - j) < max1) {
            max1 = a[j] * (i - j);
            x = j;
          }
        }
      }
    }
    ff = 1;
    max1 = 0;
    for (int j = i + 1; j <= n; j++) {
      if (b[j] == 0) {
        if (a[j] * (j - i) > max1) {
          max1 = a[j] * (j - i);
          x = j;
        }
        ff = 0;
      }
    }
    if (ff == 1) {
      max1 = 9999999999999;
      for (int j = 1; j <= i; j++) {
        if (b[j] == 0) {
          if (a[j] * (i - j) < max1) {
            max1 = a[j] * (i - j);
            x = j;
          }
        }
      }
    }
    b[x] = 1;
    s += max1;
  }
  cout << s;
  return 0;
}
