#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int> > qu2;
priority_queue<int> pq;
static const int NIL = -1;
static const int INF = 1000000007;
deque<int> deq;
const ll MOD = (1e+9) + 7;
bool chmx(int &a, int b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
bool chmn(int &a, int b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
int A[2005];
int visited[2005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    A[i] = a;
  }
  ll ans = 0;
  int l = 0, r = n - 1;
  for (int j = 0; j < (int)(n); j++) {
    if (j % 2 == 0) {
      int temp = -1;
      int k = -1;
      for (int i = 0; i < (int)(n); i++) {
        if (visited[i] == 0) {
          int tt = A[i] * abs(l - i);
          if (temp < tt) {
            k = i;
            temp = tt;
          }
        }
      }
      visited[k] = 1;
      ans += temp;
      l++;
    } else {
      int temp = -1;
      int k = -1;
      for (int i = 0; i < (int)(n); i++) {
        if (visited[i] == 0) {
          int tt = A[i] * abs(r - i);
          if (temp < tt) {
            k = i;
            temp = tt;
          }
        }
      }
      visited[k] = 1;
      ans += temp;
      r--;
    }
  }
  cout << ans << endl;
  return 0;
}
