#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;
  long weight;
  Edge(int t, long w) : to(t), weight(w) {}
};
long modpow(long a, long n, long mod) {
  long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long modinv(long a, long mod) { return modpow(a, mod - 2, mod); }
struct compare1 {
  bool operator()(const pair<long, long>& value, const long& key) {
    return (value.first < key);
  }
  bool operator()(const long& key, const pair<long, long>& value) {
    return (key < value.first);
  }
};
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  UnionFind(int n = 1) { init(n); }
  void init(int n = 1) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; (i) < (n); (i)++) par[i] = i, rank[i] = 0;
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x;
    return true;
  }
};
template <class Abel>
struct weightedUnionFind {
  vector<int> par;
  vector<int> rank;
  vector<Abel> diff_weight;
  weightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
  void init(int n = 1, Abel SUM_UNITY = 0) {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = 0; (i) < (n); (i)++)
      par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }
  int root(int x) {
    if (par[x] == x)
      return x;
    else {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }
  Abel weight(int x) {
    root(x);
    return diff_weight[x];
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y, Abel w) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y), w = -w;
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }
  Abel diff(int x, int y) { return weight(y) - weight(x); }
};
using Graph = vector<vector<int>>;
using P = pair<int, int>;
long GCD(long a, long b) {
  if (b == 0l) return a;
  if (a < b)
    return GCD(b, a);
  else
    return GCD(b, a % b);
}
long N;
long A[2005];
bool check[2005];
long rec(long left, long right) {
  if (left == right) {
    for (long i = 0; i < N; i++)
      if (!check[i]) return A[i] * abs(i - left);
  }
  long temp = 0l;
  long ind = 0l;
  for (long i = 0; i < N; i++)
    if (!check[i]) {
      long leftwa = A[i] * abs(i - left);
      long rightwa = A[i] * abs(i - right);
      if (temp < max(leftwa, rightwa)) {
        temp = max(leftwa, rightwa);
        ind = i;
      }
    }
  long leftwa = A[ind] * abs(ind - left);
  long rightwa = A[ind] * abs(ind - right);
  check[ind] = true;
  if (leftwa > rightwa) {
    return leftwa + rec(left + 1l, right);
  } else if (leftwa < rightwa) {
    return rightwa + rec(left, right - 1l);
  } else
    return max(leftwa + rec(left + 1l, right), rightwa + rec(left, right - 1l));
}
int main() {
  cin >> N;
  for (long i = 0; i < N; i++) cin >> A[i];
  for (long i = 0; i < N; i++) check[i] = false;
  cout << rec(0l, N - 1l) << endl;
  return 0;
}
