#include <bits/stdc++.h>
using namespace std;
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int c[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    c[i] = 0;
  }
  qsort(a, n, sizeof(int), compare_int);
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int x = 0;
    int y = 0;
    int z = 0;
    for (int j = 0; j < n; j++) {
      if (b[j] == a[i]) {
        z = b[j];
        b[j] = 0;
        for (int k = 0; k < n; k++) {
          if (abs(k - j) > y && c[k] == 0) {
            x = k;
            y = abs(j - k);
          }
        }
      } else {
        continue;
      }
      break;
    }
    ans += (y * z);
    c[x] = 1;
  }
  cout << ans << endl;
}
