#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-8;
void solve(long long N, std::vector<long long> A) {
  int left = 0, right = N - 1;
  long long answer = 0;
  vector<bool> used(N, false);
  for (long long i = (0); i < (N); i++) {
    int maxIndex = left;
    long long maxValue = 0;
    bool isLeft = true;
    for (long long j = (0); j < (N); j++) {
      if (used[j]) continue;
      if (maxValue < A[j] * abs(j - left)) {
        maxValue = A[j] * abs(j - left);
        maxIndex = j;
        isLeft = true;
      }
      if (maxValue < A[j] * abs(j - right)) {
        maxValue = A[j] * abs(j - right);
        maxIndex = j;
        isLeft = false;
      }
    }
    answer += maxValue;
    used[maxIndex] = true;
    if (isLeft)
      left++;
    else
      right--;
  }
  cout << answer << endl;
}
signed main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}
