#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  vector<bool> bef(n, false);
  vector<ll> ans(n, 0);
  int l = 0;
  int r = n - 1;
  for (int i = 0; i < (n); ++i) {
    ll mx = -1;
    int idx = -1;
    bool left;
    int d = 3000;
    for (int j = 0; j < (n); ++j) {
      if (bef[j]) continue;
      ll s1 = abs(j - l) * a[j];
      ll s2 = abs(r - j) * a[j];
      int dist = 0;
      if (s1 > s2)
        dist = abs(j - l);
      else
        dist = abs(r - j);
      if (max(s1, s2) >= mx) {
        if (idx != -1 && max(s1, s2) == mx) {
          if (d > dist) continue;
        }
        mx = max(s1, s2);
        idx = j;
        if (s1 > s2)
          left = true;
        else
          left = false;
      }
    }
    bef[idx] = true;
    ans[idx] = mx;
    if (left)
      l++;
    else
      r--;
  }
  ll sum = 0;
  for (int i = 0; i < (n); ++i) {
    sum += ans[i];
  }
  cout << sum << endl;
}
