#include <bits/stdc++.h>
using namespace std;
int check[2002] = {0};
unsigned long long ans = 0;
struct node {
  int n;
  long long happy;
} a[2005];
int cmd(node a, node b) { return a.happy > b.happy; }
int main() {
  int rn, lo = 1, ro;
  cin >> rn;
  ro = rn;
  for (int i = 1; i <= rn; i++) {
    cin >> a[i].happy;
    a[i].n = i;
  }
  sort(a + 1, a + rn + 1, cmd);
  for (int i = 1; i <= rn; i++) {
    int maxn = 0;
    check[i] = 0;
    for (int j = 1; j <= rn; j++) {
      if (check[j] == 0) {
        if (abs(a[i].n - j) >= maxn) {
          maxn = abs(a[i].n - j);
          check[j] = 1;
        }
      }
    }
    ans += maxn * a[i].happy;
  }
  cout << ans << endl;
  return 0;
}
