#include <bits/stdc++.h>
using namespace std;
const int IINF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;
long long dfs(vector<long long> A, vector<long long> sorted, vector<int> ind,
              vector<bool> v, int i) {
  int N = A.size();
  if (i == N) {
    return 0;
  }
  vector<long long> s(N, -1);
  long long maxs = 0;
  for (int j = 0; j < (int)(N); j++) {
    if (!v[j]) {
      s[j] = abs(ind[i] - j) * sorted[i];
      maxs = max(maxs, s[j]);
    }
  }
  long long res = 0;
  for (int j = 0; j < (int)(N); j++) {
    if (s[j] == maxs) {
      vector<bool> n(v);
      n[j] = true;
      long long t = dfs(A, sorted, ind, n, i + 1);
      res = max(res, t);
    }
  }
  return maxs + res;
}
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < (int)(N); i++) {
    cin >> A[i];
  }
  vector<long long> sorted(A);
  sort((sorted).begin(), (sorted).end(), greater<long long>());
  vector<bool> sp(N, false);
  vector<int> ind(N);
  for (int i = 0; i < (int)(N); i++) {
    long long x = sorted[i];
    int index = -1;
    for (int j = 0; j < (int)(N); j++) {
      if (!sp[j] && A[j] == x) {
        index = j;
      }
    }
    ind[i] = index;
    sp[index] = true;
  }
  vector<bool> v(N, false);
  long long res = dfs(A, sorted, ind, v, 0);
  cout << res << endl;
  return 0;
}
