#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long INF = 1ll << 60;
const double PI = 2 * asin(1);
void yes() { printf("yes\n"); }
void no() { printf("no\n"); }
void Yes() { printf("Yes\n"); }
void No() { printf("No\n"); }
void YES() { printf("YES\n"); }
void NO() { printf("NO\n"); }
int N;
long long ans = 0, A[2005], Point[2005][2005];
priority_queue<pair<pair<long long, long long>, pair<long long, long long> > >
    que;
bool usedi[2005], usedj[2005];
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    for (long long j = 0; j < N; j++) {
      Point[i][j] = A[i] * abs(i - j);
      pair<long long, long long> P = make_pair(Point[i][j], -1 * A[i]);
      que.push(make_pair(P, make_pair(i, j)));
    }
  }
  while (!que.empty()) {
    pair<pair<long long, long long>, pair<long long, long long> > Q = que.top();
    que.pop();
    int i = Q.second.first, j = Q.second.second;
    if (usedi[i] || usedj[j]) continue;
    ans += Q.first.first;
    usedi[i] = true;
    usedj[j] = true;
  }
  cout << ans << endl;
  return 0;
}
