#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[2005];
  long long ans = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    long long sum = 0;
    priority_queue<pair<long long, long long> > que;
    for (int j = 0; j < i; j++) {
      que.push(pair<long long, long long>(a[j], j));
    }
    for (long long j = 0; j < i; j++) {
      pair<long long, long long> p = que.top();
      que.pop();
      sum += p.first * (n - 1 - j - p.second);
    }
    for (int j = i; j < n; j++) {
      que.push(pair<long long, long long>(a[j], j));
    }
    for (long long j = i; j < n; j++) {
      pair<long long, long long> p = que.top();
      que.pop();
      sum += p.first * (p.second + i - j);
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
