#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct happy {
  int x;
  int y;
  int h;
};
bool operator<(const happy& h1, const happy& h2) { return h1.h < h2.h; };
bool operator>(const happy& h1, const happy& h2) { return h1.h > h2.h; };
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  vector<happy> H;
  for (int i = 0; i < (int)(N); i++)
    for (int j = 0; j < (int)(N); j++) H.push_back({i, j, A[i] * abs(j - i)});
  sort(H.begin(), H.end(), greater<happy>());
  bool used_x[N], used_y[N];
  for (int i = 0; i < (int)(N); i++) used_x[i] = false, used_y[i] = false;
  ll ans = 0;
  for (auto v : H) {
    if (used_x[v.x] || used_y[v.y]) {
      continue;
    }
    ans += v.h;
    used_x[v.x] = true;
    used_y[v.y] = true;
  }
  cout << ans << endl;
  return 0;
}
