#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class Monoid>
struct SegmentTree {
  using T = typename Monoid::T;
  int n;
  vector<T> data;
  SegmentTree() {}
  SegmentTree(int size, T initial_value = Monoid::unit()) {
    n = 1;
    while (n < size) n <<= 1;
    data.assign(2 * n - 1, initial_value);
    if (initial_value != Monoid::unit()) {
      for (int i = n - 2; i >= 0; i--)
        data[i] = Monoid::merge(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  SegmentTree(const vector<T>& v) {
    int size = v.size();
    n = 1;
    while (n < size) n <<= 1;
    data.assign(2 * n - 1, Monoid::unit());
    for (int i = 0; i < size; i++) data[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      data[i] = Monoid::merge(data[i * 2 + 1], data[i * 2 + 2]);
  }
  T getLeaf(int k) { return data[k + n - 1]; }
  void update(int k, T x) {
    k += n - 1;
    Monoid::update(data[k], x);
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = Monoid::merge(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return Monoid::unit();
    if (a <= l && r <= b)
      return data[k];
    else {
      T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return Monoid::merge(vl, vr);
    }
  }
  T query(int a, int b) { return query(a, b, 0, 0, n); }
  T query_fast(int a, int b) {
    T vl = Monoid::unit(), vr = Monoid::unit();
    for (int l = a + n, r = b + n; l != r; l >>= 1, r >>= 1) {
      if (l & 1) vl = Monoid::merge(vl, data[l++ - 1]);
      if (r & 1) vr = Monoid::merge(data[--r - 1], vr);
    }
    return Monoid::merge(vl, vr);
  }
};
template <class U = ll>
struct RangeMin {
  using T = U;
  static T merge(T x, T y) { return min(x, y); }
  static void update(T& target, T x) { target = x; }
  static constexpr T unit() { return numeric_limits<T>::max(); }
};
template <class U = ll>
struct RangeSum {
  using T = U;
  static T merge(T x, T y) { return x + y; }
  static void update(T& target, T x) { target += x; }
  static constexpr T unit() { return T(0); }
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> sort_ids(n);
  iota(sort_ids.begin(), sort_ids.end(), 0);
  sort(sort_ids.begin(), sort_ids.end(),
       [&](int i1, int i2) { return a[i1] > a[i2]; });
  ll ans = 0;
  int L = 0, R = n - 1;
  vector<int> used(n, false);
  for (int loop = 0; loop < n; ++loop) {
    int idx = -1;
    ll maxv = -1;
    for (int i = 0; i < n; ++i) {
      if (used[i]) continue;
      int vL = i - L;
      int vR = R - i;
      ll tmp = a[i] * max(vL, vR);
      if (tmp > maxv) {
        maxv = tmp;
        idx = i;
      }
    }
    ans += maxv;
    int i = idx;
    int vL = i - L;
    int vR = R - i;
    if (vL >= vR) {
      used[i] = true;
      ++L;
    } else {
      used[i] = true;
      --R;
    }
  }
  cout << ans << "\n";
  return 0;
}
