#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  scanf("%d", &N);
  vector<int> A(N + 1);
  A[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    scanf("%d", &A[i]);
  }
  long long happy = 0;
  int m;
  int left = 1;
  int right = N;
  int left_max;
  int right_max;
  int left_max_j;
  int right_max_j;
  int happy_m;
  for (int i = 0; i < N; i++) {
    left_max = 0;
    right_max = 0;
    for (int j = 1; j < N + 1; j++) {
      if (left_max <= A[j] * (j - left)) {
        left_max = A[j] * (j - left);
        left_max_j = j;
      }
      if (right_max <= A[j] * (right - j)) {
        right_max = A[j] * (right - j);
        right_max_j = j;
      }
    }
    if (left_max > right_max) {
      m = left_max_j;
      happy_m = left_max;
    } else {
      m = right_max_j;
      happy_m = right_max;
    }
    if (left_max > right_max) {
      happy += left_max;
      A[m] = 0;
      left++;
    } else {
      happy += right_max;
      A[m] = 0;
      right--;
    }
  }
  printf("%lld", happy);
  return 0;
}
