#include <bits/stdc++.h>
using namespace std;
const pair<long long, long long> dxy[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
const long long mod = 1e9 + 7;
const long long inf = 2e18;
const long double eps = 1e-9;
const long long NN = 2003;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
vector<pair<long long, long long> > a;
long long dp[NN][NN];
long long recur(long long i, long long j) {
  long long left = j - i + 1;
  ;
  if (left == 0) {
    return 0;
  }
  if (dp[i][j] != -1) return dp[i][j];
  long long idx = a[left - 1].second;
  long long v1 = abs(j - idx) * a[left - 1].first + recur(i, j - 1);
  long long v2 = abs(idx - i) * a[left - 1].first + recur(i + 1, j);
  ;
  return dp[i][j] = max(v1, v2);
}
void solve() {
  long long i = 0, j = 0, k = 0, n = 0, m = 0;
  cin >> n;
  a.resize(n);
  for (i = 0; i < (n); i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  memset(dp, -1, sizeof(dp));
  sort(a.begin(), a.end(),
       [](pair<long long, long long> &a, pair<long long, long long> &b) {
         if (a.first == b.first) return a.second < b.second;
         return a.first < b.first;
       });
  ;
  cout << recur(0, n - 1) << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long T = 1;
  for (long long tc = 1; tc <= T; tc++) {
    solve();
  }
  return 0;
}
