#include <bits/stdc++.h>
using namespace std;
struct compare {
  bool operator()(const pair<int, pair<int, int> > &lhs,
                  const pair<int, pair<int, int> > &rhs) const {
    return (lhs.second.second > rhs.second.second);
  }
};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<pair<int, pair<int, int> > > EdgeList;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int dist = a[i] * abs(i - j);
      EdgeList.push_back(
          pair<int, pair<int, int> >(i, pair<int, int>(j, dist)));
    }
  }
  sort(EdgeList.begin(), EdgeList.end(), compare());
  vector<int> occupied(n, 0);
  vector<int> vacated(n, 0);
  int sz = EdgeList.size();
  long long ans = 0;
  for (int i = 0; i < sz; i++) {
    int u = EdgeList[i].first, v = EdgeList[i].second.first,
        d = EdgeList[i].second.second;
    if (occupied[v] == 1) continue;
    if (vacated[u] == 1) continue;
    ans += d;
    occupied[v] = 1;
    vacated[u] = 1;
  }
  cout << ans << endl;
  cerr << endl
       << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
}
