#include <bits/stdc++.h>
using namespace std;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
using long long = long long;
using pii = pair<long long, long long>;
using ld = long double;
using pll = pair<long long, long long>;
template <typename T>
void do_uniq(vector<T> vec) {
  sort((vec).begin(), (vec).end());
  vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
}
const int MAXN = 2e5 + 60;
vector<int> g[MAXN];
long long mod = 1e9 + 7;
bool usd[MAXN];
int n;
void solve() {
  int n;
  cin >> n;
  vector<pair<long long, pair<long long, int> > > v;
  for (int i = 0; i < n; ++i) {
    long long curr;
    cin >> curr;
    v.push_back({curr * max(i, n - 1 - i), {curr, i}});
  }
  sort((v).begin(), (v).end());
  reverse((v).begin(), (v).end());
  long long answr = 0;
  for (int i = 0; i < n; ++i) {
    int to = i;
    long long best = 0;
    for (int j = 0; j < n; ++j) {
      if (!usd[j]) {
        long long val = v[i].second.first * abs(v[i].second.second - j);
        if (val > best) {
          best = val;
          to = j;
        }
      }
    }
    answr += best;
    usd[to] = true;
  }
  cout << answr;
}
void multisolve() {
  int t;
  cin >> t;
  int i = 1;
  while (t--) {
    cout << "Case #" << (i++) << ": ";
    solve();
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(20);
  solve();
}
