using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testss
{
    class Program
    {
        static int n = 0;
       static int h = 0;
      static string raw;
     static int result = 0;

     /* int calculate(string gg)
      {

          int x;
          for (int l = 0; l <= n; l++)
          {
              x =int.Parse(gg.Split(',')[l]);
              if (x <= h)
              {
                  result = result + 1;
              }
              else
              {
                  result = result + 2;
              }
          }
          return (result);
      }*/
        static void Main(string[] args)
        {

            string fline = Console.ReadLine();
            string[] test = fline.Split(null);
            n =int.Parse(test[0]);
            h =int.Parse(test[1]);
            string secline = Console.ReadLine();
            string[] hop = secline.Split(null);

            for (int i = 0; i <= hop.Length-1; i++)
            {

                if (int.Parse(hop[i]) <= h)
                {
                    result = result + 1;
                }
                else
                {
                    result = result + 2;
                }
            }
            Console.WriteLine(result.ToString());
        }
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        Func<int[]> r = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] n = r(), a = r();
        Console.WriteLine(a.Count(x => x > n[1]) + n[0]);
    }
}


using System;
class Program
{
    static void Main()
    {
        Func<int> read = () =>
        {
            int digit;
            var num = string.Empty;
            while ((digit = Console.Read()) > 32)
                num += (char)digit;
            return int.Parse(num);
        };
        int n = read(), h = read(), ans = 0;
        Console.ReadLine();
        while (n-- > 0)
            ans += read() > h ? 2 : 1;
        Console.WriteLine(ans);
    }
}


using System;
class Program
{
    static void Main()
    {
        int read()
        {
            int digit;
            var num = string.Empty;
            while ((digit = Console.Read()) > 32)
                num += (char)digit;
            return int.Parse(num);
        }
        int n = read(), h = read(), ans = 0;
        Console.ReadLine();
        while (n-- > 0)
            ans += read() > h ? 2 : 1;
        Console.WriteLine(ans);
    }
}


using System;
using static System.Console;
class P
{
    static void Main(string[] args)
    {
        string[] a = ReadLine().Split();
        int c = Convert.ToInt32(a[0]);
        int d = Convert.ToInt32(a[1]);
        string[] b = ReadLine().Split();
        int sum = 0;
        for (int i = 0; i < b.Length; i++)
        {
            c = Convert.ToInt32(b[i]);
            if (c > d) sum += 2;
            else sum++;
        }
        WriteLine(sum);
    }
}


using System;

class Zada4ki
{
    static void Main()
    {
        int sum = 0;
        string[] FirstStr = Console.ReadLine().Split(' ');
        int n = Convert.ToInt32(FirstStr[0]);
        int h = Convert.ToInt32(FirstStr[1]);
        string[] SecondStr = Console.ReadLine().Split(' ');
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = Convert.ToInt32(SecondStr[i]);
            if (a[i] > h) sum += 2;
            else sum++;
        }
        Console.WriteLine(sum);

    }
}


using System;

namespace _37__A._Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] values = input.Split(' ');

            int n = int.Parse(values[0]);
            int h = int.Parse(values[1]);

            int[] newArray = new int[n];

            string anotherInput = Console.ReadLine();
            string[] anotherValues = anotherInput.Split(' ');

            for (int i = 0; i < n; i++)
            {
                newArray[i] = int.Parse(anotherValues[i]);
            }

            //foreach (var item in newArray)
            //{
            //    Console.WriteLine(item);
            //}

            int counter = 0;

            for (int i = 0; i < newArray.Length; i++)
            {
                if (newArray[i]<=h)
                {
                    counter++;
                }
                else if (newArray[i]>h)
                {
                    counter += 2;
                }
            }

            Console.WriteLine(counter);

        }
    }
}


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

namespace LearningAlgoCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var first = line.Split(" ")[0];
            var second = line.Split(" ")[1];
			var cnt = 0;
			var arr = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
			for(int i = 0; i < arr.Length - 1; i++;)
			{
				if(arr[i] > second)
				{
					cnt+=2;
				}
				else
				{
					cnt++;
				}
			}
			Console.WriteLine(cnt);
        }

        private static int LevenshteinDistance(string first, string second)
        {
            if (string.IsNullOrEmpty(first) && string.IsNullOrEmpty(second))
                return 0;
            if (string.IsNullOrEmpty(first))
                return second.Length;
            if (string.IsNullOrEmpty(second))
                return first.Length;

            int firstLength = first.Length;
            int secondLength = second.Length;
            var distances = new int[firstLength + 1, secondLength + 1];
            for (int i = 0; i <= firstLength; distances[i, 0] = i++) ;
            for (int j = 0; j <= secondLength; distances[0, j] = j++) ;

            for (int i = 1; i <= firstLength; i++)
            {
                for (int j = 1; j <= secondLength; j++)
                {
                    int cost = second[j - 1] == first[i - 1] ? 0 : 1;
                    distances[i, j] = Math.Min
                        (
                        Math.Min(distances[i - 1, j] + 1, distances[i, j - 1] + 1),
                        distances[i - 1, j - 1] + cost
                        );
                }
            }

            return distances[firstLength, secondLength];
        }
    }
}


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

namespace LearningAlgoCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var second = line.Split(" ")[1];
			var cnt = 0;
			var arr = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
			for(int i = 0; i < arr.Length; i++)
			{
				if(Convert.ToInt32(arr[i]) > Convert.ToInt32(second))
				{
					cnt+=2;
				}
				else
				{
					cnt++;
				}
			}
			Console.WriteLine(cnt);
            //Console.ReadLine();
        }

        private static int LevenshteinDistance(string first, string second)
        {
            if (string.IsNullOrEmpty(first) && string.IsNullOrEmpty(second))
                return 0;
            if (string.IsNullOrEmpty(first))
                return second.Length;
            if (string.IsNullOrEmpty(second))
                return first.Length;

            int firstLength = first.Length;
            int secondLength = second.Length;
            var distances = new int[firstLength + 1, secondLength + 1];
            for (int i = 0; i <= firstLength; distances[i, 0] = i++) ;
            for (int j = 0; j <= secondLength; distances[0, j] = j++) ;

            for (int i = 1; i <= firstLength; i++)
            {
                for (int j = 1; j <= secondLength; j++)
                {
                    int cost = second[j - 1] == first[i - 1] ? 0 : 1;
                    distances[i, j] = Math.Min
                        (
                        Math.Min(distances[i - 1, j] + 1, distances[i, j - 1] + 1),
                        distances[i - 1, j - 1] + cost
                        );
                }
            }

            return distances[firstLength, secondLength];
        }
    }
}


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

