#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  ;
  vector<pair<long long, long long>> p;
  for (long long i = 0; i < n; i++) {
    p.push_back(make_pair(a[i], i));
  }
  vector<long long> vis(n), vis2(n);
  long long s = 0;
  sort(p.begin(), p.end());
  for (long long i = n - 1; i >= 0; i--) {
    long long m = 0;
    long long f = -1;
    for (long long j = 0; j < n; j++) {
      if (!vis[j]) {
        if (m < abs(p[i].first) * abs(j - p[i].second)) {
          m = abs(p[i].first) * abs(p[i].second - j);
          f = j;
        }
      }
    }
    vis[f] = 1;
    s += m;
  }
  cout << s << "\n";
  return 0;
}
