#include <bits/stdc++.h>
using namespace std;
int n, le, ri, lv, rv, i;
long long a[2020], rr;
vector<pair<long long, int> > vv;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  lv = 1;
  rv = n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    vv.push_back(make_pair(a[i] * (long long)(max(i - lv, rv - i)), i));
  }
  sort(vv.begin(), vv.end());
  reverse(vv.begin(), vv.end());
  for (int ii = 0; ii < n; ii++) {
    i = vv[0].second;
    ri = max(rv, i);
    le = min(lv, i);
    if ((ri - i) >= (i - le)) {
      rv--;
      rr += (long long)(ri - i) * a[i];
    } else {
      lv++;
      rr += (long long)(i - le) * a[i];
    }
    for (int j = 1; j < vv.size(); j++) {
      i = vv[j].second;
      vv[j].first = a[i] * (long long)(max(i - min(lv, i), max(rv, i) - i));
    }
    vv.erase(vv.begin());
    sort(vv.begin(), vv.end());
    reverse(vv.begin(), vv.end());
  }
  cout << rr << endl;
  return 0;
}
