#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<int> pqmaxi;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, long long> > a(2005);
  bool b[2005];
  a[0].second = a[0].first = 0;
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a.at(i).first;
    a.at(i).second = i;
  }
  for (int i = 0; i < (int)(n + 5); i++) b[i] = 1;
  sort(a.begin(), a.begin() + n + 1);
  for (int i = n; i > 0; i--) {
    int t = a[i].second;
    int maxi = 0;
    int kari = -1;
    for (int j = 1; j <= n; j++) {
      if (b[j] == 0) continue;
      if (maxi < abs(j - t)) {
        maxi = max(maxi, abs(j - t));
        kari = j;
      }
    }
    b[kari] = 0;
    tot += maxi * a[i].first;
  }
  cout << tot << endl;
  return 0;
}
