#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
int n;
bool cmp(const pair<int, int>& i, const pair<int, int>& j) {
  long long mxi, mxj;
  if (i.second >= (n - 1 - i.second))
    mxi = i.first * i.second;
  else
    mxi = i.first * (n - 1 - i.second);
  if (j.second >= (n - 1 - j.second))
    mxj = j.first * j.second;
  else
    mxj = j.first * (n - 1 - j.second);
  if (mxi == mxj) {
    if (i.first == j.first)
      return i.second > j.second;
    else
      i.first > j.first;
  }
  return mxi > mxj;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 0; i < (int)(n); ++i) {
    int tmp;
    cin >> tmp;
    v.emplace_back(make_pair(tmp, i));
    int mx = 0;
    if (i >= (n - 1 - i))
      mx = tmp * i;
    else
      mx = tmp * i;
  }
  sort((v).begin(), (v).end(), cmp);
  long long ans = 0;
  int l = 0;
  int r = n - 1;
  for (int i = 0; i < (int)(n); ++i) {
    auto p = v[i];
    long long u = 0;
    if (abs(p.second - l) >= abs(p.second - r)) {
      u = p.first * abs(p.second - l);
      l++;
    } else {
      u = p.first * abs(p.second - r);
      r--;
    }
    ans += u;
  }
  cout << ans << endl;
  return 0;
}