namespace LearningAlgoCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var second = line.Split(new char[] { ' ' })[1];
			var cnt = 0;
			var arr = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
			for(int i = 0; i < arr.Length; i++)
			{
				if(Convert.ToInt32(arr[i]) > Convert.ToInt32(second))
				{
					cnt+=2;
				}
				else
				{
					cnt++;
				}
			}
			Console.WriteLine(cnt);
            //Console.ReadLine();
        }

        private static int LevenshteinDistance(string first, string second)
        {
            if (string.IsNullOrEmpty(first) && string.IsNullOrEmpty(second))
                return 0;
            if (string.IsNullOrEmpty(first))
                return second.Length;
            if (string.IsNullOrEmpty(second))
                return first.Length;

            int firstLength = first.Length;
            int secondLength = second.Length;
            var distances = new int[firstLength + 1, secondLength + 1];
            for (int i = 0; i <= firstLength; distances[i, 0] = i++) ;
            for (int j = 0; j <= secondLength; distances[0, j] = j++) ;

            for (int i = 1; i <= firstLength; i++)
            {
                for (int j = 1; j <= secondLength; j++)
                {
                    int cost = second[j - 1] == first[i - 1] ? 0 : 1;
                    distances[i, j] = Math.Min
                        (
                        Math.Min(distances[i - 1, j] + 1, distances[i, j - 1] + 1),
                        distances[i - 1, j - 1] + cost
                        );
                }
            }

            return distances[firstLength, secondLength];
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _677A_Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {

            int height = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse)[1];
            int[] inputs = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int bend = inputs.Count(f => f > height);

            Console.WriteLine(inputs.Length + bend);

        }
    }
}


using System;
using System.Collections.Generic;

namespace Codeforce
{
    class Program
    {
        static void Main(string[] args)
        {

            string k = Console.ReadLine();
            string f = Console.ReadLine();
            int count = Convert.ToInt32(k[0]);
            int fenceHight = Convert.ToInt32(k[2]);
            List<int> L = new List<int>();
            int Count = 0;

            for (int i = 0; i < f.Length; i+=2)
            {
                L.Add(Convert.ToInt32(f[i]));

            }

            for (int i = 0; i < L.Count; i++)
            {
                if (L[i]>fenceHight)
                {
                    Count += 2;
                }
                else
                {
                    Count += 1;
                }
            }

            Console.WriteLine(Count);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Codeforce
{
    class Program
    {
        static void Main(string[] args)
        {

            string k = Console.ReadLine();
            string l = Console.ReadLine();

            List<int> first = new List<int>();
            List<int> second = new List<int>();

            int count = 0;

            string[] numbers1 = Regex.Split(k, @"\D+");
            string[] numbers2 = Regex.Split(l, @"\D+");
            foreach (string value in numbers1)
            {
                if (!string.IsNullOrEmpty(value))
                {
                    int i = int.Parse(value);
                    first.Add(i);
                }
            }

            foreach (string value in numbers2)
            {
                if (!string.IsNullOrEmpty(value))
                {
                    int i = int.Parse(value);
                    second.Add(i);
                }
            }

            for (int i = 0; i < second.Count; i++)
            {
                if (second[i]>first[1])
                {
                    count += 2;
                }
                else
                {
                    count += 1;
                }
            }

            Console.WriteLine(count);

        }
    }
}


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

namespace Codeforce
{
    class Program
    {
        static void Main(string[] args)
        {

            string k = Console.ReadLine();
            string l = Console.ReadLine();

            int fenceHigh = k[2] - '0';

            int Count=0;

            for (int i = 0; i < l.Length; i+=2)
            {
                if (l[i]-'0'>fenceHigh)
                {
                    Count += 2;
                }
                else
                {
                    Count += 1;
                }

            }

            Console.WriteLine(Count);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppForTrainning
{
    class Program
    {
        static void Main(string[] args)
        {
            Vanya_and_Fence();
        }
        static void Vanya_and_Fence()
        {
            string line1 = Console.ReadLine();
            string line2 = Console.ReadLine();
            var inputs = line1 + ' ' + line2;
            var tokens = inputs.Split();
            int[] numbers = Array.ConvertAll(tokens, int.Parse);
            int roadWidth = numbers[0];
            for(int i=2; i<numbers.Length; i++)
            {
                if (numbers[i] > numbers[1])
                    roadWidth++;
            }
            Console.WriteLine(roadWidth);
        }
    }
}


static void Vanya_and_Fence()
        {
            string line1 = Console.ReadLine();
            string line2 = Console.ReadLine();
            var inputs = line1 + ' ' + line2;
            var tokens = inputs.Split();
            int[] numbers = Array.ConvertAll(tokens, int.Parse);
            int roadWidth = numbers[0];
            for(int i=2; i<numbers.Length; i++)
            {
                if (numbers[i] > numbers[1])
                    roadWidth++;
            }
            Console.WriteLine(roadWidth);
        }


class Program
    {
        static void Main(string[] args)
        {
            Vanya_and_Fence();
        }
        static void Vanya_and_Fence()
        {
            string line1 = Console.ReadLine();
            string line2 = Console.ReadLine();
            var inputs = line1 + ' ' + line2;
            var tokens = inputs.Split();
            int[] numbers = Array.ConvertAll(tokens, int.Parse);
            int roadWidth = numbers[0];
            for(int i=2; i<numbers.Length; i++)
            {
                if (numbers[i] > numbers[1])
                    roadWidth++;
            }
            Console.WriteLine(roadWidth);
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForseProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputLine1 = Console.ReadLine().Split();
            string[] inputLine2 = Console.ReadLine().Split();

            int n = Int32.Parse(inputLine1[0]);
            int h = Int32.Parse(inputLine2[1]);

            int r = 0;
            for(int i = 0; i < n; i++)
            {
                if (Int32.Parse(inputLine2[i]) <= h)
                    r++;
                else
                    r += 2;
            }

            Console.WriteLine(r.ToString());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForseProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputLine1 = Console.ReadLine().Split();
            string[] inputLine2 = Console.ReadLine().Split();

            int n = Int32.Parse(inputLine1[0]);
            int h = Int32.Parse(inputLine1[1]);

            int r = 0;
            for(int i = 0; i < n; i++)
            {
                r += ((Int32.Parse(inputLine2[i]) - h) > 0) ? 2 : 1;
            }

            Console.WriteLine(r.ToString());
        }
    }
}


using System;
namespace SortApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            string[] s = str1.Split(' ');
            int cnt_friiend = Convert.ToInt32(s[0]);
            int high = Convert.ToInt32(s[1]);
            string str2 = Console.ReadLine();
            string[] t = str2.Split(' ');
            int[] arr = new int[t.Length];
            for(int i = 0; i < arr.Length; i++)
            {
                arr[i] = Convert.ToInt32(t[i]);
            }
            int width = 0;
            for(int i = 0; i < arr.Length; i++)
            {
                if (arr[i] > high)
                {
                    width += 2;
                }
                else
                {
                    width += 1;
                }
            }
            Console.WriteLine(width);
            Console.Read();

        }
    }
}


using System;

class Ahmed
{

