#include <bits/stdc++.h>
using namespace std;
inline void normal(long long &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInverse(b));
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<pair<long long, long long> > b(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    b[i].second = i;
  }
  long long ans = 0;
  int l = 0, r = n - 1, cnt = 0;
  while (cnt < n) {
    for (int j = 0; j < (int)(n); j++) {
      b[j].first = max(j - l, r - j) * a[j];
    }
    sort((b).begin(), (b).end());
    int m = n - 1;
    for (int i = n - 1; i >= 0; --i) {
      if (b[m].first == b[i].first && a[b[m].second] > a[b[i].second]) {
        m = i;
      }
    }
    ans += b[m].first;
    if (a[b[m].second] * (b[m].second - l) >
        a[b[m].second] * (r - b[m].second)) {
      l++;
    } else if (a[b[m].second] * (b[m].second - l) <
               a[b[m].second] * (r - b[m].second)) {
      r--;
    } else {
      if (n - 1 - r > l)
        r--;
      else
        l--;
    }
    a[b[m].second] = 0;
    for (int i = 0; i < (int)(n); i++) {
      b[i].first = 0;
    }
    sort((b).begin(), (b).end());
    cnt++;
  }
  cout << ans << endl;
}
