#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int occu[n], moved[n];
  memset(moved, 0, sizeof(moved));
  memset(occu, 0, sizeof(occu));
  vector<tuple<long long int, long long int, long long int> > v;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      v.push_back(make_tuple(a[i] * abs(i - j), i, j));
    }
  }
  sort(v.begin(), v.end());
  long long int count = 0, ans = 0, j = (long long int)v.size() - 1;
  while (count < n) {
    long long int a, b, c;
    tie(a, b, c) = v[j];
    j--;
    if (occu[c] == 1 || moved[b] == 1) continue;
    occu[c] = 1;
    moved[b] = 1;
    ans += a;
    count++;
  }
  cout << ans << endl;
  return 0;
}
