#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<pair<long long, pair<int, int> > > c;
  vector<bool> b1(n + 1, true), b2(n + 1, true);
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      c.push_back(pair<long long, pair<int, int> >(1ll * abs(i - j) * a[i],
                                                   pair<int, int>(i, j)));
    }
  }
  sort(c.begin(), c.end(),
       [](pair<long long, pair<int, int> > &a,
          pair<long long, pair<int, int> > &b) { return a.first > b.first; });
  for (pair<long long, pair<int, int> > &i : c)
    if (b1[i.second.first] && b2[i.second.second]) {
      b1[i.second.first] = false;
      b2[i.second.second] = false;
      ans += i.first;
    }
  cout << ans;
  return 0;
}
