#include <bits/stdc++.h>
using namespace std;
struct Node {
  int node, len;
  Node() { node = len = 0; }
  Node(int node, int len) { this->node = node, this->len = len; }
};
long long n;
pair<long long, long long> a[2001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  long long answer = 0;
  sort(a + 1, a + n + 1, greater<pair<long long, long long> >());
  long long left = 1, right = n;
  for (long long i = 1; i <= n; i++) {
    long long value = a[i].first, pos = a[i].second;
    cerr << value << ' ' << pos << '/' << left << ' ' << right << '\n';
    if (abs(pos - left) > abs(pos - right))
      answer += value * abs(pos - left), left++;
    else
      answer += value * abs(pos - right), right--;
    cerr << answer << '\n';
  }
  cout << answer;
}
