#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
  int n;
  cin >> n;
  vector<int> lis(n, 0), flagpos(n + 1, 0), flagnum(n + 1, 0);
  for (int i = (0), i_len = (n); i < i_len; ++i) {
    cin >> lis[i];
  }
  priority_queue<pair<long long, pair<long long, long long> > > pq;
  for (int i = (0), i_len = (n); i < i_len; ++i) {
    for (int l = (0), l_len = (n); l < l_len; ++l) {
      long long k = lis[i] * abs(l - i);
      pair<long long, long long> po = {i, l};
      pq.push({k, po});
    }
  }
  int count = 0;
  long long ans = 0;
  while (count != n) {
    pair<long long, pair<long long, long long> > p = pq.top();
    pq.pop();
    if (flagpos[p.second.first] == 0 & flagnum[p.second.second] == 0) {
      flagpos[p.second.first] = 1;
      flagnum[p.second.second] = 1;
      ans += p.first;
      count++;
    }
  }
  cout << ans << endl;
}
