#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1e9 + 7;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (n); i++) {
    cin >> a[i];
  }
  vector<vector<long long>> b(n, vector<long long>(n));
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (n); j++) {
      b[i][j] = a[i] * abs(i - j);
    }
  }
  long long le = 0;
  long long ri = n - 1;
  bool ok = true;
  long long ans = 0;
  vector<bool> c(n, false);
  while (ok) {
    bool l = false;
    bool r = false;
    long long m = 0;
    long long pos_i = -1;
    long long pos_j = -1;
    for (long long i = 0; i < (n); i++) {
      if (c[i]) continue;
      if (m < b[i][le]) {
        pos_i = i;
        pos_j = le;
        m = max(m, b[i][le]);
      }
    }
    for (long long i = 0; i < (n); i++) {
      if (c[i]) continue;
      if (m < b[i][ri]) {
        pos_i = i;
        pos_j = ri;
        m = max(m, b[i][ri]);
      }
    }
    if (pos_i != -1) c[pos_i] = true;
    ans += m;
    if (le == ri) break;
    if (pos_j == le)
      le++;
    else if (pos_j == ri)
      ri--;
  }
  cout << ans << endl;
  return 0;
}
