#include <bits/stdc++.h>
using namespace std;
long long int a[20000];
int low, high;
bool flg[20000];
int idx[20000];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    idx[i] = i;
  }
  low = 1;
  high = n;
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    int max_val = -1;
    int max_idx = -1;
    int real_idx;
    int to = -1;
    for (int j = 1; j <= n; j++) {
      if (max_val < a[j] * abs(j - low)) {
        max_val = a[j] * abs(j - low);
        to = low;
        max_idx = j;
      }
      if (max_val < a[j] * abs(j - high)) {
        max_val = a[j] * abs(j - high);
        to = high;
        max_idx = j;
      }
    }
    ans += a[max_idx] * abs(max_idx - to);
    a[max_idx] = -1;
    if (to == low) low++;
    if (to == high) high--;
  }
  cout << ans << endl;
}
