#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
bool prime[10000001];
long long P = 1000000007 - 2;
long long factorial[10000001] = {0};
long long powerFunction(long long x, long long y) {
  long long res = 1;
  long long p = 1000000007;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void sieveFunction(long long maxLimit) {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (long long i = 2; maxLimit >= i; i++) {
    if (prime[i]) {
      for (long long j = 2 * i; maxLimit >= j; j += i) prime[j] = false;
    }
  }
}
void factorialFunction(long long maxLimit) {
  factorial[0] = 1;
  for (long long i = 1; i <= maxLimit; i++)
    factorial[i] = (factorial[i - 1] * i) % 1000000007;
  return;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
signed main() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; n > i; i++) {
    cin >> arr[i];
  }
  long long has[n];
  memset(has, -1, sizeof(has));
  long long l = 0, r = n - 1;
  long long cnt = n;
  long long ans = 0;
  while (cnt--) {
    long long mx = INT64_MIN;
    long long id = -1;
    for (long long i = 0; n > i; i++) {
      if (has[i] == -1) {
        if (arr[i] * (max(abs(i - l), abs(i - r))) > mx) {
          mx = arr[i] * (max(abs(i - l), abs(i - r)));
          id = i;
        }
      }
    }
    has[id] = 1;
    if (abs(id - l) > abs(id - r)) {
      l++;
    } else {
      r--;
    }
    ans += mx;
  }
  cout << ans << "\n";
}
