#include <bits/stdc++.h>
using namespace std;
const int nm = 2010;
int n;
long long a[nm];
bool fr[nm];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  memset(fr, 1, sizeof(fr));
  int l = 1, r = n;
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    int besti = -1;
    long long best = -1;
    for (int j = 1; j <= n; ++j) {
      if (fr[j]) {
        long long tmp = a[j] * max(abs(j - l), abs(j - r));
        if (tmp > best) {
          best = tmp;
          besti = j;
        }
      }
    }
    int j = besti;
    res += best;
    if (abs(j - l) > abs(j - r)) {
      l++;
    } else {
      r--;
    }
    fr[j] = 0;
  }
  cout << res << "\n";
}
