#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
long long val[maxn];
bool used[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &val[i]);
  int l = 1, r = n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    bool sign = false;
    long long maxx = 0;
    int pos = 0;
    for (int j = 1; j <= n; j++) {
      if (used[j]) continue;
      bool type = false;
      long long cur;
      if (abs(j - l) > abs(j - r)) {
        type = false;
        cur = (long long)abs(j - l) * val[j];
      } else {
        type = true;
        cur = (long long)abs(j - r) * val[j];
      }
      if (cur > maxx) {
        maxx = cur;
        sign = type;
        pos = j;
      }
    }
    ans += maxx;
    used[pos] = true;
    if (sign == false)
      l++;
    else
      r--;
  }
  printf("%lld\n", ans);
  return 0;
}
