#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (n); i++) {
    cin >> a[i];
  }
  long long ans = 0;
  long long left = 0;
  long long right = n - 1;
  long long disl;
  long long disr;
  long long max_num;
  bool flag;
  vector<long long> b(n);
  for (long long j = 0; j < (n); j++) {
    max_num = 0;
    for (long long i = 0; i < (n); i++) {
      disl = (i - left) * a[i];
      disr = (right - i) * a[i];
      if (disl >= disr) {
        b[i] = disl;
      } else {
        b[i] = disr;
      }
      if (b[i] > max_num) {
        max_num = b[i];
        if (b[i] == disl)
          flag = true;
        else
          flag = false;
      }
    }
    long long maxIndex = max_element(b.begin(), b.end()) - b.begin();
    ans += b[maxIndex];
    a[maxIndex] = 0;
    if (flag)
      left++;
    else
      right--;
  }
  cout << ans << endl;
  return 0;
}