    static void Main()
    {
        //input1 and 2
        string [] input1 = (Console.ReadLine()).Split(' ');
        string [] input2 = (Console.ReadLine()).Split(' ');

        int w = 0;

        foreach(string item in input2)
        {
            if( (int.Parse(item)) > (int.Parse(input1[1])) )
                w++;
            w++;
        }

        Console.WriteLine(w);
    }
}


using System;

class Ahmed
{
    static void Main()
    {

        int n, h, w = 0;
        //accept inputs
        n = Convert.ToInt32(Console.ReadLine());
        h = Convert.ToInt32(Console.ReadLine());
        //loop
        int i = 0;
        int a;
        while (i < n)
        {
            a = Convert.ToInt32(Console.ReadLine());
            if (a > h)
            {
                w++;
            }
            w++;
            i++;
        }

        Console.WriteLine($"{w}");
    }
}


using System;

class Ahmed{
    static void Main(){

        int n,h,w = 0;
        //accept inputs
        n = Convert.ToInt32(Console.ReadLine());
        h = Convert.ToInt32(Console.ReadLine());
        //loop
        int i = 0;
        while(i < n)
        {
            _ = Convert.ToInt32(Console.ReadLine());
            if(_ > h )
            {
                w++;
            }
            w++;
            i++;
        }

        Console.WriteLine($"{w}");
    }
}


using System;
using System.Text;

namespace Team
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] firstLine = Console.ReadLine().Split(' ');

            int n = int.Parse(firstLine[0]);
            int h = int.Parse(firstLine[1]);

            string[] secondLine = Console.ReadLine().Split(' ');

            int[] heights = new int[n];
            int result = 0;

            for(int i = 0; i <= n - 1; i++)
            {
                heights[i] = int.Parse(secondLine[i]);
                if(heights[i] <= h)
                {
                    result += 1;
                }
                else
                {
                    result += 2;
                }
            }

            Console.WriteLine(result);
        }
    }
}


using System;

namespace Lesson18_CSharo
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line1 = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(line1[0]);
            int h = Convert.ToInt32(line1[1]);
            string[] line2 = Console.ReadLine().Split(' ');
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                int ph = Convert.ToInt32(line2[i]);
                if(ph>h)
                {
                    count = count + 1;
                }
            }
            Console.WriteLine(n + count);
        }
    }
}


using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr1 = Console.ReadLine().Split(' ');
            string[] arr2 = Console.ReadLine().Split(' ');
            int n = int.Parse(arr1[0]);
            int h = int.Parse(arr1[1]);
            int width = 0;
            int[] heights = new int[n];
            for (int i = 0; i < n; i++)
            {
                heights[i] = int.Parse(arr2[i]);
            }
            for (int i = 0; i < n; i++)
            {
                if (heights[i] <= h)
                    width++;
                else
                    width += 2;
            }
            Console.WriteLine(width);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0, h = 0, res = 0;
            n = Convert.ToInt32(Console.ReadLine());
            h = Convert.ToInt32(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                int p = Convert.ToInt32(Console.ReadLine());
                if (p > h)
                {
                    res += 2;
                }
                else
                {
                    res++;
                }
            }

            Console.WriteLine(res);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0, h = 0, res = 0;
            n = Convert.ToInt32(Console.ReadLine());
            h = Convert.ToInt32(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                int p = Convert.ToInt32(Console.ReadLine());
                if (p > h)
                {
                    res += 2;
                }
                else
                {
                    res++;
                }
            }

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0, h = 0, res = 0;
            string[] ln1 = Console.ReadLine().Split();

            n = int.Parse(ln1[0]);
            h = int.Parse(ln1[1]);

            string[] ln2 = Console.ReadLine().Split();

            for (int i = 0; i < ln2.Length; i++)
            {
                int p = Convert.ToInt32(ln2[i]);
                if (p > h)
                {
                    res += 2;
                }
                else
                {
                    res++;
                }
            }

            Console.WriteLine(res);
        }
    }
}


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

namespace CSharpOlympTasks
{
    class Program
    {
        static void Main(string[] args)
        {
            int h = int.Parse(Console.ReadLine().Split(' ')[1]);

            int width = Console.ReadLine()
                        .Split(' ')
                        .Select(int.Parse)
                        .Sum(e => (e > h ? 2 : 1));

            Console.WriteLine(width);
        }
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nh = StringToIntArray(Console.ReadLine());
            int n = nh[0];
            int h = nh[1];
            int[] a = StringToIntArray(Console.ReadLine());
            int width = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] > h)
                    width += 2;
                else
                    width += 1;
            }
            Console.WriteLine(width);
        }

        static int[] StringToIntArray(string input)
        {
            string[] splitInput = input.Split();
            int length = splitInput.Length;
            int[] result = new int[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = int.Parse(splitInput[i]);
            }
            return result;
        }

        static long[] StringToLongArray(string input)
        {
            string[] splitInput = input.Split();
            int length = splitInput.Length;
            long[] result = new long[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = long.Parse(splitInput[i]);
            }
            return result;
        }
    }
}


