#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
  long long n, ans = 0;
  cin >> n;
  vector<long long> a(n);
  vector<bool> ok(n, true);
  for (long long i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  long long b = 0, e = 0;
  for (long long i = (0); i < (n); ++i) {
    vector<long long> dp(n, 0);
    for (long long j = (0); j < (n); ++j) {
      if (ok[j]) {
        dp[j] = a[j] * max(n - e - 1 - j, j - b);
      }
    }
    auto ite = max_element(dp.begin(), dp.end());
    ans += *ite;
    long long m = ite - dp.begin();
    if (n - e - 1 - m > m - b) {
      e++;
    } else {
      b++;
    }
    ok[m] = false;
  }
  cout << ans << endl;
}
