#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000007;
long long n, a[2005], ans, b[2005];
vector<pair<long long, int> > v;
int main(void) {
  cin >> n;
  for (int i = (1); i < (n + 1); i++) scanf("%lld", &a[i]);
  for (int i = (1); i < (n + 1); i++) v.push_back(make_pair(a[i], i));
  sort((v).begin(), (v).end(), greater<pair<long long, int> >());
  for (int i = 0; i < n; i++) {
    long long vv = v[i].first;
    long long pos = v[i].second;
    int insert = 1;
    long long mx = 0;
    for (int j = 1; j <= n; j++) {
      if (abs(pos - j) * vv > mx && b[j] == 0) {
        insert = j;
        mx = abs(pos - j) * vv;
      }
    }
    b[insert] = vv;
    ans += abs(pos - insert) * vv;
  }
  cout << ans << endl;
  return 0;
}
