#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
const ll mod = 1000000007;
void testCase() {
  int n;
  cin >> n;
  ll a[n + 3];
  for (int i = 1; i <= n; i++) cin >> a[i];
  ll mat[n + 2][n + 2];
  set<pair<ll, pair<int, int>>> s;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      mat[i][j] = a[i] * abs(i - j);
      s.insert(make_pair(mat[i][j], make_pair(i, j)));
    }
  }
  ll ans = 0;
  int cnt = 0;
  while (cnt < n) {
    cnt++;
    pair<ll, pair<int, int>> p = *s.rbegin();
    ans += p.first;
    int i = p.second.first;
    int j = p.second.second;
    vector<pair<ll, pair<int, int>>> del;
    auto it = s.begin();
    while (it != s.end()) {
      p = (*it);
      if (p.second.first == i || p.second.second == j) del.push_back(p);
      it++;
    }
    for (pair<ll, pair<int, int>> p1 : del) {
      s.erase(p1);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  testCase();
  return 0;
}
