#include <bits/stdc++.h>
using namespace std;
bool compare(
    pair<long long int, pair<long long int, pair<long long int, long long int>>>
        v1,
    pair<long long int, pair<long long int, pair<long long int, long long int>>>
        v2) {
  if (v1.second.first == v2.second.first) {
    return v1.first < v2.first;
  }
  return v1.second.first > v2.second.first;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n];
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    vector<pair<long long int,
                pair<long long int, pair<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++) {
        if (i == j) continue;
        long long int x = (abs(j - i) * arr[i]);
        v.push_back(make_pair(arr[i], make_pair(x, make_pair(i, j))));
      }
    }
    sort(v.begin(), v.end(), compare);
    long long int ans = 0;
    map<long long int, long long int> m1;
    map<long long int, long long int> m2;
    for (long long int i = 0; i < v.size(); i++) {
      if (m1.count((v[i].second).second.second) == 0 &&
          m2.count((v[i].second).second.first) == 0) {
        ans += v[i].second.first;
        m1[(v[i].second).second.second]++;
        m2[(v[i].second).second.first]++;
      }
    }
    cout << ans << endl;
  }
}
