#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &V) {
  os << '[';
  for (int i = 0; i < (int)V.size(); i++)
    os << V[i] << ",]"[i == (int)V.size() - 1];
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &V) {
  for (T &x : V) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << '{' << p.first << ',' << p.second << '}';
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
void minself(T &a, T &b) {
  a = min(a, b);
}
template <typename T>
void maxself(T &a, T &b) {
  a = max(a, b);
}
int fastexp(long long base, long long esp, int mod) {
  long long res = 1LL;
  base %= mod;
  while (esp) {
    if (esp % 2) res = (res * base) % mod;
    esp /= 2;
    base = (base * base) % mod;
  }
  return res;
}
int inv(int n, int mod) { return fastexp(n, mod - 2, mod); }
vector<long long> __fact;
void fill_fact(int up_to, int mod) {
  __fact.resize(up_to + 1);
  __fact[0] = 1LL;
  for (int i = 1; i <= up_to; i++) __fact[i] = (__fact[i - 1] * i) % mod;
}
int bin(int n, int k, int mod) {
  if (n > (int)__fact.size() || k > (int)__fact.size())
    fill_fact(max(n, k), mod);
  long long den = (__fact[k] * __fact[n - k]) % mod;
  return (__fact[n] * inv(den, mod)) % mod;
}
int const MAXN = 2010;
int n, memo[MAXN][MAXN];
vector<int> v;
vector<pair<int, int>> order;
int dp(int start, int end) {
  if (start > end) return 0;
  int &res = memo[start][end];
  if (res != -1) return res;
  int i = (n - 1 - end) + start;
  int val = order[i].first;
  int index = order[i].second;
  return res = max(val * abs(index - start) + dp(start + 1, end),
                   val * abs(end - index) + dp(start, end - 1));
}
int main() {
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
  cin >> n;
  v.resize(n);
  cin >> v;
  order.resize(n);
  for (int i = 0; i < n; i++) order[i] = {v[i], i};
  sort(order.rbegin(), order.rend());
  memset(memo, -1, sizeof(memo));
  cout << dp(0, n - 1);
}
