#include <bits/stdc++.h>
using namespace std;
int n;
int a[2001];
int main(int argc, char const *argv[]) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int distFront = 0;
  int distEnd = n - 1;
  int ans = 0;
  while (distFront <= distEnd) {
    int maxUre = 0;
    int maxUreIndex = 0;
    bool isFront;
    for (int j = 0; j < n; j++) {
      if (a[j] != 0) {
        if (j - distFront >= distEnd - j) {
          if ((j - distFront) * a[j] > maxUre) {
            maxUre = (j - distFront) * a[j];
            isFront = true;
            maxUreIndex = j;
          }
        } else if (j - distFront < distEnd - j) {
          if ((distEnd - j) * a[j] > maxUre) {
            maxUre = (distEnd - j) * a[j];
            isFront = false;
            maxUreIndex = j;
          }
        }
      }
    }
    if (isFront) {
      distFront++;
    } else {
      distEnd--;
    }
    ans += maxUre;
    a[maxUreIndex] = 0;
  }
  cout << ans << endl;
  return 0;
}
