#include <bits/stdc++.h>
using namespace std;
long long mod(long long n) { return n > 0 ? n : -1 * n; }
long double dist(long long x1, long long y1, long long x2, long long y2) {
  long double ans = round(pow(mod(x2 - x1), 2)) + round(pow(mod(y2 - y1), 2));
  ans = sqrt(ans);
  return ans;
}
long double dist(pair<long long, long long> a, pair<long long, long long> b) {
  long double ans = round(pow(mod(b.first - a.first), 2)) +
                    round(pow(mod(b.second - a.second), 2));
  ans = sqrt(ans);
  return ans;
}
unordered_map<long long, long long> isPrime;
void SieveOfEratosthenes(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long p = 2; p <= n; p++)
    if (prime[p]) isPrime[p] = 1;
}
int *dp;
long long maxCompositeSummands(long long n) {
  if (n == 2 || n == 1 || n == 3) {
    return INT_MIN;
  }
  if (dp[n] != -1) {
    return dp[n];
  }
  long long mexx = INT_MIN;
  for (long long i = 4; i <= n; i++) {
    if (!isPrime[i]) {
      mexx = max(mexx, maxCompositeSummands(n - i));
    }
  }
  return dp[n] = mexx == INT_MIN ? mexx : mexx + 1;
}
bool comp(vector<long long> a, vector<long long> b) { return a[2] > b[2]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a;
  for (long long i = 0; i < (n); i++) {
    long long temp;
    cin >> temp;
    a.push_back(temp);
  }
  vector<vector<long long> > v;
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (n); j++) {
      if (i != j) {
        vector<long long> naya;
        naya.push_back(i);
        naya.push_back(j);
        naya.push_back(a[i] * abs(i - j));
        v.push_back(naya);
      }
    }
  }
  sort((v).begin(), (v).end(), comp);
  unordered_map<long long, long long> isAvailable;
  unordered_map<long long, long long> isAvailableSecond;
  long long ans = 0;
  long long total = 0;
  for (long long i = 0; i < (v.size()); i++) {
    if (isAvailableSecond[v[i][0]] == 0 && isAvailable[v[i][1]] == 0) {
      ans += v[i][2];
      isAvailable[v[i][1]] = 1;
      isAvailableSecond[v[i][0]] = 1;
      total++;
      if (total == n) {
        break;
      }
    }
  }
  cout << ans << endl;
}