using System;

namespace A.Vanya_and_Fence
{
	class Program
	{
		static void Main()
		{
			string[] tokens = Console.ReadLine().Split(' ');
			int a = int.Parse(tokens[0]);
			int b = int.Parse(tokens[1]);
			int sum = 0;
			int c;
			string[] secondLine = Console.ReadLine().Split(' ');
			for (int i = 0; i < a; i++)
			{
				c = int.Parse(secondLine[i]);

				if (c > b)
				{
					sum +=2;
				}
				else
				{
					sum++;
				}

			}
			Console.WriteLine(sum);
			Console.ReadKey();
		}
	}
}


using System;

namespace A.Vanya_and_Fence
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] tokens = Console.ReadLine().Split(' ');
			int a = int.Parse(tokens[0]);
			int b = int.Parse(tokens[1]);
			int sum=0;
			int c;
			string[] secondLine = Console.ReadLine().Split(' ');
			for (int i = 0; i < a; i++)
			{
				c = int.Parse(secondLine[i]);

				if (c > b)
				{
					sum += 2;
				}
				else
				{
					sum++;
				}

			}
			Console.WriteLine(sum);

		}
	}
}


using System;

namespace A.Vanya_and_Fence
{
	class Program
	{
		static void Main()
		{
			string[] tokens = Console.ReadLine().Split(' ');
			int a = int.Parse(tokens[0]);
			int b = int.Parse(tokens[1]);
			int sum=0;
			int c=0;
			string[] secondLine = Console.ReadLine().Split(' ');
			for (int i = 0; i < a; i++)
			{
				c = int.Parse(secondLine[i]);

				if (c > b)
				{
					sum += 2;
				}
				else
				{
					sum++;
				}

			}
			Console.WriteLine(sum);
			Console.ReadKey();
		}
	}
}


using System;

public class Test
{
	public static void Main()
	{
			int[] dizi = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			int[] arkadaslar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			int sayac = 0;
			for(int i = 0; i < dizi[0]; i++)
			{
				if (arkadaslar[i] > dizi[1]) sayac++;
			}
			int sonuc = (dizi[0] - sayac) +2*sayac;
			Console.WriteLine(sonuc);
	}
}


using System;

class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split();
        string[] pHeights = Console.ReadLine().Split();
        int people = int.Parse(input[0]);
        int fenceH = int.Parse(input[1]);
        int roadW = 0;

        foreach (var item in pHeights)
        {
            if (int.Parse(item) > fenceH) { roadW += 2; }
            else { roadW++; }
        }
        Console.WriteLine(roadW);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int Whi = int.Parse(Console.ReadLine());
            int[] Fhi = new int[n];
            int z = 0;
            for(int i=0;i<Fhi.Length;i++)
            {
                Fhi[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 0; i < Fhi.Length; i++)
            {
                if (Fhi[i] <= Whi)
                {
                    z += 1;
                }
                else
                {
                    z += 2;
                }

            }

            Console.WriteLine(z);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            string line_1 = Console.ReadLine();
            string[] s = line_1.Split(' ');
            string line_2 = Console.ReadLine();
            string[] Fhi = line_2.Split(' ');
            int Fnum = int.Parse(s[0]);
            int Whi = int.Parse(s[1]);
            int z = 0;

            for(int i=0;i<Fhi.Length;i++)
            {
                if(int.Parse(Fhi[i])<=Whi)
                { z+=1;}
                else{z+=2;}
            }
            Console.WriteLine(z);

        }
    }
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication8", "ConsoleApplication8\ConsoleApplication8.csproj", "{50E67FF1-8D36-4E28-8824-9A1F2314974A}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{50E67FF1-8D36-4E28-8824-9A1F2314974A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{50E67FF1-8D36-4E28-8824-9A1F2314974A}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{50E67FF1-8D36-4E28-8824-9A1F2314974A}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{50E67FF1-8D36-4E28-8824-9A1F2314974A}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{4E05DE2F-7142-4C7D-8C82-6C7A1C559E8B}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>A.Vanya_and_Fence</RootNamespace>
    <AssemblyName>A.Vanya_and_Fence</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A. Vanya and Fence", "A. Vanya and Fence\A. Vanya and Fence.csproj", "{4E05DE2F-7142-4C7D-8C82-6C7A1C559E8B}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{4E05DE2F-7142-4C7D-8C82-6C7A1C559E8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{4E05DE2F-7142-4C7D-8C82-6C7A1C559E8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{4E05DE2F-7142-4C7D-8C82-6C7A1C559E8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{4E05DE2F-7142-4C7D-8C82-6C7A1C559E8B}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


using System;

namespace problemA
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            int h,ph;
            int sum = 0;
            string[] arr=Console.ReadLine().Split(' ');
            n = int.Parse(arr[0]);
            h = int.Parse(arr[1]);

            string[] arr2 = Console.ReadLine().Split(' ');
            foreach (var item in arr2)
            {
                ph=int.Parse(item);
                if (ph > h)
                    sum += 2;
                else
                    sum += 1;
            }

            Console.WriteLine(sum);
        }
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        string[] array = Console.ReadLine().Split(' ');
        int n = int.Parse(array[0]);
        int h = int.Parse(array[1]);
        string[] height = Console.ReadLine().Split(' ');
        int width = height.Length;

        for (int i = 0; i < height.Length; i++)
        {
            if (int.Parse(height[i]) > h)
                width++;
        }
        Console.WriteLine(width);
    }
}


using System;

namespace _677A
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split();
            var friendsCount = int.Parse(input[0]);
            var fenceHeight = int.Parse(input[1]);

            var heightsString = Console.ReadLine().Split();
            var length = 0;
            for (var i = 0; i < friendsCount; i++)
                length += int.Parse(heightsString[i]) > fenceHeight ? 2 : 1;

            Console.WriteLine(length);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Code7.Tamrin
{
    class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();
            string[] line1 = input1.Split(' ');
            string[] line2 = input2.Split(' ');

            int n = int.Parse(line1[0]);
            int h = int.Parse(line1[1]);
            int sum =0;

            int[] hs = new int[n];
            for(int i = 0; i < n; i++)
            {
                hs[i] = Convert.ToInt32(line2[i]);
                if (hs[i] > h)
                    sum += 2;
                else
                    sum += 1;
            }
            Console.WriteLine(sum);

        }
    }
}


