#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    lint ret = 0;
    for (int i = 0; i < n; ++i) {
        vector<pair<lint, lint>> l, r;
        for (int j = 0; j < i; ++j) {
            r.emplace_back(a[j], j);
        }
        for (int j = i; j < n; ++j) {
            l.emplace_back(a[j], j);
        }
        lint temp = 0;
        sort(r.begin(), r.end(), greater<>());
        sort(l.begin(), l.end(), greater<>());
        lint rpos = n - 1, lpos = 0;
        for (auto &b : r) {
            temp += abs(b.second - rpos) * b.first;
            rpos--;
        }
        for (auto &b : l) {
            temp += abs(b.second - lpos) * b.first;
            lpos++;
        }
        chmax(ret, temp);
    }
    cout << ret << "\n";
    return 0;
}