#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  pair<long long int, int> temp[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    temp[i].second = i;
  }
  int left = 1;
  int right = n;
  long long int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (right + left) / 2; j++) {
      temp[j].first = (right - j - 1) * a[j];
      temp[j].second = j;
    }
    for (int j = (right + left) / 2; j < n; j++) {
      temp[j].first = (j + 1 - left) * a[j];
      temp[j].second = j;
    }
    sort(temp, temp + n);
    if (temp[n - 1].second == (right + left) / 2 - 1 &&
        (right - left) % 2 == 0) {
      if (temp[n - 2].second < (right + left) / 2) {
        left++;
      } else {
        right--;
      }
    } else if (temp[n - 1].second < (right + left) / 2) {
      right--;
    } else {
      left++;
    }
    res += temp[n - 1].first;
    a[temp[n - 1].second] = 0;
  }
  cout << res << endl;
  return 0;
}
