#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<long long>> dist(n, vector<long long>(n));
  vector<long long> a(n);
  set<pair<long long, pair<long long, long long>>> s;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dist[i][j] = -abs(j - i) * a[i];
      s.insert({dist[i][j], {i, j}});
    }
  }
  long long ans = 0;
  while (!s.empty()) {
    auto it = *s.begin();
    s.erase(s.begin());
    ans += -it.first;
    int v = it.second.first;
    int u = it.second.second;
    for (int i = 0; i < n; i++) {
      if (s.find({dist[v][i], {v, i}}) != s.end()) {
        s.erase(s.find({dist[v][i], {v, i}}));
      }
      if (s.find({dist[i][u], {i, u}}) != s.end()) {
        s.erase(s.find({dist[i][u], {i, u}}));
      }
    }
  }
  cout << ans;
}
