#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long long MAX_N = 200100;
bool leftsort(pair<long long, long long> lhs, pair<long long, long long> rhs) {
  long long a = lhs.first;
  long long b = lhs.second;
  long long c = rhs.first;
  long long d = rhs.second;
  if (a == c)
    return b > d;
  else
    return a < c;
}
bool rightsort(pair<long long, long long> lhs, pair<long long, long long> rhs) {
  long long a = lhs.first;
  long long b = lhs.second;
  long long c = rhs.first;
  long long d = rhs.second;
  if (a == c)
    return b < d;
  else
    return a > c;
}
bool memo[2010];
signed main() {
  long long N;
  cin >> N;
  vector<long long> q;
  for (long long i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    q.emplace_back(tmp);
  }
  long long ans = 0;
  long long left = 0;
  long long right = N - 1;
  for (long long i = 0; i < N; i++) {
    vector<pair<long long, pair<long long, bool>>> v;
    for (long long j = 0; j < N; j++) {
      if (!memo[j]) {
        v.push_back(make_pair(q[j] * abs(left - j), make_pair(j, true)));
        v.push_back(make_pair(q[j] * abs(right - j), make_pair(j, false)));
      }
    }
    sort((v).begin(), (v).end());
    pair<long long, pair<long long, bool>> tmp = v[v.size() - 1];
    memo[tmp.second.first] = true;
    ans += tmp.first;
    if (tmp.second.second) {
      left++;
    } else {
      right--;
    }
  }
  cout << ans << endl;
  return 0;
}
