#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define eb emplace_back
#define PI 3.14159265
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.rbegin(), c.rend()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double ld;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
ll dfs(int nd, int n, vector<bool> &vis, vll &a)
{
    if(nd > n)
    {
        return 0;
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++)
    {
        if (!vis[i])
        {
            vis[i] = true;
            ans = max(ans, (abs(nd - i) * a[nd]) + dfs(nd + 1, n, vis, a));
            vis[i] = false;
        }
    }
    return ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, l, r;
    cin >> n;
    vll a(n);
    fr(i, 0, n)
    {
        cin >> a[i];
    }
    vector<bool> vis(n,false);
    ll ans = dfs(0, n - 1, vis, a);
    cout << ans << "\n";
    return 0;
}