#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
long double eps = 1e-12;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long a[2010] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long left = 0;
  long long right = n - 1;
  long long ans = 0;
  for (int j = 0; j < n; j++) {
    long long best = -1;
    long long bestind = -1;
    int dir = -1;
    for (int i = 0; i < n; i++) {
      if (best < max(a[i] * (i - left), a[i] * (right - i))) {
        bestind = i;
        if (a[i] * (i - left) > a[i] * (right - i)) {
          dir = 0;
          best = a[i] * (i - left);
        } else {
          dir = 1;
          best = a[i] * (right - i);
        }
      }
    }
    a[bestind] = 0;
    ans += best;
    if (dir == 0)
      left++;
    else
      right--;
  }
  cout << ans << endl;
}
