#include <bits/stdc++.h>
using namespace std;
const int mxN = 2000;
int N;
vector<pair<int, int>> v;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    pair<int, int> p;
    int happiness;
    cin >> happiness;
    p.first = happiness;
    p.second = i;
    v.push_back(p);
  }
  long long ans = 0;
  int total = 0, i = 0, flag = 0, left = 0, right = N - 1;
  while (total < N) {
    int m = 0;
    if (flag % 2 == 1) {
      i = right--;
    } else {
      i = left++;
    }
    flag++;
    total++;
    for (int j = 0; j < v.size(); j++) {
      if (v[j].first * abs(i - v[j].second) >
          v[m].first * abs(i - v[m].second)) {
        m = j;
      }
    }
    ans += v[m].first * abs(i - v[m].second);
    v.erase(v.begin() + m);
  }
  cout << ans << "\n";
  return 0;
}
