#include <bits/stdc++.h>
using namespace std;
const int mods = 1e9 + 7;
const int maxn = 2e3 + 10;
const int N = 1e5 + 10;
const int E = 2e5 + 10;
long long n, k;
long long a[maxn];
long long ans;
struct node {
  long long v, len;
  node(long long v = 0, long long len = 0) : v(v), len(len) {}
  bool operator<(const node &a) const { return len < a.len; }
};
vector<node> G[maxn];
bool vis[maxn];
long long dis[maxn];
void init() {
  for (int i = 1; i <= n; i++) {
    vis[i] = 0;
    dis[i] = 0;
  }
}
int dijkstra(int s) {
  priority_queue<node> Q;
  Q.push(node(s, 0));
  dis[s] = 0;
  while (!Q.empty()) {
    node now = Q.top();
    Q.pop();
    int v = now.v;
    if (vis[v]) continue;
    vis[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
      int v2 = G[v][i].v;
      int len = G[v][i].len;
      if (!vis[v2] && dis[v2] < dis[v] + len) {
        dis[v2] = dis[v] + len;
        Q.push(node(v2, dis[v2]));
      }
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= (n); ++i) {
    cin >> a[i];
    for (int j = 1; j <= (n); ++j) {
      if (i == j) continue;
      G[i].push_back(node(j, abs(j - i) * a[i]));
    }
  }
  for (int i = 1; i <= (n); ++i) {
    init();
    dijkstra(i);
    for (int j = 1; j <= (n); ++j) {
      if (i == j) continue;
      ans = max(ans, dis[j] + abs(j - i) * a[j]);
    }
  }
  cout << ans << endl;
}
