#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
set<long long> s;
const long long N = 2005;
long long a[N];
pair<long long, long long> check(long long idx) {
  long long ans = 0, i;
  for (auto &it : s) {
    long long temp = a[it] * (abs(idx - it));
    if (temp >= ans) {
      ans = temp;
      i = it;
    }
  }
  return {i, ans};
}
int32_t main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) s.insert(i);
  for (long long i = 1; i <= n; i++) cin >> a[i];
  long long l = 1, r = n;
  long long ans = 0;
  while (!s.empty()) {
    pair<long long, long long> ans1 = check(l);
    pair<long long, long long> ans2 = check(r);
    if (ans1.second >= ans2.second) {
      l++;
      s.erase(ans1.first);
    } else {
      r--;
      s.erase(ans2.first);
    }
    ans += max(ans1.second, ans2.second);
  }
  cout << ans;
}
