#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
}
using Graph = vector<vector<int>>;
using P = pair<long long, long long>;
using Tuple = tuple<int, int, int>;
long long modnum = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (long long)(n); ++i) cin >> a[i];
  int start = 0, end = n - 1;
  vector<bool> used(n, false);
  long long ans = 0;
  for (long long x = 0; x < (long long)(n); ++x) {
    long long maximum = -1;
    int use = -1;
    for (long long i = 0; i < (long long)(n); ++i)
      if (!used[i]) {
        if (a[i] * max(abs(i - start), abs(end - i)) > maximum) {
          maximum = a[i] * max(abs(i - start), abs(end - i));
          use = i;
        }
      }
    if (abs(use - start) > abs(end - use))
      start++;
    else
      end--;
    used[use] = true;
    ans += maximum;
  }
  cout << ans << endl;
  return 0;
}
