#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
struct edge3
{
    long long to, cap, cost, rev;
};
#define MAX_V_mcf 66666
vector<edge3> G_mcf[MAX_V_mcf];
long long dist_mcf[MAX_V_mcf];
long long prevv_mcf[MAX_V_mcf], preve[MAX_V_mcf];

void add_edge3(long long from, long long to, long long cap, long long cost)
{
    G_mcf[from].push_back((edge3){to, cap, cost, G_mcf[to].size()});
    G_mcf[to].push_back((edge3){from, 0, -cost, G_mcf[from].size() - 1});
}
long long min_cost_flow(long long s, long long t, long long f, long long V)
{
    long long res = 0;
    while (f > 0)
    {
        fill(dist_mcf, dist_mcf + V, 1e18);
        dist_mcf[s] = 0;
        bool update = true;
        while (update)
        {
            update = false;
            for (long long v = 0; v < V; v++)
            {
                if (dist_mcf[v] == 1e18)
                    continue;
                for (long long i = 0; i < G_mcf[v].size(); i++)
                {
                    edge3 &e = G_mcf[v][i];
                    if (e.cap > 0 && dist_mcf[e.to] > dist_mcf[v] + e.cost)
                    {
                        dist_mcf[e.to] = dist_mcf[v] + e.cost;
                        prevv_mcf[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }
        if (dist_mcf[t] == 1e18)
        {
            return -1;
        }
        long long d = f;
        for (long long v = t; v != s; v = prevv_mcf[v])
        {
            d = min(d, G_mcf[prevv_mcf[v]][preve[v]].cap);
        }
        f -= d;
        res += d * dist_mcf[t];
        for (long long v = t; v != s; v = prevv_mcf[v])
        {
            edge3 &e = G_mcf[prevv_mcf[v]][preve[v]];
            e.cap -= d;
            G_mcf[v][e.rev].cap += d;
        }
    }
    return res;
}
int main()
{
    ll n;
    cin >> n;
    ll a[n];
    rp(i, 0, n) cin >> a[i];
    ll co = 0;

    rp(i, 0, n)
    {
        rp(j, 0, n)
        {
            ll cost = llabs(j - i) * (a[i] + a[j]);
            if(i!=j)
            add_edge3(i, j + n, 1, -1 * cost);
        }
    }
    rp(i, 0, n)
    {
        add_edge3(2*n, i , 1, 0);
        add_edge3(i + n , 2 * n + 1, 1, 0);

    }
    cout << (-1 * min_cost_flow(2*n, 2 * n+1, n, 2 * n + 2)+2)/2 << endl;
}