using System;
 class Program
    {
        static void Main()
        {
            string[] firstLineInput = Console.ReadLine()?.Split(' ');
            string[] secondLineInput = Console.ReadLine()?.Split(' ');
            int friendsNumber = int.Parse(firstLineInput[0]);
            double fenceHeight = double.Parse(firstLineInput[1]);

            int totalWidth=0;
            foreach (string friendHeight in secondLineInput)
            {
                if (double.Parse(friendHeight) <= fenceHeight) totalWidth++;
                else totalWidth += 2;
            }

            Console.WriteLine(totalWidth);

            Console.ReadKey();
        }
    }


 var firstLineInput = Console.ReadLine()?.Split(' ');
            var secondLineInput = Console.ReadLine()?.Split(' ');
            var friendsNumber = int.Parse(firstLineInput[0]);
            var fenceHeight = double.Parse(firstLineInput[1]);

            int totalWidth=0;
            foreach (var friendHeight in secondLineInput)
            {
                if (double.Parse(friendHeight) <= fenceHeight) totalWidth++;
                else totalWidth += 2;
            }

            Console.WriteLine(totalWidth);


using System;
 class Program
    {
        static void Main()
        {
            string[] firstLineInput = Console.ReadLine()?.Split(' ');
            string[] secondLineInput = Console.ReadLine()?.Split(' ');
            int friendsNumber = int.Parse(firstLineInput[0]);
            double fenceHeight = double.Parse(firstLineInput[1]);

            int totalWidth=0;
            foreach (string friendHeight in secondLineInput)
            {
                if (double.Parse(friendHeight) <= fenceHeight) totalWidth++;
                else totalWidth += 2;
            }

            Console.WriteLine(totalWidth);

        }
    }


 using System;
 class Program
    {
        static void Main(string[] args)
        {
            string[] firstLineInput = Console.ReadLine()?.Split(' ');
            string[] secondLineInput = Console.ReadLine()?.Split(' ');
            int friendsNumber = int.Parse(firstLineInput[0]);
            double fenceHeight = double.Parse(firstLineInput[1]);

            int totalWidth=0;
            foreach (string friendHeight in secondLineInput)
            {
                if (double.Parse(friendHeight) <= fenceHeight) totalWidth++;
                else totalWidth += 2;
            }

            Console.WriteLine(totalWidth);

            Console.ReadKey();
        }
    }


            string[] firstLineInput = Console.ReadLine()?.Split(' ');
            string[] secondLineInput = Console.ReadLine()?.Split(' ');
            int friendsNumber = int.Parse(firstLineInput[0]);
            double fenceHeight = double.Parse(firstLineInput[1]);

            int totalWidth=0;
            foreach (string friendHeight in secondLineInput)
            {
                if (double.Parse(friendHeight) <= fenceHeight) totalWidth++;
                else totalWidth += 2;
            }

            Console.WriteLine(totalWidth);


using System;

namespace soloLearnCsharpBasics
{
    class Program
    {

