#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long heur(long long h, long long i, long long n) {
  return max(h * abs(i - n + 1), h * abs(i));
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = (0); i < (n); ++i) cin >> a[i];
  vector<bool> assign(n);
  long long hap = 0;
  vector<pair<long long, long long> > vals;
  for (long long i = (0); i < (n); ++i) {
    vals.push_back(make_pair(heur(a[i], i, n), i));
  }
  sort(vals.begin(), vals.end());
  reverse(vals.begin(), vals.end());
  for (pair<long long, long long> pr : vals) {
    long long k = 0;
    long long delta = -1;
    for (long long i = (0); i < (n); ++i) {
      if (!assign[i] && abs(pr.second - i) > delta) {
        delta = abs(pr.second - i);
        k = i;
      }
    }
    assign[k] = true;
    hap += a[pr.second] * delta;
  }
  cout << hap << '\n';
}
