#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using Graph = vector<vector<int>>;
using Edge = map<pair<int, int>, int>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  cout << fixed << setprecision(15);
  long long N;
  cin >> N;
  vector<long long> A(N + 1);
  vector<bool> use(N + 1, true);
  A[0] = 0;
  for (long long i = 0; i < (long long)(N); ++i) {
    cin >> A[i + 1];
  }
  long long start = 1;
  long long end = N;
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    long long maxa = 0;
    long long dis = 0;
    long long used = 0;
    bool st = true;
    for (long long j = 1; j <= N; j++) {
      if (use[j]) {
        if ((abs(start - j) * A[j] > maxa) ||
            ((abs(start - j) * A[j] == maxa) && (abs(start - j) > dis))) {
          maxa = abs(start - j) * A[j];
          dis = abs(start - j);
          st = true;
          used = j;
        }
        if ((abs(end - j) * A[j] > maxa) ||
            ((abs(end - j) * A[j] == maxa) && (abs(end - j) > dis))) {
          maxa = abs(end - j) * A[j];
          dis = abs(end - j);
          st = false;
          used = j;
        }
      }
    }
    if (st)
      start++;
    else
      end--;
    use[used] = false;
    ans += maxa;
  }
  cout << ans << endl;
  return 0;
}
