#include <bits/stdc++.h>
using namespace std;
const int mods = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 1e5 + 10;
const int E = 2e5 + 10;
long long n, k;
struct node {
  long long v, id;
} h[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= (n); ++i) {
    cin >> h[i].v;
    h[i].id = i;
  }
  int l = 1, r = n, idx;
  long long ans = 0, a, b, tmp;
  bool flg = 0;
  while (l <= r) {
    flg = 0;
    tmp = 0;
    for (int i = 1; i <= (n); ++i) {
      a = h[i].v * abs(h[i].id - l);
      b = h[i].v * abs(h[i].id - r);
      if (a > b) {
        if (a > tmp) {
          tmp = a;
          idx = i;
          flg = 0;
        } else if (a == tmp && flg == 0) {
          idx = i;
        }
      }
      if (b >= a) {
        if (b > tmp) {
          tmp = b;
          idx = i;
          flg = 1;
        }
      }
    }
    ans += tmp;
    h[idx].v = 0;
    if (flg == 0) {
      l++;
    } else
      r--;
  }
  cout << ans << endl;
}
