#include <bits/stdc++.h>
using namespace std;
int mark[2005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, i, j, x, best, k, v1, v2, id1, sum = 0, id2;
  vector<long long int> v;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> x;
    v.push_back(x);
  }
  i = 0;
  j = n - 1;
  while (i <= j) {
    best = 0;
    id1 = -1;
    id2 = -1;
    for (k = 0; k < n; ++k) {
      if (mark[k] == 0) {
        v1 = v[k] * abs(k - i);
        v2 = v[k] * abs(k - j);
        if (v1 >= best) {
          id1 = i;
          best = v1;
          id2 = k;
        }
        if (v2 > best) {
          id1 = j;
          best = v2;
          id2 = k;
        }
      }
    }
    mark[id2] = 1;
    if (id1 == i) {
      i++;
      sum += best;
    } else {
      j--;
      sum += best;
    }
  }
  cout << sum;
}