        static void Main(string[] args)
        {
            string firstLine = Console.ReadLine();
            String[] firstLinelist = firstLine.Split(' ');

            int fenceHight = int.Parse(firstLinelist[1]);
            int arraysize= int.Parse(firstLinelist[0]);

            string scondLine = Console.ReadLine();
            String[] scondLinelist = scondLine.Split(' ');

            int[] frindsHights=new int [arraysize];
            int count = 0;
            frindsHights= Array.ConvertAll(scondLinelist, int.Parse);

            for (int i=0;i<arraysize;i++)
            {
                if(frindsHights[i]< fenceHight||frindsHights[i]== fenceHight)
                {
                    count++;
                }
                else if(frindsHights[i] > fenceHight)
                {
                    count+=2;
                }

            }
            Console.WriteLine(count);

        }

    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001];
ll shl[200001];
ll shr[200001];
ll sum[200001];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=arr[i]*j;
    k+=sum[j-1]-sum[0];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+arr[i]*i;
        shl[i]= shl[i-1]+arr[i]*(i-1);
        shr[i]= shr[i-1]+arr[i]*(i+1);
//        cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e15;
    for(int i=1;i<=n;i++){
        int lo = i+1,hi = n;
        for(int j=0;j<100;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans,calc1(i,lo));
        lo = 1,hi = i-1;
        for(int j=0;j<100;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans , calc2(i,lo));
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001+100];
ll shl[200001+100];
ll shr[200001+100];
ll sum[200001+100];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1]-sum[0];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        //cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e15;
    for(int i=1;i<=n;i++){
        int lo = i+1,hi = n;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = (2*lo+hi)/3;
            int m2 = (2*hi+lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=n)ans = max(ans,calc1(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
        lo = 1,hi = i-1;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = (2*lo+hi)/3;
            int m2 = (2*hi+lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=i-1)ans = max(ans , calc2(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001+100];
ll shl[200001+100];
ll shr[200001+100];
ll sum[200001+100];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        //cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e17;
    for(int i=1;i<=n;i++){
        int lo = i,hi = n;
        for(int j=0;j<150&&hi>=lo;j++){
            int m1 = (2*lo+hi)/3;
            int m2 = (2*hi+lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans,calc1(i,lo));
        ans = max(ans,calc1(i,hi));
        //cout << ans << " " << i << " " << lo << "\n";
        lo = 1,hi = i;
        for(int j=0;j<150&&hi>=lo;j++){
            int m1 = (2*lo+hi)/3;
            int m2 = (2*hi+lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans , calc2(i,lo));
        ans = max(ans , calc2(i,hi));
        //cout << ans << " " << i << " " << lo << "\n";
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001+100];
ll shl[200001+100];
ll shr[200001+100];
ll sum[200001+100];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%I64d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        //cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e17;
    for(int i=1;i<=n;i++){
        int lo = i,hi = n;
        for(int j=0;j<120&&hi>=lo;j++){
            int m1 = lo+(hi-lo)/3;
            int m2 = hi-(hi-lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans,calc1(i,lo));
        ans = max(ans,calc1(i,hi));
        //cout << ans << " " << i << " " << lo << "\n";
        lo = 1,hi = i;
        for(int j=0;j<120&&hi>=lo;j++){
            int m1 = lo+(hi-lo)/3;
            int m2 = hi-(hi-lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans , calc2(i,lo));
        ans = max(ans , calc2(i,hi));
        //cout << ans << " " << i << " " << lo << "\n";
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001+100];
ll shl[200001+100];
ll shr[200001+100];
ll sum[200001+100];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1]-sum[0];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        //cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e15;
    for(int i=1;i<=n;i++){
        int lo = i+1,hi = n;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=n)ans = max(ans,calc1(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
        lo = 1,hi = i-1;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=i-1)ans = max(ans , calc2(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001];
ll shl[200001];
ll shr[200001];
ll sum[200001];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1]-sum[0];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        //cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e15;
    for(int i=1;i<=n;i++){
        int lo = i+1,hi = n;
        for(int j=0;j<100;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=n)ans = max(ans,calc1(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
        lo = 1,hi = i-1;
        for(int j=0;j<100;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=i-1)ans = max(ans , calc2(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001+100];
ll shl[200001+100];
ll shr[200001+100];
ll sum[200001+100];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        //cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e17;
    for(int i=1;i<=n;i++){
        int lo = i,hi = n;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = lo+(hi-lo)/3;
            int m2 = hi-(hi-lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans,calc1(i,lo));
        ans = max(ans,calc1(i,hi));
        //cout << ans << " " << i << " " << lo << "\n";
        lo = 1,hi = i;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = lo+(hi-lo)/3;
            int m2 = hi-(hi-lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans , calc2(i,lo));
        ans = max(ans , calc2(i,hi));
        //cout << ans << " " << i << " " << lo << "\n";
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001];
ll shl[200001];
ll shr[200001];
ll sum[200001];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1]-sum[0];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        //cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e15;
    for(int i=1;i<=n;i++){
        int lo = i+1,hi = n;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=n)ans = max(ans,calc1(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
        lo = 1,hi = i-1;
        for(int j=0;j<100&&hi>=lo;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        if(lo<=i-1)ans = max(ans , calc2(i,lo));
        //cout << ans << " " << i << " " << lo << "\n";
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
int arr[200001];
ll shl[200001];
ll shr[200001];
ll sum[200001];
int n;
ll calc1(int i,int j){
    ll k = sum[i-1];
    k+=shl[j]-shl[i];
    k+=1ll*arr[i]*j;
    k+=sum[n]-sum[j];
    return k;
}

ll calc2(int i,int j){
    ll k = sum[n]-sum[i];
    k+=shr[i-1]-shr[j-1];
    k+=1ll*arr[i]*j;
    k+=sum[j-1]-sum[0];
    return k;
}

int main(){
    int  m;
    cin >> n;
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        sum[i]= sum[i-1]+1ll*arr[i]*i;
        shl[i]= shl[i-1]+1ll*arr[i]*(i-1);
        shr[i]= shr[i-1]+1ll*arr[i]*(i+1);
        cout << shl[i] << " " << shr[i] << "\n";
    }
    ll ans = -1e15;
    for(int i=1;i<=n;i++){
        int lo = i+1,hi = n;
        for(int j=0;j<100;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc1(i,m1);
            ll zz = calc1(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans,calc1(i,lo));
        lo = 1,hi = i-1;
        for(int j=0;j<100;j++){
            int m1 = (hi+lo)/3;
            int m2 = 2*(hi+lo)/3;
            ll z = calc2(i,m1);
            ll zz = calc2(i,m2);
            if(z>zz)hi = m2;
            else lo = m1;
        }
        ans = max(ans , calc2(i,lo));
    }
    cout << ans;
    return 0;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , a[MAXN] , stack[MAXN] , top ;
ll sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2 - 1] - sum[j1 - 1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%d" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	stack[++top] = 1 ;
	for (int i = 1 ; i <= n + 1 ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) <= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top + 10 ;
		while (l + 1 < r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) > X (j1 , j2)) l = mid ;
			else r = mid ;
		}
		int j1 = stack[r - 1] , j2 = stack[r] ;
		int j = a[i] * Y (j1 , j2) > X (j1 , j2) ? stack[r] : stack[l] ;
		f[i] = a[i] * (j - i) - sum[j - 1] + sum[i - 1] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%I64d" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , a[MAXN] , stack[MAXN] , top ;
ll sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2 - 1] - sum[j1 - 1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%d" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	for (int i = 1 ; i <= n + 1 ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) <= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top , j = 1 ;
		while (l <= r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) >= X (j1 , j2)) l = mid + 1 , j = j2 ;
			else r = mid - 1 ;
		}
		f[i] = a[i] * (j - i) - sum[j - 1] + sum[i - 1] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%lld" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , a[MAXN] , stack[MAXN] , top ;
ll sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2 - 1] - sum[j1 - 1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%d" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	stack[++top] = 1 ;
	for (int i = 1 ; i <= n + 1 ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) <= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top + 5;
		while (l + 1 < r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) >= X (j1 , j2)) l = mid ;
			else r = mid ;
		}
		int j1 = stack[r - 1] , j2 = stack[r] ;
		int j = stack[l] ;
		f[i] = a[i] * (j - i) - sum[j - 1] + sum[i - 1] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%lld" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , a[MAXN] , stack[MAXN] , top ;
ll sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2 - 1] - sum[j1 - 1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%d" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	for (int i = 1 ; i <= n ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) <= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top ;
		while (l + 1 < r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) >= X (j1 , j2)) l = mid ;
			else r = mid ;
		}
		int j1 = stack[l] , j2 = stack[r] ;
		int j = a[i] * Y (j1 , j2) >= X (j1 , j2) ? stack[r] : stack[l] ;
		f[i] = a[i] * (j - i) - sum[j - 1] + sum[i - 1] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%lld" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , a[MAXN] , stack[MAXN] , top ;
ll sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2 - 1] - sum[j1 - 1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%d" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	for (int i = 1 ; i <= n ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) <= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top , j = 1 ;
		while (l <= r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) >= X (j1 , j2)) l = mid + 1 , j = j2 ;
			else r = mid - 1 ;
		}
		f[i] = a[i] * (j - i) - sum[j - 1] + sum[i - 1] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%lld" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , stack[MAXN] , top ;
ll a[MAXN] , sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2] - sum[j1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%lld" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	for (int i = 1 ; i <= n ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) >= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top , j = 0 ;
		while (l <= r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) >= X (j1 , j2)) l = mid + 1 , j = j2 ;
			else r = mid - 1 ;
		}
		f[i] = a[i] * (j - i) - sum[j] + sum[i] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%lld" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , a[MAXN] , stack[MAXN] , top ;
ll sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2 - 1] - sum[j1 - 1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%d" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	stack[++top] = 1 ;
	for (int i = 1 ; i <= n + 1 ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) <= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top + 1 ;
		while (l + 1 < r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) > X (j1 , j2)) l = mid ;
			else r = mid ;
		}
		int j1 = stack[r - 1] , j2 = stack[r] ;
		int j = a[i] * Y (j1 , j2) > X (j1 , j2) ? stack[r] : stack[l] ;
		f[i] = a[i] * (j - i) - sum[j - 1] + sum[i - 1] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%lld" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , a[MAXN] , stack[MAXN] , top ;
ll sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2 - 1] - sum[j1 - 1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%d" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	stack[++top] = 1 ;
	for (int i = 1 ; i <= n + 1 ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) <= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top + 1 ;
		while (l + 1 < r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) > X (j1 , j2)) l = mid ;
			else r = mid ;
		}
		int j1 = stack[r - 1] , j2 = stack[r] ;
		int j = a[i] * Y (j1 , j2) > X (j1 , j2) ? stack[r] : stack[l] ;
		f[i] = a[i] * (j - i) - sum[j - 1] + sum[i - 1] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%I64d" , ans + tmp) ;
	return 0 ;
}


