#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return (b.first < a.first);
}
void solve() {
  int n;
  cin >> n;
  vector<pair<long long, long long> > a;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int c;
    cin >> c;
    a.push_back(make_pair(c, i));
  }
  sort(a.begin(), a.end(), comp);
  int l = 1, r = n;
  for (int i = 0; i < n; ++i) {
    if (a[i].second > n / 2) {
      ans += abs(l - a[i].second) * a[i].first;
      l++;
    } else {
      ans += abs(r - a[i].second) * a[i].first;
      r--;
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
