#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool pairCompare(const pair<ll, int>& firstElof,
                 const pair<ll, int>& secondElof) {
  if (firstElof.first != secondElof.first)
    return firstElof.first > secondElof.first;
  else
    return firstElof.second > secondElof.second;
}
int main() {
  int N;
  cin >> N;
  vector<int> q(N);
  vector<pair<ll, int>> p(N);
  for (int i = 0; i < N; i++) {
    q[i] = i + 1;
  }
  for (int i = 0; i < N; i++) {
    ll kasei;
    cin >> kasei;
    p[i] = make_pair(kasei, i + 1);
  }
  sort(p.begin(), p.end(), pairCompare);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    int max_sa = -5000;
    int max_index = 0;
    for (int j = 0; j < q.size(); j++) {
      int sa = abs(q[j] - p[i].second);
      if (max_sa < sa) {
        max_sa = sa;
        max_index = j;
      }
    }
    q.erase(q.begin() + max_index);
    sum += p[i].first * max_sa;
  }
  cout << sum << endl;
  return 0;
}
