#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  ;
  long long n, i, j, k, happy = 0, a[2001], left = 0, right;
  cin >> n;
  right = n - 1;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  set<int> vis;
  long long maxi = 0, curr = -1, side = -1;
  for (i = 0; i < n; i++) {
    maxi = -1;
    curr = -1;
    side = -1;
    for (j = 0; j < n; j++) {
      if (vis.find(j) != vis.end()) continue;
      if (maxi < (abs(left - j) * a[j])) {
        maxi = abs(left - j) * a[j];
        curr = j;
        side = 0;
      }
      if (maxi < (abs(right - j) * a[j])) {
        maxi = abs(right - j) * a[j];
        curr = j;
        side = 1;
      }
    }
    if (side == 0) {
      left++;
      vis.insert(curr);
      happy += maxi;
    } else if (side == 1) {
      right--;
      vis.insert(curr);
      happy += maxi;
    } else
      break;
  }
  cout << happy << "\n";
  return 0;
}
