#include <bits/stdc++.h>
using namespace std;
using VP = vector<pair<long long, long long> >;
using VVP = vector<VP>;
using VI = vector<long long>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const long long INF = 1LL << 61;
const long long mod = 1e9 + 7;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, j;
  long long n;
  cin >> n;
  long long a[n];
  long long ans = 0;
  for (i = 0; i < n; i++) cin >> a[i];
  for (j = 0; j < n; j++) {
    vector<pair<long long, long long> > b1, b2;
    for (i = 0; i < j; i++) {
      b1.push_back(pair<long long, long long>(a[i], i));
    }
    for (i = j; i < n; i++) {
      b2.push_back(pair<long long, long long>(a[i], i));
    }
    sort(b1.begin(), b1.end());
    sort(b2.begin(), b2.end());
    reverse(b1.begin(), b1.end());
    reverse(b2.begin(), b2.end());
    long long sum1 = 0;
    int s = b1.size();
    for (i = 0; i < s; i++) {
      sum1 += abs((n - 1 - i - b1[i].second)) * b1[i].first;
    }
    int t = b2.size();
    for (i = 0; i < t; i++) {
      sum1 += abs((b2[i].second - i)) * b2[i].first;
    }
    chmax(ans, sum1);
  }
  cout << ans << endl;
}
