#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  v.clear();
  v.resize(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v[i] = make_pair(x, i);
  }
  sort(v.begin(), v.end());
  bool visited[n];
  int total = 0;
  for (int i = 0; i < n; i++) visited[i] = false;
  for (int i = n - 1; i >= 0; i--) {
    int r = v[i].second;
    int dist = 0;
    for (int j = 0; j < n; j++) {
      if (visited[j] == false) {
        int cur_val = v[i].first * abs(j - v[i].second);
        if (cur_val >= dist) {
          dist = cur_val;
          r = j;
        }
      }
    }
    visited[r] = true;
    total += dist;
  }
  cout << total;
  return 0;
}