#include <cstdio>
using namespace std ;
const int MAXN = 2e5 + 10 ;
typedef long long ll ;
int n , stack[MAXN] , top ;
ll a[MAXN] , sum[MAXN] , tmp , ans , f[MAXN] ;
ll X (int j1 , int j2) {return sum[j2] - sum[j1] ;}
ll Y (int j1 , int j2) {return j2 - j1 ;}
int main () {
	scanf ("%d" , &n) ;
	for (int i = 1 ; i <= n ; i++)
		scanf ("%lld" , &a[i]) , sum[i] = sum[i - 1] + a[i] , tmp += 1LL * a[i] * i ;
	for (int i = 1 ; i <= n ; i++) {
		while (top && X (stack[top - 1] , stack[top]) * Y (stack[top] , i) >= Y (stack[top - 1] , stack[top]) * X (stack[top] , i)) top-- ;
		stack[++top] = i ;
	}
	for (int i = 1 ; i <= n ; i++) {
		int l = 1 , r = top , j = 1 ;
		while (l <= r) {
			int mid = l + r >> 1 ;
			int j1 = stack[mid - 1] , j2 = stack[mid] ;
			if (a[i] * Y (j1 , j2) >= X (j1 , j2)) l = mid + 1 , j = j2 ;
			else r = mid - 1 ;
		}
		f[i] = a[i] * (j - i) - sum[j] + sum[i] ;
		if (f[i] > ans) ans = f[i] ;
	}
	printf ("%lld" , ans + tmp) ;
	return 0 ;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 1], lines[sz - 2], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        ll ret = -LLINF;
        for (int i = r; i <= r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(-r, -s[r]);
        ll delta = CH.get(-a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 2], lines[sz - 1], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        while(r - l > 1) {
            int mid = (l + r) / 2;
            if (lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        l = max(l - 3, 0);
        r = min(sz, r + 3);
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(r, -s[r]);
        ll delta = CH.get(a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 1], lines[sz - 2], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        l = max(l - 3, 0);
        r = min(sz, r + 3);
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(r, -s[r]);
        ll delta = CH.get(a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (b.k - c.k) <= (c.b - b.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 2], lines[sz - 1], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        l = max(l - 3, 0);
        r = min(sz, r + 3);
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(r, -s[r]);
        ll delta = CH.get(a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 1], lines[sz - 2], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        l = max(l - 3, 0);
        r = min(sz, r + 3);
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(r, -s[r]);
        ll delta = CH.get(a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(-l, -s[l - 1]);
        ll delta = CH.get(-a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 2], lines[sz - 1], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        l = max(l - 3, 0);
        r = min(sz, r + 3);
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(r, -s[r]);
        ll delta = CH.get(a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (b.k - c.k) >= (c.b - b.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 2], lines[sz - 1], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        l = max(l - 3, 0);
        r = min(sz, r + 3);
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(r, -s[r]);
        ll delta = CH.get(a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;
typedef long long Long;

struct Line {
    Long a, b, get(Long x) { return a * x + b; }
};

struct ConvexHull {
    int size;
    Line *hull;

    ConvexHull(int maxSize) {
        hull = new Line[++maxSize], size = 0;
    }

    bool is_bad(Long curr, Long prev, Long next) {
        Line c = hull[curr], p = hull[prev], n = hull[next];
        return (c.b - n.b) * (c.a - p.a) <= (p.b - c.b) * (n.a - c.a);
    }

    void add_line(Long a, Long b) {
        hull[size++] = (Line){a, b};
        while (size > 2 && is_bad(size - 2, size - 3, size - 1))
            hull[size - 2] = hull[size - 1], size--;
    }

    Long get(Long x) {
        int l = -1, r = size - 1;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (hull[m].get(x) <= hull[m + 1].get(x))
                l = m;
            else
                r = m;
        }
        return hull[r].get(x);
    }
};

ConvexHull CH(maxN);
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = ConvexHull(maxN);
    for(int r = n; r >= 1; --r) {
        CH.add_line(r, -s[r]);
        ll delta = CH.get(a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = ConvexHull(maxN);
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 1], lines[sz - 2], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(-r, -s[r]);
        ll delta = CH.get(-a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

template <typename T>
struct convex_hull  {
    struct line {
        T k, b;
        line() {}
        line(T k, T b): k(k), b(b) {}
        T get(T x) const {
            return k * x + b;
        }
    };

    convex_hull(): sz(0) {}
    convex_hull(int n) {
        hull = new line[n + 10];
        sz = 0;
    }

    int sz;
    line *hull;

    bool bad(const line &x, const line &y, const line &z) {
        return (y.b - x.b) * (x.k - z.k) <= (z.b - x.b) * (x.k - y.k);
    }

    void add_line(T k, T b) {
        line L = line(k, b);
        while(sz >= 2 && bad(hull[sz - 1], hull[sz - 2], L)) {
            sz--;
        }
        hull[sz++] = L;
    }

    T get(T x) {
        assert(sz > 0);
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int m = (l + r) / 2;
            if (hull[m].get(x) > hull[m + 1].get(x)) {
                r = m;
            } else {
                l = m;
            }
        }
        return hull[r].get(x);
    }
};

convex_hull<ll> CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull<ll>(n);
    for(int r = n; r >= 1; --r) {
        CH.add_line(-r, -s[r]);
        ll delta = CH.get(-a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull<ll>(n);
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 1], lines[sz - 2], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        l = max(l - 3, 0);
        r = min(sz, r + 3);
        ll ret = -LLINF;
        for (int i = l; i < r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(-r, -s[r]);
        ll delta = CH.get(-a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdlib>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <cassert>
#include <bitset>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;

template <typename T>
T nextInt() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int maxN = (int)3e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 5;
const ll LLINF = (ll)1e18 + 5;

struct convex_hull {

    convex_hull() {
        lines.clear();
        sz = 0;
    }

    struct line {
        ll k;
        ll b;
        line() {}
        line(ll k, ll b): k(k), b(b) {}
        ll get(ll x) {
            return k * x + b;
        }
    };

    bool bad(line a, line b, line c) {
        return (b.b - a.b) * (a.k - c.k) <= (c.b - a.b) * (a.k - b.k);
    }

    vector <line> lines;
    int sz;

    void add_line(ll k, ll b) {
        line L = line(k, b);
        while(sz >= 2 && bad(lines[sz - 1], lines[sz - 2], L)) {
            lines.pop_back();
            sz--;
        }
        sz++;
        lines.push_back(L);
    }

    ll get(ll x) {
        if (sz == 0) return -LLINF;
        int l = 0, r = sz - 1;
        for (int iter = 0; iter < 20; ++iter) {
            int mid = (l + r) / 2;
            if (mid + 1 < sz && lines[mid].get(x) > lines[mid + 1].get(x)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        ll ret = -LLINF;
        for (int i = l; i <= r; ++i) {
            ret = max(ret, lines[i].get(x));
        }
        return ret;
    }
};

convex_hull CH;
ll a[maxN];
ll s[maxN];
int n;

int main() {

   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    n = nextInt<int>();
    ll result = 0LL;
    for (int i = 1; i <= n; ++i) {
        a[i] = nextInt<int>();
        s[i] = s[i - 1] + a[i];
        result += a[i] * i;
    }

    ll answer = -LLINF;
    CH = convex_hull();
    for(int r = n; r >= 1; --r) {
        CH.add_line(-r, -s[r]);
        ll delta = CH.get(-a[r]) - a[r] * r + s[r];
        answer = max(answer, result + delta);
    }

    CH = convex_hull();
    for(int l = 1; l <= n; ++l) {
        CH.add_line(l, -s[l - 1]);
        ll delta = CH.get(a[l]) + s[l - 1] - a[l] * l;
        answer = max(answer, result + delta);
    }

    printf("%I64d\n", answer);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define inf 99999999999999999
#define maxn 200010
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int a[maxn];
ll sum[maxn];
struct P{
    double x,y;
}s[maxn];
int top;
int id[maxn];
ll ans=-inf,now;
double slope(P a,P b)
{
    return (a.y-b.y)/(a.x-b.x);
}
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  a[i]=read();
    for(int i=1;i<=n;i++)  sum[i]=sum[i-1]+a[i];
    for(int i=1;i<=n;i++)  now+=1ll*i*a[i];
    s[++top]=(P){1,0};
    s[0]=(P){0,(double)inf};
    id[1]=1;
    for(int i=2;i<=n;i++)
    {
        int l=1,r=top;
        int pos;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(slope(s[mid],s[mid-1])<a[i])
            {
                pos=id[mid];
                l=mid+1;
            }
            else r=mid-1;
        }
        ans=max(ans,now+1ll*(pos-i)*a[i]+sum[i-1]-sum[pos-1]);
        P tmp=(P){i,sum[i-1]};
        while(top>1&&slope(tmp,s[top-1])<slope(s[top-1],s[top]))  top--;
        s[++top]=tmp;
        id[top]=i;
    }
    top=0;
    s[0]=(P){n+1,-(double)inf};
    s[++top]=(P){n,sum[n]};
    id[1]=n;
    for(int i=n-1;i>=1;i--)
    {
        int l=1,r=top;
        int pos;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(slope(s[mid],s[mid-1])<-a[i])
            {
                pos=id[mid];
                l=mid+1;
            }
            else r=mid-1;
        }
        ans=max(ans,now+1ll*(pos-i)*a[i]+sum[i]-sum[pos]);
        P tmp=(P){i,sum[i]};
        while(top>1&&slope(tmp,s[top-1])<slope(s[top-1],s[top]))  top--;
        s[++top]=tmp;
        id[top]=i;
    }
    cout<<ans<<endl;
    return 0;
}