#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

ll mypow(ll x, ll n) {
    if (n == 0) return 1;
    if (n%2 == 0) return mypow(((x%mod)*(x%mod))%mod, n/2);
    else return ((x%mod) * mypow(((x%mod)*(x%mod))%mod, (n-1)/2))%mod;
}

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i=0; i<N; i++) cin >> A.at(i);
    vector<vector<ll>> table(N, vector<ll>(N));
    vector<vector<ll>> max_place(N, vector<ll>(1));
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            table.at(i).at(j) = A.at(i) * max(i - j, j - i);
        }
        ll max_value = 0;
        for (int j=0; j<N; j++) {
            if (table.at(i).at(j) > max_value) {
                max_value = table.at(i).at(j);
                max_place.at(i).at(0) = j;
            }
            else if (table.at(i).at(j) == max_value) {
                max_place.at(i).emplace_back(j);
            }
        }
    }
    ll sum = 0;
    set<int> non_fixed_place;
    set<int> non_fixed_baby;
    for (int i=0; i<N; i++) {
        non_fixed_place.insert(i);
        non_fixed_baby.insert(i);
    }
    for (int x=0; x<N; x++) {
        map<string, ll> max_set;
        max_set["value"] = 0;
        max_set["baby"] = 0;
        max_set["place"] = 0;
        for (auto baby : non_fixed_baby) {
            if (table.at(baby).at(max_place.at(baby).at(0)) > max_set["value"]) {
                max_set["value"] = table.at(baby).at(max_place.at(baby).at(0));
                max_set["baby"] = baby;
                max_set["place"] = max_place.at(baby).at(0);
            }
        }
        sum += max_set["value"];
        non_fixed_baby.erase(max_set["baby"]);
        non_fixed_place.erase(max_set["place"]);
        if (non_fixed_place.empty()) break;
        for (auto baby : non_fixed_baby) {
            for (int i=0; i<max_place.at(baby).size(); i++) {
                if (max_place.at(baby).at(i) == max_set["place"]) {
                    max_place.at(baby).at(i) = -1;
                    sort(max_place.at(baby).begin(), max_place.at(baby).end());
                    reverse(max_place.at(baby).begin(), max_place.at(baby).end());
                    max_place.at(baby).pop_back();
                }
            }
            if (max_place.at(baby).size() == 0) {
                if (max_set["place"] < baby) {
                    max_place.at(baby).emplace_back(max_set["place"] + 1);
                    if (2*baby - max_set["place"] + 1 <= *rbegin(non_fixed_place)) {
                        max_place.at(baby).emplace_back(2*baby - max_set["place"] + 1);
                    }
                }
                else {
                    max_place.at(baby).emplace_back(max_set["place"] - 1);
                    if (2*baby - max_set["place"] + 1 >= *begin(non_fixed_place)) {
                        max_place.at(baby).emplace_back(2*baby - max_set["place"] + 1);
                    }
                }
            }
        }
    }
    cout << sum << endl;
}