using System.Linq;
using static System.Math;
using System;

public class P
{
    public int act { get; set; }
    public int id { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var ps = new P[n];
        for (int i = 0; i < n; i++)
            ps[i] = new P { id = i, act = a[i] };
        ps = ps.OrderByDescending(x => x.act).ToArray();
        goDP(n, ps);
    }
    static void goDP(int n, P[] ps)
    {
        var dp = new long[n + 1, n + 1];
        for (int i = 0; i < n; i++)
            for (int j = 0; j <= i; j++)
            {
                var te = dp[i, j] + calcL(j, ps[i]);
                dp[i + 1, j + 1] = Max(dp[i + 1, j + 1], te);
                var te2 = dp[i, j] + calcR(n, i, j, ps[i]);
                dp[i + 1, j] = Max(dp[i + 1, j], te2);
            }
        var ans = 0L;
        for (int i = 1; i < n + 1; i++)
            ans = Max(ans, dp[n, i]);
        Console.WriteLine(ans);
    }
    static int calcL(int y, P p) => p.act * Abs(y - p.id);
    static int calcR(int n, int x, int y, P p) => p.act * Abs(n - (x - y) - 1 - p.id);
}

