#include <bits/stdc++.h>
using namespace std;
const long double PIE = atan2(0, -1);
const long long MOD = 1e9 + 7;
const int MAXN = 2e3 + 5;
int n;
int a[MAXN];
bool cmp(int i, int j) { return a[i] > a[j]; }
void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<bool> taken(n);
  vector<int> indices;
  for (int i = 0; i < n; ++i) indices.push_back(i);
  sort(indices.begin(), indices.end(), cmp);
  long long ans = 0;
  for (auto ind : indices) {
    int newpos = -1;
    int maxshift = -1;
    for (int i = 0; i < n; ++i) {
      if (taken[i]) continue;
      if (maxshift < abs(ind - i)) {
        maxshift = abs(ind - i);
        newpos = i;
      }
    }
    assert(newpos != -1);
    ans += maxshift * 1ll * a[ind];
    taken[newpos] = true;
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
