using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.E
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static long N { get; private set; }
        public static List<long> A { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            N = CR.GetLong();
            A = CR.GetLongs();

            var table = new List<Score>();
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    table.Add(new Score
                    {
                        Value = A[i] * Math.Abs(i - j),
                        X = i,
                        Y = j,
                    });
                }
            }

            table = table.OrderByDescending(x => x.Value).ToList();
            var sum = 0L;
            for (int i = 0; i < N; i++)
            {
                var max = table.First();
                sum += max.Value;
                table.RemoveAll(x => x.X == max.X || x.Y == max.Y);
            }

            return sum;
        }

        class Score
        {
            public long Value { get; set; }
            public long X { get; set; }
            public long Y { get; set; }
        }
    }
}
