#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000009;
long long MOD = 1000000007;
long long a[2020];
bool moved[2020];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < 2020; i++) {
    moved[i] = false;
  }
  long long l = 0;
  long long r = n - 1;
  long long ans = 0;
  while (r - l >= 0) {
    long long tmp = 0;
    long long pointer = 0;
    for (long long i = 0; i < n; i++) {
      if (moved[i]) continue;
      if (tmp <= a[i] * max(long long(abs(long long(i - l))),
                            long long(abs(long long(r - i))))) {
        tmp = a[i] * max(long long(abs(long long(i - l))),
                         long long(abs(long long(r - i))));
        pointer = i;
      }
    }
    ans += a[pointer] * max(long long(abs(long long(pointer - l))),
                            long long(abs(long long(r - pointer))));
    moved[pointer] = true;
    if (abs(pointer - l) < abs(r - pointer))
      r--;
    else
      l++;
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
