#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = (0); i < (n); ++i) cin >> a[i];
  ll ans = 0;
  ll l = 0;
  ll r = n - 1;
  vector<bool> used(n);
  for (int i = (0); i < (n); ++i) {
    bool left = true;
    ll fun = -1;
    int index = -1;
    for (int j = (0); j < (n); ++j) {
      if (used[j]) continue;
      ll temp = a[j] * max(j - l, r - j);
      if (temp > fun) {
        if (j - l > r - j)
          left = true;
        else
          left = false;
        fun = temp;
        index = j;
      }
    }
    if (left)
      l++;
    else
      r--;
    ans += fun;
    used[index] = true;
  }
  cout << ans << endl;
  return 0;
}
