#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,n) for (int i = a;i<=n;++i)
#define per(i,a,n) for (int i = n;i>=a;--i)
#define all(x) (x).begin(), (x).end()     
#define SZ(x) ((int)x.size())

typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef long double ld;

mt19937 mrand(random_device{}());
ll rnd(ll a, ll b) { return a + mrand() % (b - a + 1); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 2510;
ll a[N];
int n, used[N], aux[N];

struct greedy {
      ll a, b, c, d;
} v[N*N];

bool cmp(greedy a, greedy b) {
      if (a.a != b.a) return a.a > b.a;
      return a.b > b.b;
}

int main() {
      ios::sync_with_stdio(false); cin.tie(0);
#ifdef arrias
      freopen("a.txt", "r", stdin);
#endif
      cin >> n;
      rep(i, 1, n) cin >> a[i];
      int sz = 0;
      rep(i, 1, n) {
            rep(j, 1, n) {
                  v[sz++] = { abs(i - j) * a[i], a[i], i, j };
            }
      }
      sort(v, v + sz, cmp);
      ll ans = 0;
      rep(i, 0, sz - 1) {
            if (used[v[i].c] || aux[v[i].d]) continue;
            used[v[i].c] = 1;
            aux[v[i].d] = 1;
            ans += v[i].a;
      }
      cout << ans << "\n";
      return 0;
}