#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, sum, a, b, arr[2 * 1003], vis[2 * 1003];
long long int ans;
string str;
int main() {
  ios::sync_with_stdio(false);
  {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    int l = 1, r = n;
    for (int i = 0; i < n; i++) {
      int lIdx, rIdx;
      long long int lValue, rValue, lMax = -1, rMax = -1;
      for (int j = 1; j <= n; j++) {
        if (!vis[j]) {
          lValue = abs(j - l) * 1ll * arr[j];
          rValue = abs(j - r) * 1ll * arr[j];
          if (rMax < rValue) {
            rMax = rValue;
            rIdx = j;
          }
          if (lMax < lValue) {
            lMax = lValue;
            lIdx = j;
          }
        }
      }
      if (rMax < lMax) {
        ans += lMax;
        vis[lIdx] = 1;
        l++;
      } else {
        ans += rMax;
        vis[rIdx] = 1;
        r--;
      }
    }
    cout << ans;
  }
  return 0;
}
