#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n;
pair<long long, long long> a[N];
long long f[N][N];
long long F(int i, int j) {
  if (i > j) {
    return 0;
  }
  if (f[i][j] != -1) {
    return f[i][j];
  }
  int now = j - i + 1;
  long long ans = 0;
  ans = max(F(i, j - 1) + abs(a[now].second - j) * a[now].first,
            F(i + 1, j) + abs(a[now].second - i) * a[now].first);
  return f[i][j] = ans;
}
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  return (x.first != y.first ? x.first < y.first : x.second > y.second);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1, cmp);
  memset(f, -1, sizeof(f));
  long long ans = 0;
  cout << F(1, n);
  return 0;
}
