#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<Pll> mans(N);
  for (int i = 0; i < N; i++) {
    cin >> mans[i].first;
    mans[i].second = i;
  }
  vector<Pll> mansp = mans;
  Vi used(N);
  ll ans = 0;
  ll ul = 0, ur = N - 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      ll power, idx;
      tie(power, idx) = mans[j];
      ll p = max(power * abs(idx - ul), power * abs(idx - ur));
      if (used[idx] == 1) p = -1;
      mansp[j].first = p;
      mansp[j].second = idx;
    }
    sort(mansp.begin(), mansp.end(), greater<Pll>());
    ans += mansp[0].first;
    used[mansp[0].second] = 1;
    ll idx_used = mansp[0].second;
    if (abs(idx_used - ul) >= abs(idx_used - ur)) {
      ++ul;
    } else {
      --ur;
    }
  }
  cout << ans << "\n";
  return 0;
}
