#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e3;
int n;
long long int a[maxN];
bool done[maxN];
struct Node {
  long long int value;
  int to, i;
  bool operator<(const Node &other) const {
    return value < other.value || (value == other.value && a[i] > a[other.i]);
  }
};
int main() {
  while (scanf("%d", &n) != EOF) {
    memset(done, false, sizeof(done));
    set<int> available;
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]), available.insert(i);
    priority_queue<Node> pq;
    for (int i = 0; i < n; i++) {
      int left = i, right = n - i - 1;
      pq.push({a[i] * left, 0, i});
      pq.push({a[i] * right, n - 1, i});
    }
    long long int ans = 0;
    while (!pq.empty()) {
      Node u = pq.top();
      pq.pop();
      if (0) printf("\t%lld %d %d\n", u.value, u.to, u.i);
      if (done[u.i]) continue;
      if (!available.count(u.to)) {
        int left = *available.begin();
        int right = *available.rbegin();
        pq.push({a[u.i] * abs(u.i - left), left, u.i});
        pq.push({a[u.i] * abs(u.i - right), right, u.i});
        continue;
      }
      ans += u.value;
      available.erase(u.to);
      done[u.i] = true;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
