#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (long long i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
  for (long long i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << endl;
    os << v[i];
  }
  return os;
}
const int md = 1000000007;
const int INF = 1 << 30;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  long long sum = 0;
  int l = 0;
  int r = n - 1;
  vector<bool> v(n, false);
  for (long long i = (0), __last_i = (n); i < __last_i; i++) {
    int na = 0;
    bool le = true;
    int ni = 0;
    for (long long i = (0), __last_i = (n); i < __last_i; i++) {
      if (v[i]) continue;
      long long nl = a[i] * abs(i - l);
      long long nr = a[i] * abs(r - i);
      if (nl > nr) {
        if (nl > na) {
          na = nl;
          ni = i;
          le = true;
        }
      } else {
        if (nr > na) {
          na = nr;
          ni = i;
          le = false;
        }
      }
    }
    sum += na;
    v[ni] = true;
    if (le)
      l++;
    else
      r--;
  }
  cout << sum << endl;
}
