#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
const long long MOD = 1000000007;
signed main() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < (n); i++) cin >> a[i];
  vector<bool> vis(n, 0);
  long long ans = 0;
  long long l = 0, r = n - 1;
  for (int cnt = 0; cnt < (n); cnt++) {
    pair<long long, long long> Pma = {0, 0};
    for (long long i = 0; i < n; i++) {
      if (vis[i]) continue;
      if (Pma.first < a[i] * llabs(r - i) ||
          (Pma.first == a[i] * llabs(r - i) && (i - l) < (r - i))) {
        Pma = {a[i] * llabs(r - i), -i};
      }
      if (Pma.first < a[i] * llabs(i - l) ||
          (Pma.first == a[i] * llabs(i - l) && (i - l) > (r - i))) {
        Pma = {a[i] * llabs(i - l), i};
      }
    }
    ans += Pma.first;
    if (Pma.second > 0) {
      vis[Pma.second] = 1;
      l++;
    } else {
      vis[-Pma.second] = 1;
      r--;
    }
  }
  cout << ans << endl;
}
