using System;
using System.Collections.Generic;

namespace abc163
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var aStrList = Console.ReadLine().Split(' ');
            var aList = new List<long>();
            var iList = new List<int>();
            var index = 0;
            foreach (var aStr in aStrList)
            {
                aList.Add(long.Parse(aStr));
                iList.Add(index);
                ++index;
            }
            Console.WriteLine(F(aList, iList));
        }
        static long F(List<long> aList, List<int> iList)
        {
            var max = 0L;
            var index = aList.Count - iList.Count;
            if (iList.Count == 2)
            {
                var l = aList[iList[0]] * Math.Abs(iList[0] - index) + aList[iList[1]] * Math.Abs(iList[1] - index - 1);
                var r = aList[iList[1]] * Math.Abs(iList[1] - index) + aList[iList[0]] * Math.Abs(iList[0] - index - 1);
                return Math.Max(l, r);
            }
            for (var i = 0; i < iList.Count; ++i)
            {
                var restList = iList.GetRange(0, i);
                if (i < iList.Count - 1)
                {
                    restList.AddRange(iList.GetRange(i + 1, iList.Count - i - 1));
                }
                var sub = aList[iList[i]] * Math.Abs(iList[i] - index);
                sub += F(aList, restList);
                if (max < sub)
                {
                    max = sub;
                }
            }
            return max;
        }
    }
}
