#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<long long> v(n);
  vector<int> idx(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    idx[i] = i;
  }
  sort(idx.rbegin(), idx.rend(), [&v](int l, int r) { return v[l] < v[r]; });
  long long tot = 0;
  vector<bool> vis(n, false);
  int lo = 0;
  int hi = n - 1;
  while (lo <= hi) {
    long long maxv = 0;
    int maxi = 0;
    bool firstPick = true;
    int pick;
    for (int i = 0; i < n; ++i) {
      if (!vis[idx[i]]) {
        if (firstPick) {
          if (abs(idx[i] - lo) < abs(idx[i] - hi)) {
            pick = hi;
            hi -= 1;
          } else {
            pick = lo;
            lo += 1;
          }
          maxi = idx[i];
          maxv = v[idx[i]] * abs(idx[i] - pick);
          firstPick = false;
        } else {
          long long val = v[idx[i]] * abs(idx[i] - pick);
          if (val > maxv) {
            maxv = val;
            maxi = idx[i];
          }
        }
      }
    }
    tot += maxv;
    vis[maxi] = true;
  }
  cout << tot << '\n';
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
