#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin.exceptions(cin.failbit);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<pair<long long, pair<long long, long long>>> edges;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      long long t = a[j] * abs(i - j);
      edges.push_back(make_pair(-t, make_pair(i, j)));
    }
  }
  sort(edges.begin(), edges.end());
  long long res = 0;
  vector<bool> checkpos(n, 0);
  vector<bool> checkchild(n, 0);
  for (long long i = 0; i < edges.size(); i++) {
    long long pos = edges[i].second.first;
    long long child = edges[i].second.second;
    if (checkpos[pos] || checkchild[child]) continue;
    checkpos[pos] = true;
    checkchild[child] = true;
    res += -edges[i].first;
  }
  cout << res << '\n';
  return 0;
}
