#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<long long> pre, suff;
  long long ans = arr[1] + arr[0];
  pre.push_back(0);
  pre.push_back(1);
  suff.push_back(1);
  suff.push_back(0);
  for (long long i = 2; i < n; i++) {
    long long temp = ans + (arr[i] * (i)), ind = 0;
    for (long long j = 1; j < i; j++) {
      if (ans + pre[j] + suff[j - 1] + (arr[i] * (i - j)) > temp) {
        temp = ans + pre[j] + suff[j - 1] + (arr[i] * (i - j));
        ind = j;
      }
    }
    pre.insert(pre.begin() + ind, 0);
    suff.insert(suff.begin() + ind, arr[i]);
    for (long long j = 1; j <= i; j++) {
      pre[j] += pre[j - 1];
      suff[j - 1] += suff[j];
    }
    ans = temp;
  }
  cout << ans;
}
int main() {
  long long t = 1, i = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  std::cout.precision(6);
  std::cout.setf(std::ios::fixed, std::ios::floatfield);
  while (i <= t) {
    solve();
    i++;
  }
  return 0;
}
