#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
void chmax(T& a, T b) {
  a > b ?: a = b;
}
template <class T>
void chmin(T& a, T b) {
  a < b ?: a = b;
}
int main() {
  ll n, a[2000], b[2000] = {};
  ll ans = 0;
  set<ll> st;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    st.insert(i);
  }
  for (int i = 0; i < n; ++i) {
    ll l = *st.begin();
    ll r = *st.rbegin();
    ll maxv = -1, s = 0, t = 0;
    for (int j = 0; j < n; ++j) {
      if (!b[j] && maxv < a[j] * (j - l)) {
        maxv = a[j] * (j - l);
        s = j;
        t = l;
      }
      if (!b[j] && maxv < a[j] * (r - j)) {
        maxv = a[j] * (r - j);
        s = j;
        t = r;
      }
    }
    st.erase(st.find(t));
    b[s] = 1;
    ans += maxv;
  }
  cout << ans << endl;
  return 0;
}
