#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 2e3 + 10;
bool done[N];
const long long INF = 1e17;
void solve() {
  int n;
  cin >> n;
  long long ans = 0;
  vector<long long> v;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  for (int i = n - 1; i >= 0; --i) {
    int ind;
    long long mx = -INF;
    for (int j = n - 1; j >= 0; --j) {
      if (done[j]) continue;
      if (1LL * abs(j - i) * v[j] - 1LL * (j - 0) * v[j] > mx) {
        ind = j;
        mx = 1LL * abs(j - i) * v[j] - 1LL * (j - 0) * v[j];
      }
    }
    done[ind] = 1;
    ans += 1LL * abs(ind - i) * v[ind];
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
