#include <bits/stdc++.h>
using namespace std;
int main() {
  bool vis[2001];
  for (int i = 0; i < 2001; i++) vis[i] = false;
  int n;
  cin >> n;
  vector<pair<unsigned long long int, int>> vec(n + 1);
  unsigned long long int val;
  for (int i = 1; i <= n; i++) {
    cin >> val;
    vec[i].first = val;
    vec[i].second = i;
  }
  unsigned long long int happiness = 0;
  int left = 1;
  int right = n;
  while (true) {
    unsigned long long int maxi = 0;
    int dir = 0;
    int idx = -1;
    for (int i = 1; i <= n; i++) {
      if (!vis[vec[i].second]) {
        if (abs(vec[i].second - left) >= abs(vec[i].second - right) &&
            maxi <= vec[i].first * abs(vec[i].second - left)) {
          maxi = vec[i].first * abs(vec[i].second - left);
          dir = 0;
          idx = vec[i].second;
        } else if (abs(vec[i].second - right) >= abs(vec[i].second - left) &&
                   maxi <= vec[i].first * abs(vec[i].second - right)) {
          maxi = vec[i].first * abs(vec[i].second - right);
          dir = 1;
          idx = vec[i].second;
        }
      }
    }
    happiness += maxi;
    if (left == right) break;
    if (dir == 0)
      ++left;
    else
      --right;
    vis[idx] = true;
  }
  cout << happiness;
}
