#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto& el : a) {
    cin >> el;
  }
  long long l = 0, r = n - 1;
  long long res = 0;
  vector<bool> u(n, true);
  for (int t = 0; t < n; ++t) {
    long long maxx = 0, inx = l;
    bool isl = true;
    for (int i = 0; i < n; ++i) {
      bool is = false;
      if (u[i] and abs(l - i) * a[i] > maxx) {
        inx = i;
        is = true;
        isl = true;
        maxx = abs(l - i) * a[i];
      }
      if (u[i] and abs(r - i) * a[i] > maxx) {
        inx = i;
        is = true;
        isl = false;
        maxx = abs(r - i) * a[i];
      }
    }
    u[inx] = false;
    res += maxx;
    if (isl) {
      ++l;
    } else {
      --r;
    }
  }
  cout << res << endl;
}
