#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, count = 0;
  string s;
  cin >> n;
  vector<pair<ll, ll>> a;
  for (int i = 0; i < (int)(n); i++) {
    ll aa;
    cin >> aa;
    pair<ll, ll> p = make_pair(aa, i);
    a.push_back(p);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<ll> ans(n);
  ll middle = (n - 1) / 2;
  ll r = n - 1, l = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (a[i].second > middle) {
      ans[l] = a[i].first * abs(a[i].second - l);
      l++;
    } else {
      ans[r] = a[i].first * abs(a[i].second - r);
      r--;
    }
  }
  ll answer = 0;
  for (int i = 0; i < (int)(n); i++) {
    answer += ans[i];
  }
  cout << answer << endl;
}
