#include <bits/stdc++.h>
using namespace std;
long long mod(long long a, long long b) {
  if (a % b < 0) {
    return a % b + b;
  }
  return a % b;
}
long long mod_exp(long long a, long long b, long long c) {
  long long res = 1;
  a = a % c;
  while (b > 0) {
    if (b % 2 == 1) {
      res = (res * a) % c;
    }
    b /= 2;
    a = (a * a) % c;
  }
  return res;
}
long long mymod(long long a, long long b) { return ((a % b) + b) % b; }
bool prime[200001];
void SieveOfEratosthenes() {
  memset(prime, true, sizeof(prime));
  prime[1] = false;
  for (int p = 2; p * p <= 200000; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= 200000; i += p) prime[i] = false;
    }
  }
  return;
}
long long powe[200005];
void power() {
  powe[0] = 1;
  for (long long i = 1; i < 200005; i++) {
    powe[i] = mymod(2 * powe[i - 1], 1000000007);
  }
}
long long gcdExtended(long long, long long, long long *, long long *);
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  long long res = (x % m + m) % m;
  return res;
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long n;
struct node {
  vector<long long> adj;
  long long dist;
  long long cwgd;
};
long long facto[200005], pre[200005];
long long nCr(long long n, long long r) {
  long long a = facto[n];
  a = mymod(a * modInverse(facto[r], 1000000007), 1000000007);
  a = mymod(a * modInverse(facto[n - r], 1000000007), 1000000007);
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > A(n);
  for (long long i = 0; i < n; i++) {
    cin >> A[i].first;
    A[i].second = i + 1;
  }
  long long max = n, min = 1;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    pair<long long, long long> maxdiff = {-1, -1};
    long long index = -1;
    for (long long x = 0; x < A.size(); x++) {
      if ((A[x].second - min) * A[x].first > maxdiff.first) {
        maxdiff = {(A[x].second - min) * A[x].first, 0};
        index = x;
      }
      if ((max - A[x].second) * A[x].first > maxdiff.first) {
        maxdiff = {(max - A[x].second) * A[x].first, 1};
        index = x;
      }
    }
    ans += (maxdiff.first);
    A.erase(A.begin() + index);
    (maxdiff.second == 1) ? max-- : min++;
  }
  cout << ans << endl;
  return 0;
}
