#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  priority_queue<pair<long long, pair<int, int> > > pq;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      pq.push({arr[i] * abs(j - i), {i, j}});
    }
  }
  long long max_ans = 0;
  vector<int> visited(n, 0);
  vector<int> done(n, 0);
  while (!pq.empty()) {
    auto x = pq.top();
    pq.pop();
    long long val = x.first;
    long long from = x.second.first;
    long long to = x.second.second;
    if (done[from] == 0 and visited[to] == 0) {
      visited[to] = 1;
      done[from] = 1;
      max_ans += val;
    }
  }
  cout << max_ans << endl;
  return 0;
}
