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

namespace uni
{
    class Program
    {
        public bool equal(int in1,int in2)
        {
            if (in1==in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool greater(int in1, int in2)
        {
            if (in1 > in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool smaller(int in1, int in2)
        {
            if (in1 < in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        static void Main(string[] args)
        {
            Program n = new Program();
            int x;
           x=Convert.ToInt32(Console.ReadLine());
            List<int> nums=new List<int>();
            List<string> st = new List<string> ();
            string y = Console.ReadLine();
            string[] temp = y.Split();
            for (int i=0;i<x;i++)
            {
                nums.Add(Convert.ToInt32(temp[i]));
            }
            for (int i=0;i<x-1;i++)
            {
                bool temp1 =n.equal(nums[i],nums[i+1]);
                bool temp2 =n.greater(nums[i], nums[i+1]);
                bool temp3 =n.smaller(nums[i], nums[i+1]);
                if (temp1==true)
                {
                    st.Add("Equal");
                }
               else if (temp2 == true)
                {
                    st.Add("decreasing");
                }
               else if (temp3 == true)
                {
                    st.Add("increasing");
                }
            }
            bool t = false;
            for (int i=0;i<st.Count()-1;i++)
            {
                if (st[i+1]== "increasing"&& st[i] == "decreasing")
                {
                    Console.WriteLine("NO");
                    t = true;
                    break;
                }
                if (st[i+1] == "Equal" && st[i] == "decreasing")
                {
                    Console.WriteLine("NO");
                    t = true;
                    break;
                }
                if (st[i+1] == "increasing" && st[i] == "Equal")
                {
                    Console.WriteLine("NO");
                    t = true;
                    break;
                }
            }
            if (t==false)
            {
                Console.WriteLine("YES");
            }
        }
     }
}

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

namespace Contest1UnimodalArrayA00817810
{
    class Program
    {
        static void Main(string[] args)
        {
            string stringInput  = Console.ReadLine();
            int arrayLength = int.Parse(stringInput);

            stringInput = Console.ReadLine();
            string[] inputs = stringInput.Split(' ');
            int[] array = new int[arrayLength];
            for (int i = 0; i < arrayLength; i++)
            {

                array[i] = int.Parse(inputs[i]);
            }

            bool isFirstBlock = true;
            bool isMediumBlock = false;
            bool isLastBlock = false;
            bool isUnimodal = true;
            int lastNumber = array[0];

            for (int i=1; i< arrayLength; i++)
            {
                if (isFirstBlock)
                {
                    if(array[i] < lastNumber)
                    {
                        isFirstBlock = false;
                        isLastBlock = true;
                    }
                    else if(array[i] == lastNumber)
                    {
                        isFirstBlock = false;
                        isMediumBlock = true;
                    }
                }else if (isMediumBlock)
                {
                    if (array[i] > lastNumber)
                    {
                        Console.WriteLine("NO");
                        isUnimodal = false;
                        break;
                    }
                    else if (array[i] < lastNumber)
                    {
                        isMediumBlock = false;
                        isLastBlock = true;
                    }
                }
                else if(isLastBlock)
                {
                    if (array[i] > lastNumber || array[i] == lastNumber)
                    {
                        Console.WriteLine("NO");
                        isUnimodal = false;
                        break;
                    }
                }
                lastNumber = array[i];
            }
            if (isUnimodal)
            {
                Console.WriteLine("YES");
            }
        }
    }
}

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

namespace Contest1UnimodalArrayA00817810
{
    class Program
    {
        static void Main(string[] args)
        {
            string stringInput = Console.ReadLine();
            int arrayLength = int.Parse(stringInput);

            stringInput = Console.ReadLine();
            string[] inputs = stringInput.Split(' ');
            int[] array = new int[arrayLength];
            for (int i = 0; i < arrayLength; i++)
            {

                array[i] = int.Parse(inputs[i]);
            }

            bool isFirstBlock = true;
            bool isMediumBlock = false;
            bool isLastBlock = false;
            bool isUnimodal = true;
            int lastNumber = array[0];

            for (int i = 1; i < arrayLength; i++)
            {
                if (isFirstBlock)
                {
                    if (array[i] < lastNumber)
                    {
                        isFirstBlock = false;
                        isLastBlock = true;
                    }
                    else if (array[i] == lastNumber)
                    {
                        isFirstBlock = false;
                        isMediumBlock = true;
                    }
                }
                else if (isMediumBlock)
                {
                    if (array[i] > lastNumber)
                    {
                        Console.WriteLine("NO");
                        isUnimodal = false;
                        break;
                    }
                    else if (array[i] < lastNumber)
                    {
                        isMediumBlock = false;
                        isLastBlock = true;
                    }
                }
                else if (isLastBlock)
                {
                    if (array[i] > lastNumber || array[i] == lastNumber)
                    {
                        Console.WriteLine("NO");
                        isUnimodal = false;
                        break;
                    }
                }
                lastNumber = array[i];
            }
            if (isUnimodal)
            {
                Console.WriteLine("YES");
            }
        }
    }
}

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

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

            string str = Console.ReadLine();
            long n = Convert.ToInt64(str);
            string str2 = Console.ReadLine();
            string[] sttr = str2.Split(' ');
            List<long> a = new List<long>();
            foreach (var item in sttr)
            {
                a.Add(Convert.ToInt64(item));
            }

        int i = 0;
        while (i < n - 1 && a[i] < a[i + 1]) i++;
        while (i < n - 1 && a[i] == a[i + 1]) i++;
        while (i < n - 1 && a[i] > a[i + 1]) i++;
            if (i == n - 1) { Console.WriteLine("YES"); }
            else { Console.WriteLine("NO"); }

        }
    }
}

using System;
using System.IO;

namespace archivess1488
{
    class MainClass
    {
        public static void Main()
        {
            int n =  int.Parse(Console.ReadLine());
            string nubms = Console.ReadLine();
            string[] num;
            int[] numbers = new int[n];
            num = nubms.Split(' ');
            for (int i = 0; i < n; i++)
                numbers[i] = int.Parse(num[i]);
            bool down = false, constant = false, up = false;
            if (n < 3) constant = true;
            else
            {
				if (numbers[0] < numbers[1]) up = true;
				else up = false;
                for (int i = 1; i < numbers.Length; i++)
                {
                    if (!constant)
                    {
                        if (numbers[i] > numbers[i-1] && up && i==numbers.Length-1) constant = true;
                        if (numbers[i] > numbers[i - 1] && !up) break;
                        if (numbers[i] == numbers[i - 1]) constant = true;
                        if (numbers[i] < numbers[i - 1]) { constant = true; down = true; }
                    }
                    else if (constant && !down)
                    {
                        if (numbers[i] > numbers[i - 1]) { constant = false; break;  }
                        if (numbers[i] < numbers[i - 1] && !down) down = true;
                    }
                    else if (constant && down)
                    {
                        if (numbers[i] > numbers[i - 1]) { constant = false; break;  }
                        if (numbers[i] == numbers[i - 1]) { constant = false; break;  }
                    }
                }
            }
            if (constant == false) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}

using System;

namespace OlympicAAAAA
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            byte q = 0;
            int curr = 0;
            for(int i = 0; i < n; i++)
            {
                switch(q)
                {
                    case 0:
                        if (int.Parse(s[i]) < curr) q = 2;
                        else if (int.Parse(s[i]) == curr) q = 1;
                        break;
                    case 1:
                        if (int.Parse(s[i]) > curr)
                        {
                            Console.WriteLine("NO");
                            return;
                        }
                        else if (int.Parse(s[i]) < curr) q = 2;
                        break;
                    case 2:
                        if(int.Parse(s[i]) >= curr)
                        {
                            Console.WriteLine("NO");
                            return;
                        }
                        break;
                }
                curr = int.Parse(s[i]);
            }
            Console.WriteLine("YES");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
            //using (var sr = new InputReader(new StreamReader("input.txt")))
            {
                var task = new Task();
                using (var sw = Console.Out)
                {
                    //using (var sw = new StreamWriter("output.txt")) {
                    task.Solve(sr, sw);
                    //Console.ReadKey();
                }
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var array = sr.ReadArrayOfInt32();
            if (n == 1) {
                sw.WriteLine("YES");
                return;
            }
            for (var i = 0; i < array.Length; i++) {
                for (var j = i; j < array.Length; j++) {
                    var can = true;
                    for (var k = 1; k <= i; k++) {
                        if (array[k] <= array[k - 1]) {
                            can = false;
                            break;
                        }
                    }
                    for (var k = i; k <= j; k++) {
                        if (array[k] != array[i]) {
                            can = false;
                            break;
                        }
                    }
                    for (var k = j + 1; k < array.Length; k++) {
                        if (array[k] >= array[k - 1]) {
                            can = false;
                            break;
                        }
                    }
                    if (can) {
                        sw.WriteLine("YES");
                        return;
                    }
                }
            }

            sw.WriteLine("NO");
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] linea = Console.ReadLine().Split();
            bool bajando = false;
            bool constante = false;
            int cons = -1;
            bool res = true;
            for (int i = 0; i < linea.Length - 1; i++)
            {
                int a = int.Parse(linea[i].ToString());
                int b = int.Parse(linea[i + 1].ToString());

                if (!bajando)
                {
                    if (a == b)
                    {
                        constante = true;
                        bajando = true;
                        cons = a;
                    }
                    if (b < a)
                    {
                        bajando = true;
                    }
                }
                if (bajando)
                {
                    if (constante)
                    {
                        if (b != cons)
                        {
                            constante = false;
                            if (b >= a)
                            {
                                res = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (b >= a)
                        {
                            res = false;
                            break;
                        }
                    }

                }
            }
            if (res)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

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

namespace FORexam
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] arr = new int[n];
            for (int k = 0; k < n; k++)
            {
                arr[k] = Convert.ToInt32(input[k]);
            }
            int i = 1;
            while (i < n && arr[i - 1] < arr[i] && i < n)
            {
                i++;
            }
            while(i < n && arr[i-1] == arr[i] && i < n)
            {
                i++;
            }

            while (i < n && arr[i - 1] > arr[i])
            {
                i++;
            }
            if (i - 1 == n - 1)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }
    }
}

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

namespace LearningCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.ReadKey();
            int n; string result = "";
            int a = 0, b = 0, c = 0;
            n = int.Parse(Console.ReadLine());

            var inputIntArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (n == 1) { result = "YES"; Console.WriteLine(result); return; }

            for (int i = 0; i < n - 1; i++)
            {

                if (inputIntArray[i] < inputIntArray[i + 1])
                {
                    if (b == 0 && c == 0) { a++; }
                    else { Console.WriteLine("NO"); return; }
                }
                else if (inputIntArray[i] == inputIntArray[i + 1])
                {
                    if (c == 0) { b++; }
                    else { Console.WriteLine("NO"); return; }
                }
                else { c++; }

            }
            Console.WriteLine("YES");

          //  Console.ReadKey();

        }
    }
}

using System;
using System.Linq;

namespace Problem831A
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var a = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();

            Console.WriteLine(Check(a) ? "YES" : "NO");
        }

        static bool Check(int[] a)
        {
            int le = -1;
            int l = a.Length;
            int i = 0;
            if (l == 1)
                return true;

            while (i < l && a[i] > le)
            {
                le = a[i];
                i++;
            }
            if (i == l && a[l - 1] > a[l - 2])
                return true;

            if (a[i] == le)
            {
                while (i < l && a[i] == le)
                {
                    le = a[i];
                    i++;
                }

                if (i == l && a[l - 1] == a[l - 2])
                    return true;
            }
            le = a[i - 1];
            while (i < l && a[i] < le)
            {
                le = a[i];
                i++;
            }

            if (i != l)
                return false;

            return true;
        }
    }
}

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

namespace A_UnimodalArray
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.ReadLine();
			var numbers = Console.ReadLine().Split().Select(Int32.Parse).ToArray();
			int i = 0;
			while (i < numbers.Length - 1 && numbers[i + 1] > numbers[i])
			{
				i++;
			}
			while (i < numbers.Length - 1 && numbers[i + 1] == numbers[i])
			{
				i++;
			}
			while (i < numbers.Length - 1 && numbers[i + 1] < numbers[i])
			{
				i++;
			}
			Console.WriteLine(i == numbers.Length - 1 ? "YES" : "NO");
		}
	}
}

using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string firstLine = Console.ReadLine();
            string secondLine = Console.ReadLine();

            int firstArray = int.Parse(firstLine);
            string[] secondArray = secondLine.Split(' ');

            int[] values = Array.ConvertAll(secondArray, int.Parse);

            int constStart = 0;
            int constEnd = values.Length - 1;

            int index = 0;
            while (index + 2 < values.Length && values[index] < values[index + 1])
            {
                index++;
            }
            //index++;
            constStart = index;

            index = constEnd;

            while (index > 0 && values[index] < values[index - 1])
            {
                index--;
            }
            //index--;
            constEnd = index;

            bool isModal = true;

            for (int i = constStart; i < constEnd; i++)
            {
                if (constEnd - constStart == 1)
                    break;
                if (values[i] != values[i + 1])
                {
                    isModal = false;
                    break;
                }

            }

            if (isModal)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

    }
}

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace Round424A
{
    class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
            {
                // using (var sr = new InputReader(new StreamReader("input.txt"))) {
                var task = new Task();
                using (var sw = Console.Out)
                {
                    //using (var sw = new StreamWriter("output.txt")){

                    task.Solve(sr, sw);
                    //Console.ReadKey();

                }
            }
        }
    }
    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            int n = sr.NextInt32();
            int[] arr = sr.ReadArrayOfInt32();
            int segment = 0;
            for(int i=0; i<arr.Length-1; i++)
            {

                if (arr[i] == arr[i + 1] )
                {
                    if (segment <= 1)
                    {
                        segment = 1;
                    }
                    else { sw.WriteLine("NO"); return; }
                }

                if (arr[i+1] < arr[i] )
                {
                    if (segment <= 2)
                    {
                        segment = 2;
                    }
                    else { sw.WriteLine("NO"); return; }
                }

                if (arr[i+1] < arr[i] && segment==0)
                { sw.WriteLine("NO");return; }
                if (arr[i+1] > arr[i] && (segment == 1|| segment == 2))
                { sw.WriteLine("NO"); return; }

            }
            sw.WriteLine("YES");

        }
    }
    internal class InputReader : IDisposable
    {
        private bool isDispose;
        private readonly TextReader sr;

        public InputReader(TextReader stream)
        {
            sr = stream;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        public string NextString()
        {
            var result = sr.ReadLine();
            return result;
        }

        public int NextInt32()
        {
            return Int32.Parse(NextString());
        }

        public long NextInt64()
        {
            return Int64.Parse(NextString());
        }

        public string[] NextSplitStrings()
        {
            return NextString()
                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
        {
            return NextSplitStrings()
                    .Select(s => func(s, CultureInfo.InvariantCulture))
                    .ToArray();
        }

        public int[] ReadArrayOfInt32()
        {
            return ReadArray(Int32.Parse);
        }

        public long[] ReadArrayOfInt64()
        {
            return ReadArray(Int64.Parse);
        }

        public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
        {
            return
                    str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(s => func(s, CultureInfo.InvariantCulture))
                            .ToArray();
        }

        protected void Dispose(bool dispose)
        {
            if (!isDispose)
            {
                if (dispose)
                    sr.Close();
                isDispose = true;
            }
        }

        ~InputReader()
        {
            Dispose(false);
        }
    }
}

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

namespace ConsoleApplication1A
{
  class ProgramAAA
  {

    static void Main()
    {

     int n = Convert.ToInt32(Console.ReadLine());
     string[] tk = Console.ReadLine().Split(' ');
      int[] M = new int[n];
      for (var i = 0; i < n; i++)
        M[i] = Convert.ToInt32(tk[i]);

      string res = "NO";
     for (var i = 0; i < n; i++)
     {
       for (var j = i; j < n; j++)
       {
         string tmp = "YES";

         for (var k = i; k <=j; k++)
           if (M[i]!=M[k]) tmp = "NO";

         for (var k = 1; k <=i-1; k++)
           if (M[k-1]>=M[k]) tmp = "NO";
         if (i-1>=0) if (M[i-1] >= M[i]) tmp = "NO";

         for (var k = j+1; k < n; k++)
           if (M[k-1] <= M[k]) tmp = "NO";
         if (j+1<n) if (M[j+1] >= M[j]) tmp = "NO";

         if (tmp == "YES") res = "YES";
       }
     }

      Console.WriteLine(res);

    }
  }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace TestApplication2
{
    class Program
    {
        private static ComparingResults GetCompRes(int number1, int number2)
        {
            if (number1 < number2)
            {
                return ComparingResults.Greater;
            }
            if (number1 == number2)
            {
                return ComparingResults.Equal;
            }
            else
            {
                return ComparingResults.Lesser;
            }
        }

        enum ComparingResults { Greater, Equal, Lesser };
        static void Main(string[] args)
        {
            int arraySize = int.Parse(Console.ReadLine());
            int[] array = new int[arraySize];
            string initializaString = Console.ReadLine();

            string[] numbers = initializaString.Split(' ');

            for (int i = 0; i < arraySize; i++)
            {
                array[i] = int.Parse(numbers[i]);
            }

            if (arraySize == 1)
            {
                Console.WriteLine("YES");
                return;
            }

            ComparingResults prev = GetCompRes(array[0], array[1]);
            ComparingResults next = prev;

            for (int i = 1; i < arraySize - 1; i++)
            {
                next = GetCompRes(array[i], array[i + 1]);
                if (
                    (prev == ComparingResults.Equal && next == ComparingResults.Greater) ||
                    prev == ComparingResults.Lesser && (next == ComparingResults.Greater || next == ComparingResults.Equal))
                {
                    Console.WriteLine("NO");
                    return;
                }
                prev = next;
            }

            Console.WriteLine("YES");
            return;
        }
    }
}

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

namespace ConsoleApplication1.CodeForces
{
    class _4032
    {
        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        class Node : IComparable
        {
            public long X { get; set; }
            public long Y { get; set; }
            public int CompareTo(object obj)
            {
                if (this.Y > ((Node)obj).Y)
                {
                    return 1;
                }
                if (this.Y == ((Node)obj).Y)
                {
                    return 0;
                }
                return -1;
            }
        }
        public static string ReverseString(string s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
        }
        static void Main(String[] args)
        {
            var n = int.Parse(Console.ReadLine().TrimEnd());
            var step = 0;
            var data = Console.ReadLine().TrimEnd().Split(' ').Select(int.Parse).ToList();
            for (var i = 1; i < n; i++)
            {
                if (step == 0)
                {
                    if (data[i] > data[i - 1])
                    {
                        continue;
                    }
                    else if (data[i] == data[i - 1])
                    {
                        step = 1;
                        continue;
                    }
                    else if (data[i] < data[i - 1])
                    {
                        step = 2;
                        continue;
                    }
                }
                if (step == 1)
                {
                    if (data[i] == data[i - 1])
                    {
                        continue;
                    }
                    else if (data[i] < data[i - 1])
                    {
                        step = 2;
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
                if (step == 2)
                {
                    if (data[i] < data[i - 1])
                    {
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }

                //Console.WriteLine(-1);
            }
            Console.WriteLine("YES");
        }
    }
}

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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public int c;
    public string val;
    public PairVariable()
    {
        a = b = 0;
        c = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
        c = 0;
    }
    public PairVariable(int a, int b, string x)
    {
        this.a = a;
        this.b = b;
        val = x;
        c = 0;
    }

    public PairVariable(int a, int b, int c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public int CompareTo(PairVariable other)
    {
        if (this.a > other.a)
        {
            return 1;
        }
        else if (this.a < other.a)
        {
            return -1;
        }
        else
        {
            if (this.b > other.b)
            {
                return 1;
            }
            else if (this.b < other.b)
            {
                return -1;
            }
            else
            {
                if (this.c > other.c)
                {
                    return 1;
                }
                else if (this.c < other.c)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }

            }
        }

    }
}

namespace ConsoleApplication3
{
    class Program
    {

        static bool isPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        static int gcd(int a, int b)
        {
            if (b == 0)
            {
                return a;
            }
            else
            {
                return gcd(b, a % b);
            }
        }
        static long factorial(int a)
        {
            long s = 1;
            for (long i = 1; i <= a; i++)
            {
                s *= i;
            }
            return s;
        }

        static void Main(string[] args)
        {

            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);

            int a = 0;
            int b = 0;
            int c = 0;
            string[] s = Console.ReadLine().Split();
            int[] arr = new int[n];
            if (n == 1)
            {

                Console.WriteLine("YES");
                return;
            }
            for (int i = 0; i < n; i++)
            {
                arr[i] = int.Parse(s[i]);
            }
            string q = "";

            for (int i = 0; i < n-1; i++)
            {
                if (arr[i] < arr[i + 1])
                {
                    q += 1;
                }
                else if (arr[i] == arr[i + 1])
                {
                    q += 2;
                }
                else
                {
                    q += 3;
                }
            }
            for (int i = 0; i < q.Length - 1; i++)
            {
                if ((q[i] == '2' && q[i + 1] == '1') || (q[i] == '3' && q[i + 1] == '1') || (q[i] == '3' && q[i + 1] == '2'))
                {
                    Console.WriteLine("NO");
                    return;
                }

            }
            Console.WriteLine("YES");
        }
    }
}

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

//831A. Унимодальный массив

namespace CodeForces
{

    class Program
    {
        bool Down(int n, int v)
        {
            while (n-- != 0)
            {
                int w = cin.gi();
                if (w >= v) return false;
                v = w;
            }
            return true;
        }

        bool Flat(int n, int v)
        {
            while (n-- != 0)
            {
                int w = cin.gi();
                if (w > v) return false;
                if (w < v) return Down(n, w);
                v = w;
            }
            return true;
        }

        bool Up(int n, int v)
        {
            while (n-- != 0)
            {
                int w = cin.gi();
                if (w == v) return Flat(n, w);
                if (w < v) return Down(n, w);
                v = w;
            }
            return true;
        }

        private void solve()
        {
            Console.WriteLine(Up(cin.gi(), 0) ? "YeS" : "nO");
        }

        static void Main()
        {
            Program app = new Program();
            app.solve();
#if DEBUG
            Console.ReadKey(true);
#endif
        }
    }

    //class Parser
    //{
    //    Regex re = new Regex(@"(?<!\S)[-+]?\d+", RegexOptions.Compiled);
    //    //static Regex re = new Regex(@"[-+]?\d+");

    //    int Index { get; set; }
    //    public string Input { get; set; }
    //    public Parser(string input) { Input = input; }

    //    int[] GetArray(int n)
    //    {
    //        int[] a = new int[n];
    //        Match m = re.Match(Input);
    //        for (int i = 0; i < n; i++)
    //        {
    //            a[i] = int.Parse(m.Value);
    //            m = m.NextMatch();
    //        }

    //        return a;
    //    }

    //    public int GetInt()
    //    {
    //        var m = re.Match(Input, Index);
    //        Index = m.Index + m.Length;
    //        return int.Parse(m.Value);
    //    }

    //}

    class cin
    {
        public static int gi()
        {
            int u, c;
            for (c = Console.In.Read(); c != -1; c = Console.In.Read())
            {
                if (char.IsDigit((char)c))
                {
                    u = c - '0';
                    for (c = Console.In.Read(); c != -1; c = Console.In.Read())
                    {
                        if (char.IsDigit((char)c))
                        {
                            u = 10 * u + c - '0';
                            continue;
                        }

                        break;
                    }

                    return u;
                }
            }

            return 0;
        }
    }

    public class PriorityQueue<T> where T : IComparable<T>
    {
        private List<T> data;

        public PriorityQueue()
        {
            this.data = new List<T>();
        }

        public PriorityQueue(int capacity)
        {
            this.data = new List<T>(capacity);
        }

        public void Enqueue(T item)
        {
            data.Add(item);
            int ci = data.Count - 1; // child index; start at end
            while (ci > 0)
            {
                int pi = (ci - 1) / 2; // parent index
                if (data[ci].CompareTo(data[pi]) >= 0) break; // child item is larger than (or equal) parent so we're done
                T tmp = data[ci]; data[ci] = data[pi]; data[pi] = tmp;
                ci = pi;
            }
        }

        public T Dequeue()
        {
            // assumes pq is not empty; up to calling code
            int li = data.Count - 1; // last index (before removal)
            T frontItem = data[0];   // fetch the front
            data[0] = data[li];
            data.RemoveAt(li);

            --li; // last index (after removal)
            int pi = 0; // parent index. start at front of pq
            while (true)
            {
                int ci = pi * 2 + 1; // left child index of parent
                if (ci > li) break;  // no children so done
                int rc = ci + 1;     // right child
                if (rc <= li && data[rc].CompareTo(data[ci]) < 0) // if there is a rc (ci + 1), and it is smaller than left child, use the rc instead
                    ci = rc;
                if (data[pi].CompareTo(data[ci]) <= 0) break; // parent is smaller than (or equal to) smallest child so done
                T tmp = data[pi]; data[pi] = data[ci]; data[ci] = tmp; // swap parent and child
                pi = ci;
            }
            return frontItem;
        }

        public T Peek()
        {
            T frontItem = data[0];
            return frontItem;
        }

        public int Count()
        {
            return data.Count;
        }

        public override string ToString()
        {
            string s = "";
            for (int i = 0; i < data.Count; ++i)
                s += data[i].ToString() + " ";
            s += "count = " + data.Count;
            return s;
        }

        public bool IsConsistent()
        {
            // is the heap property true for all data?
            if (data.Count == 0) return true;
            int li = data.Count - 1; // last index
            for (int pi = 0; pi < data.Count; ++pi) // each parent index
            {
                int lci = 2 * pi + 1; // left child index
                int rci = 2 * pi + 2; // right child index

                if (lci <= li && data[pi].CompareTo(data[lci]) > 0) return false; // if lc exists and it's greater than parent then bad.
                if (rci <= li && data[pi].CompareTo(data[rci]) > 0) return false; // check the right child too.
            }
            return true; // passed all checks
        } // IsConsistent
    } // PriorityQueue

}

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

namespace _424
{
    class Program
    {
        static void Main(string[] args)
        {
            testA();
            Console.WriteLine();
        }
        static void testA()
        {
            int n = int.Parse(Console.ReadLine());
            int state = 1;
            var ss = Console.ReadLine().Split(' ');
            List<int> li = new List<int>();
            foreach (var i in ss)
            {
                li.Add(int.Parse(i));
            }
            for (int i = 1; i < li.Count; i++)
            {
                int pr = li[i - 1];
                int ic = li[i] - pr;
                if (ic > 0 && state == 1)
                {
                    continue;
                }
                if (ic == 0 & state == 1)
                {
                    state = 2;
                    continue;
                }

                if (ic == 0 & state == 2)
                {
                    continue;
                }
                if (ic < 0 && state == 2)
                {
                    state = 3;
                    continue;
                }
                if (ic < 0 && state == 3) {
                    continue;
                }
                if (ic < 0 && state == 1) {

                    state = 3;
                    continue;
                }
                Console.Write("NO");
                return;
            }
            Console.Write("YES");
        }
    }
}

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

namespace UnimodalArray
{
    class Program
    {
        static void Main(string[] args)
        {
            bool incFinished = false;
            bool constFinished = false;

            bool unimodal = true;

            int amount = int.Parse(Console.ReadLine());
            int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int prev = array[0];

            for(int i=1; i<amount; i++)
            {
                if(array[i] > prev && !incFinished)
                {
                    prev = array[i];
                    continue;
                }
                else if(array[i] == prev && !incFinished)
                {
                    prev = array[i];
                    incFinished = true;
                }
                else if(array[i] == prev && !constFinished)
                {
                    prev = array[i];
                    continue;
                }
                else if (array[i] < prev && !incFinished)
                {
                    prev = array[i];
                    incFinished = true;
                    constFinished = true;
                }
                else if(array[i] < prev && incFinished)
                {
                    prev = array[i];
                    constFinished = true;
                }
                else
                {
                    prev = array[i];
                    unimodal = false;
                }
            }
            Console.WriteLine(unimodal ? "YES" : "NO");
        }
    }
}

using System;
using System.Text.RegularExpressions;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var count = int.Parse(input);
            if (count == 1)
            {
                Console.Write("YES");
                return;
            }
            var array = new int[count];
            input = Console.ReadLine();
            var split = input.Split(new[] { ' ' });
            for (int i = 0; i < count; i++)
            {
                array[i] = int.Parse(split[i]);
            }

            var delta = new char[count - 1];
            for (int i = 0; i < count - 1; i++)
            {
                if (array[i] < array[i + 1])
                {
                    delta[i] = 'a';
                    continue;
                }
                if (array[i] == array[i + 1])
                {
                    delta[i] = 'b';
                    continue;
                }
                if (array[i] > array[i + 1])
                {
                    delta[i] = 'c';
                    continue;
                }
            }
            var str = new string(delta).Trim();
            Console.Write(Regex.IsMatch(str, "^[a]{0,}b+[c]{0,}$") || Regex.IsMatch(str, "^[a]{1,}[c]{1,}$") || Regex.IsMatch(str, "^[a]{1,}$") || Regex.IsMatch(str, "^[c]{1,}$") ? "YES" : "NO");
            //Console.Write(string.Join("", delta));
        }
    }
}

using System;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var canGoUp = true;
            var canGoDown = true;
            var canEq = true;

            for (var i = 0; i < arr.Length - 1; i++)
            {
                var f = arr[i];
                var s = arr[i + 1];

                if (f > s)
                {
                    if (!canGoDown)
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                    canEq = false;
                    canGoUp = false;
                }

                if (f < s)
                {
                    if (!canGoUp)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }

                if (f == s)
                {
                    if (!canEq)
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                    canGoUp = false;
                }
            }

            Console.WriteLine("YES");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Web.UI.WebControls;

namespace Codeforces
{
    class Program : IDisposable
    {
        private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
        private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

        private void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (n == 1)
            {
                Console.WriteLine("YES");
                return;
            }
            var pos1 = 0;
            var pos2 = n - 1;
            var i = 1;
            while (i < n)
            {
                if (!(arr[i] > arr[i - 1]))
                    break;
                i++;
            }
            pos1 = i-1;
            i = n - 1;
            while (i > 0)
            {
                if (!(arr[i - 1] > arr[i]))
                    break;
                i--;
            }
            pos2 = i;

            var val = arr[pos1];
            for (int j = pos1; j <= pos2; j++)
            {
                if (arr[j] != val)
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }

        int BinarySearch(int[] arr, int q)
        {
            var l = 0;
            var r = arr.Length - 1;
            //int med = -1;
            while (l <= r)
            {
                var med = l + (r - l) / 2;
                if (arr[med] == q)
                {
                    return med;
                }
                if (q < arr[med])
                {
                    r = med - 1;
                }
                else
                {
                    l = med + 1;
                }
            }
            return -1;
        }

        static void Main(string[] args)
        {
            var p = new Program();

            //var r1 = r;
            p.Solve();
            //Console.ReadLine();
            p.Dispose();
        }

        #region Helpers

        private static int ReadInt()
        {
            return int.Parse(textReader.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(textReader.ReadLine());
        }

        private static int[] ReadIntArray()
        {
            return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        #endregion

        public void Dispose()
        {
            textReader.Close();
            textWriter.Close();
        }
    }
}

 using System;
 public class Program
    {
        public static void Main(string[] args)
        {
            int[] data;
            {
                string[] input = Console.In.ReadToEnd().Split(new char[] { ' ', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                data = new int[input.Length];
                for (int j = 0; j < data.Length; ++j) data[j] = int.Parse(input[j]);
            }

            bool result = true;
            int i = 2;
            while (i < data.Length && data[i] > data[i - 1]) i++;
            while (i<data.Length && data[i] == data[i - 1]) i++;
            while (i < data.Length && data[i] < data[i - 1]) i++;
            if (i < data.Length) result = false;
            Console.WriteLine(result ? "YES" : "NO");
        }
    }

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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            int[] blocks = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int counter = 1;
            try
            {
                while (blocks[counter] > blocks[counter - 1])
                    counter++;
                while (blocks[counter] == blocks[counter - 1])
                    counter++;
                while (blocks[counter] < blocks[counter - 1])
                    counter++;
            }
            catch
            {
                Console.WriteLine("YES");
                return;
            }
            Console.WriteLine("NO");
        }
    }
}

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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = Convert.ToInt32(Console.ReadLine());
            int[] blocks = new Int32[size];
            string[] s = Console.ReadLine().Split(' ');
            for (int i = 0; i < size; i++)
                blocks[i] = Convert.ToInt32(s[i]);
            int counter = 1;
            try
            {
                while (blocks[counter] > blocks[counter - 1])
                    counter++;
                while (blocks[counter] == blocks[counter - 1])
                    counter++;
                while (blocks[counter] < blocks[counter - 1])
                    counter++;
            }
            catch
            {
                Console.WriteLine("YES");
                return;
            }
            Console.WriteLine("NO");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      var n = input.ReadInt();
      var a = input.ReadIntArray(n);
      Console.Write(IsUnimodal(a) ? "YES" : "NO");
    }

    private bool IsUnimodal(int[] a)
    {
      int n = a.Length;
      int i = 0;
      while (i < n - 1 && a[i] < a[i + 1])
        i++;
      while (i < n - 1 && a[i] == a[i + 1])
        i++;
      while (i < n - 1 && a[i] > a[i + 1])
        i++;
      return i == n - 1;
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

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

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n;

        int[] array;

        bool IsUniModal()
        {
            int i = 0;
            int sec = 0;

            if (n == 1)
                return true;

            for(i=1;i<n;i++)
            {
                if(array[i]-array[i-1] == 0)
                { sec = 1; break; }

                if(array[i]-array[i-1]>0)
                { sec = 0; }

                if(array[i] - array[i-1]<0)
                { sec = 2; break; }
            }
            i++;

            if (sec == 0)
                return true;

            if (sec == 1)
            {
                for (; i < n; i++)
                {
                    if (array[i] - array[i - 1] > 0)
                        return false;

                    if (array[i] - array[i - 1] < 0)
                    {
                        sec = 2; break;
                    }
                }
                i++;
            }

            if (sec == 2)
                for (; i < n; i++)
                    if (array[i] - array[i - 1] >= 0)
                        return false;

            return true;

        }

        public void Solve()
        {
            n = ioHelper.ReadNextInt();

            array = new int[n + 1];

            int i;

            for (i = 0; i < n; i++)
                array[i] = ioHelper.ReadNextInt();

            bool rez = IsUniModal();

            if (rez)
                ioHelper.WriteLine("YES");
            else
                ioHelper.WriteLine("NO");
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}

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

namespace Codeforces
{
    class Program
    {
        static int Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int z = 0;
            int a = 0;

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

            int[] m = Array.ConvertAll(s, int.Parse);

            foreach(int x in m)
            {
                if (z == 0)
                {
                    if (x == a) z = 1;
                    if (x < a)z = 2;
                }
                else if (z == 1)
                {
                    if (x > a)
                    {
                        Console.Write("NO");
                        return 0;
                    }
                    if (x < a) z = 2;
                }
                else
                {
                    if (x >= a)
                    {
                        Console.Write("NO");
                        return 0;
                    }
                }
                a = x;
            }
            Console.WriteLine("YES");
            return 0;
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Unimodal_Array
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            int index0 = 0;
            for (int i = 1; i < n; i++)
            {
                if (nn[i] <= nn[i - 1])
                    break;
                index0 = i;
            }

            int index1 = n - 1;
            for (int i = n - 2; i >= 0; i--)
            {
                if (nn[i] <= nn[i + 1])
                    break;
                index1 = i;
            }

            bool eq = true;
            for (int i = index0 + 1; i <= index1; i++)
            {
                if (nn[i] != nn[i - 1])
                {
                    eq = false;
                    break;
                }
            }

            writer.WriteLine(eq ? "Yes" : "No");

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
namespace _831A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine()), constStart = 0, constEnd = 0;
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            bool result = true;
            for (int i = 1; i < n; i++)
            {
                constStart = i - 1;
                constEnd = i;
                if (a[i] <= a[i - 1])
                    break;
            }
            for (int i = constStart + 1; i < n; i++)
                if (a[i] == a[i - 1])
                    constEnd = i;
                else if (a[i] != a[i - 1])
                {
                    break;
                }
            for (int i = constEnd + 1; i < n; i++)
                if (a[i] >= a[i - 1])
                {
                    result = false;
                    break;
                }
            result = n == 1 || (result && constEnd - constStart > 0);
            Console.WriteLine(result ? "YES" : "NO");
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }
        object Solve()
        {
            var n = ReadLong();
            var a = ReadLongs();
            var i = 0;
            while (i < n - 1 && a[i] < a[i + 1])
                i++;
            while (i < n - 1 && a[i] == a[i + 1])
                i++;
            while (i < n - 1 && a[i] > a[i + 1])
                i++;
            return i == n - 1 ? "YES" : "NO";

        }

        class Vac
        {
            public long Left { get; set; }
            public long Right { get; set; }
            public long Cost { get; set; }
        }

        long Fact(long k)
        {
            return k == 1 ? 1 : k * Fact(k - 1);
        }
        long[,] FastPow(long[,] matrix, long n, long x)
        {
            if (x == 1)
                return matrix;
            if (x % 2 == 0)
                return FastPow(Multiply(matrix, matrix, n), n, x / 2);
            return Multiply(FastPow(matrix, n, x - 1), matrix, n);
        }

        long[,] Multiply(long[,] x, long[,] y, long n)
        {
            var result = new long[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        result[i, j] += x[i, k] * y[k, j] % commonMod;
                    }
                    result[i, j] = result[i, j] % commonMod;
                }
            }
            return result;
        }

        class End
        {
            public long Val { get; set; }
            public bool Left { get; set; }
        }

        int BS(long[] a, int left, int right, long s)
        {
            if (right - left == 1)
                return left;
            var half = (left + right) / 2;
            if (Check(half, a, s))
                return BS(a, half, right, s);
            return BS(a, left, half, s);
        }

        bool Check(int k, long[] a, long s)
        {
            var newArr = new long[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                newArr[i] = a[i] + ((long)k) * (i + 1);
            }
            Array.Sort(newArr);
            return newArr.Take(k).Sum() <= s;
        }

        double Dist(Point a, Point b, Point z)
        {
            return Math.Abs((b.y - a.y) * z.x - (b.x - a.x) * z.y + b.x * a.y - b.y * a.x) / Math.Sqrt((b.y - a.y) * (b.y - a.y) + (b.x - a.x) * (b.x - a.x));
        }

    }

    class Point
    {
        public double x { get; set; }
        public double y { get; set; }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10)
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            //var i = s.IndexOf(' ');
            //return new[] { long.Parse(s.Substring(0, i)), long.Parse(s.Substring(i + 1)) };
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }

}

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

namespace Contest831A
{
    class Program
    {
        static void Main(string[] args)
        {
            var way = 1;
            Console.ReadLine();
            var previous = -1;
            var unimodelNum = -1;
            var unimodelCount = 0;
            var values = Console.ReadLine().Split(' ');
            for (var i = 0; i < values.Length; i++)
            {
                var current = int.Parse(values[i]);
                if (current > previous)
                {
                    if (way == 0 || way == -1)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
                else if (current == previous)
                {
                    if (unimodelNum == -1)
                    {
                        unimodelNum = current;
                    }
                    if (way == -1 || current != unimodelNum)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                    way = 0;
                    unimodelNum = current;
                    unimodelCount = 0;
                }
                else if (current < previous)
                {
                    if (way == 1 && unimodelCount != 0)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                    way = -1;
                }
                previous = current;
            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace olimp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int length = Convert.ToInt32(Console.ReadLine());
            int[] arr = new int[length];
            string[] s = Console.ReadLine().Split(' ');
            for (int i = 0; i < length; i++)
            {
                arr[i] = Convert.ToInt32(s[i]);
            }
            Console.WriteLine(isUnimodal(arr) ? "YES" : "NO");
        }

        static bool isUnimodal(int[] arr)
        {
            bool isInc = true;
            bool isConst = true;
            int i;
            for (i = 0; i < arr.Length-1; i++)
            {
                if (isInc && arr[i + 1] > arr[i])
                    continue;
                else
                {
                    isInc = false;
                    if (isConst && arr[i + 1] == arr[i])
                        continue;
                    else
                    {
                        isConst = false;
                        if (arr[i + 1] < arr[i])
                            continue;
                        else break;
                    }
                }

            }
            if (i == arr.Length-1)
                return true;
            else return false;
        }
    }
}

using System;
using System.Linq;

namespace CSharp
{
    public class _831A
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();

            int left = 0;
            while (left + 1 < n && a[left] < a[left + 1])
            {
                left++;
            }

            int right = n - 1;
            while (right > 0 && a[right] < a[right - 1])
            {
                right--;
            }

            for (int i = left; i < right; i++)
            {
                if (a[i] != a[right])
                {
                    Console.WriteLine("NO");
                    return;
                }
            }

            Console.WriteLine("YES");
        }
    }
}

using System;
using System.Linq;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();
            var answer = Solve(input1, input2);
            Console.WriteLine(answer);
        }

        public static string Solve(string input1, string input2)
        {
            var n = int.Parse(input1);
            if (n == 1) return "YES";
            var array = input2.Split(' ').Select(c => int.Parse(c)).ToArray();

            var previous = array[0];
            var i = 1;

            //increase
            for (; i < n; i++)
            {
                if (previous == array[i]) break; //constant began
                if (previous > array[i]) break; //constant of 1 and begin decrease
                previous = array[i];
            }

            //constant
            for (; i < n; i++)
            {
                if (array[i] > previous) return "NO"; //cannot increase again
                if (previous > array[i]) break; //begin decrease
            }

            //decrease
            for (; i < n; i++)
            {
                if (array[i] > previous) return "NO";
                if (array[i] == previous) return "NO";
                previous = array[i];
            }

            return "YES";
        }
    }
}

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = int.Parse(str[i]);
        }
        int state = 0;
        bool OK = true;
        for(int i=0;i<N-1;i++){
            if(A[i+1] > A[i]){
                if(state != 0){
                    OK = false;
                    break;
                }
            }
            else if(A[i+1] == A[i]){
                if(state == 2){
                    OK = false;
                    break;
                }
                else{
                    state = 1;
                }
            }
            else{
                state = 2;
            }
        }
        if(OK){
            sb.Append("YES\n");
        }
        else{
            sb.Append("NO\n");
        }
    }
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] linea = Console.ReadLine().Split();
            bool bajando = false;
            bool res = true;
            for (int i = 0; i < linea.Length - 1; i++)
            {
                int a = int.Parse(linea[i].ToString());
                int b = int.Parse(linea[i + 1].ToString());
                if (!bajando)
                {
                    if (b < a)
                    {
                        bajando = true;
                    }
                }
                if (bajando)
                {
                    if (b >= a)
                    {
                        res = false;
                        break;
                    }
                }
            }
            if (res)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

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

namespace FORexam
{
    class Program
    {
        static void Main(string[] args)
        {
            bool ach = true;
            bool stab = false;
            bool nva = false;
            int n = Convert.ToInt32(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = Convert.ToInt32(input[i]);
            }

            for (int i = 1; i < n; i++)
            {
                if (arr[i] < arr[i - 1] && ach == true)
                {
                    ach = false;
                    stab = true;
                }
                else if (arr[i ] != arr[i - 1] && stab == true)
                {
                    nva = true;
                    stab = false;
                }
                else if (arr[i ] > arr[i - 1] && nva == true)
                {
                    Console.WriteLine("NO");
                }

            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace A_UnimodalArray
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.ReadLine();
			var numbers = Console.ReadLine().Split().Select(Int32.Parse).ToArray();

			if (numbers.Length < 3)
			{
				Console.WriteLine("NO");
				return;
			}
			else
			{
				int state = 0;
				int old = numbers[0];
				for (int i = 1; i < numbers.Length; ++i)
				{
					if (state == 0)
					{
						if (numbers[i] < old)
						{
							Console.WriteLine("NO");
							return;
						}else if (numbers[i] == old)
						{
							state = 1;
						}
					}else if (state == 1)
					{
						if (numbers[i] > old)
						{
							Console.WriteLine("NO");
							return;
						}else if (numbers[i] < old)
						{
							state = 2;
						}
					}else if (state == 2)
					{
						if (numbers[i] >= old)
						{
							Console.WriteLine("NO");
							return;
						}
					}

					old = numbers[i];
				}

				Console.WriteLine("YES");
				return;
			}
		}
	}
}

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

namespace A_UnimodalArray
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.ReadLine();
			var numbers = Console.ReadLine().Split().Select(Int32.Parse).ToArray();
			int i = 0;
			bool first = false;
			bool second = false;
			bool third = false;
			while (i < numbers.Length - 1 && numbers[i + 1] > numbers[i])
			{
				first = true;
				i++;
			}
			while (i < numbers.Length - 1 && numbers[i + 1] == numbers[i])
			{
				second = true;
				i++;
			}
			while (i < numbers.Length - 1 && numbers[i + 1] < numbers[i])
			{
				third = true;
				i++;
			}
			Console.WriteLine(first && second && third ? "YES" : "NO");
		}
	}
}

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

namespace A_UnimodalArray
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.ReadLine();
			var numbers = Console.ReadLine().Split().Select(Int32.Parse).ToArray();
			int i = 0;
			bool second = false;
			while (i < numbers.Length - 1 && numbers[i + 1] > numbers[i])
			{
				i++;
			}
			while (i < numbers.Length - 1 && numbers[i + 1] == numbers[i])
			{
				second = true;
				i++;
			}
			while (i < numbers.Length - 1 && numbers[i + 1] < numbers[i])
			{
				i++;
			}
			Console.WriteLine(second && i == numbers.Length - 1 ? "YES" : "NO");
		}
	}
}

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

namespace A_UnimodalArray
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.ReadLine();
			var numbers = Console.ReadLine().Split().Select(Int32.Parse).ToArray();

			if (numbers.Length < 3)
			{
				Console.WriteLine("NO");
				return;
			}
			else
			{
				int state = 0;
				int old = numbers[0];

				int increasing = 0;

				for (int i = 1; i < numbers.Length; ++i)
				{
					var current = numbers[i];
					if (state == 0)
					{
						if (current < old)
						{
							Console.WriteLine("NO");
							return;
						}
						else if (current == old)
						{
							state = 1;
						}
						else
						{
							increasing ++;
						}
					}else if (state == 1)
					{
						if (current > old)
						{
							Console.WriteLine("NO");
							return;
						}else if (current < old)
						{
							state = 2;
						}
					}else if (state == 2)
					{
						if (current >= old)
						{
							Console.WriteLine("NO");
							return;
						}
					}

					old = current;
				}

				Console.WriteLine(increasing > 0 && state == 2 ? "YES" : "NO");
				return;
			}
		}
	}
}

using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string firstLine = Console.ReadLine();
            string secondLine = Console.ReadLine();

            int firstArray = int.Parse(firstLine);
            string[] secondArray = secondLine.Split(' ');

            int[] values = Array.ConvertAll(secondArray, int.Parse);

            int constStart = 0;
            int constEnd = values.Length - 1;

            int index = 0;
            while (index + 2 < values.Length && values[index] < values[index + 1])
            {
                index++;
            }
            //index++;
            constStart = index;

            index = constEnd;

            while (index > 0 && values[index] < values[index - 1])
            {
                index--;
            }
            //index--;
            constEnd = index;

            bool isModal = true;

            for (int i = constStart; i < constEnd; i++)
            {
                if (values[i] != values[i + 1])
                {
                    isModal = false;
                    break;
                }

            }

            if (isModal)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

    }
}

using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string firstLine = Console.ReadLine();
            string secondLine = Console.ReadLine();

            int firstArray = int.Parse(firstLine);
            string[] secondArray = secondLine.Split(' ');

            int[] values = Array.ConvertAll(secondArray, int.Parse);

            int constStart = 0;
            int constEnd = values.Length - 1;

            int index = 0;
            while(index+2 < values.Length && values[index] < values[index + 1])
            {
                index++;
            }
            index++;
            constStart = index;

            index = constEnd;

            while(index > 0 && values[index] < values[index - 1])
            {
                index--;
            }
            index--;
            constEnd = index;

            bool isModal = true;

            if(constStart == constEnd)
            {
                isModal = false;
            }
            else
            {
                for (int i = constStart; i < constEnd; i++)
                {
                    if (values[i] != values[i + 1])
                    {
                        isModal = false;
                        break;
                    }

                }
            }

            if (isModal)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

    }
}

using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string firstLine = Console.ReadLine();
            string secondLine = Console.ReadLine();

            int firstArray = int.Parse(firstLine);
            string[] secondArray = secondLine.Split(' ');

            int[] values = Array.ConvertAll(secondArray, int.Parse);

            int constStart = 0;
            int constEnd = values.Length - 1;

            int index = 0;
            while(index+2 < values.Length && values[index] < values[index + 1])
            {
                index++;
            }
            index++;
            constStart = index;

            index = constEnd;

            while(index > 0 && values[index] < values[index - 1])
            {
                index--;
            }
            //index--;
            constEnd = index;

            bool isModal = true;

            if(constStart == constEnd)
            {
                isModal = false;
            }
            else
            {
                for (int i = constStart; i < constEnd; i++)
                {
                    if (values[i] != values[i + 1])
                    {
                        isModal = false;
                        break;
                    }

                }
            }

            if (isModal)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }

    }
}

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

namespace uni
{
    class Program
    {
        public bool equal(int in1,int in2)
        {
            if (in1==in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool greater(int in1, int in2)
        {
            if (in1 > in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool smaller(int in1, int in2)
        {
            if (in1 < in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        static void Main(string[] args)
        {
            Program n = new Program();
            int x;
           x=Convert.ToInt32(Console.ReadLine());
            List<int> nums=new List<int>();
            List<string> st = new List<string> ();
            string y = Console.ReadLine();
            string[] temp = y.Split();
            for (int i=0;i<x;i++)
            {
                nums.Add(Convert.ToInt32(temp[i]));
            }
            for (int i=0;i<x-1;i++)
            {
                bool temp1 =n.equal(nums[i],nums[i+1]);
                bool temp2 =n.greater(nums[i], nums[i+1]);
                bool temp3 =n.smaller(nums[i], nums[i+1]);
                if (temp1==true)
                {
                    st.Add("Equal");
                }
               else if (temp2 == true)
                {
                    st.Add("decreasing");
                }
               else if (temp3 == true)
                {
                    st.Add("increasing");
                }
            }
            bool t = false;
            for (int i=0;i<st.Count()-1;i++)
            {
                if (st[i+1]== "increasing"&& st[i] == "decreasing")
                {
                    Console.WriteLine("NO");
                    t = true;
                }
               else if (st[i+1] == "Equal" && st[i] == "decreasing")
                {
                    Console.WriteLine("NO");
                    t = true;
                }
              else  if (st[i+1] == "increasing" && st[i] == "Equal")
                {
                    Console.WriteLine("NO");
                    t = true;
                }
            }
            if (t==false)
            {
                Console.WriteLine("YES");
            }
        }
     }
}

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

namespace uni
{
    class Program
    {
        public bool equal(int in1,int in2)
        {
            if (in1==in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool greater(int in1, int in2)
        {
            if (in1 > in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool smaller(int in1, int in2)
        {
            if (in1 < in2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        static void Main(string[] args)
        {
            Program n = new Program();
            int x;
           x=Convert.ToInt32(Console.ReadLine());
            List<int> nums=new List<int>();
            List<string> st = new List<string> ();
            string y = Console.ReadLine();
            string[] temp = y.Split();
            for (int i=0;i<x;i++)
            {
                nums.Add(Convert.ToInt32(temp[i]));
            }
            for (int i=0;i<x-1;i++)
            {
                bool temp1 =n.equal(nums[i],nums[i+1]);
                bool temp2 =n.greater(nums[i], nums[i+1]);
                bool temp3 =n.smaller(nums[i], nums[i+1]);
                if (temp1==true)
                {
                    st.Add("Equal");
                }
               else if (temp2 == true)
                {
                    st.Add("decreasing");
                }
               else if (temp3 == true)
                {
                    st.Add("increasing");
                }
            }
            bool t = false;
            for (int i=0;i<st.Count()-1;i++)
            {
                if (st[i+1]== "increasing"&& st[i] == "decreasing")
                {
                    Console.WriteLine("NO");
                    t = true;
                }
                if (st[i+1] == "Equal" && st[i] == "decreasing")
                {
                    Console.WriteLine("NO");
                    t = true;
                }
                if (st[i+1] == "increasing" && st[i] == "Equal")
                {
                    Console.WriteLine("NO");
                    t = true;
                }
            }
            if (t==false)
            {
                Console.WriteLine("YES");
            }
        }
     }
}

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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public int c;
    public string val;
    public PairVariable()
    {
        a = b = 0;
        c = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
        c = 0;
    }
    public PairVariable(int a, int b, string x)
    {
        this.a = a;
        this.b = b;
        val = x;
        c = 0;
    }

    public PairVariable(int a, int b, int c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public int CompareTo(PairVariable other)
    {
        if (this.a > other.a)
        {
            return 1;
        }
        else if (this.a < other.a)
        {
            return -1;
        }
        else
        {
            if (this.b > other.b)
            {
                return 1;
            }
            else if (this.b < other.b)
            {
                return -1;
            }
            else
            {
                if (this.c > other.c)
                {
                    return 1;
                }
                else if (this.c < other.c)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }

            }
        }

    }
}

namespace ConsoleApplication3
{
    class Program
    {

        static bool isPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        static int gcd(int a, int b)
        {
            if (b == 0)
            {
                return a;
            }
            else
            {
                return gcd(b, a % b);
            }
        }
        static long factorial(int a)
        {
            long s = 1;
            for (long i = 1; i <= a; i++)
            {
                s *= i;
            }
            return s;
        }

        static void Main(string[] args)
        {

            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);

            int a = 0;
            int b = 0;
            int c = 0;
            string[] s = Console.ReadLine().Split();
            int[] arr = new int[n];
            if (n == 1)
            {

                Console.WriteLine("YES");
                return;
            }
            for (int i = 0; i < n; i++)
            {
                arr[i] = int.Parse(s[i]);
            }
            string q = "";

            for (int i = 0; i < n-1; i++)
            {
                if (arr[i] <= arr[i + 1])
                {
                    q += 1;
                }
                else
                {
                    q += 0;
                }
            }
            if (q[0] == '0')
            {
                Console.WriteLine("NO");
                return;
            }
            int p = 0;
            for (int i = 0; i < q.Length; i++)
            {
                if (q[i] == '1')
                {
                    p = i;

                }
            }
            for (int i = 0; i <= p; i++)
            {
                if (q[i] == '0')
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace UnimodalArray
{
    class Program
    {
        static void Main(string[] args)
        {
            bool incFinished = false;
            bool constFinished = false;

            bool unimodal = true;

            int amount = int.Parse(Console.ReadLine());
            int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int prev = array[0];

            for(int i=1; i<amount; i++)
            {
                if(array[i] > prev && !incFinished)
                {
                    prev = array[i];
                    continue;
                }
                else if(array[i] == prev && !incFinished)
                {
                    prev = array[i];
                    incFinished = true;
                }
                else if(array[i] == prev && !constFinished)
                {
                    prev = array[i];
                    continue;
                }
                else if(array[i] < prev && incFinished)
                {
                    prev = array[i];
                    constFinished = true;
                }
                else
                {
                    prev = array[i];
                    unimodal = false;
                }
            }
            Console.WriteLine(unimodal ? "YES" : "NO");
        }
    }
}

using System;
using System.Text.RegularExpressions;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var count = int.Parse(input);
            if(count == 1)
            {
                Console.Write("YES");
                return;
            }
            var array = new int[count];
            input = Console.ReadLine();
            var split = input.Split(new[] { ' ' });
            for (int i = 0; i < count; i++)
            {
                array[i] = int.Parse(split[i]);
            }

            var delta = new char[count - 1];
            for(int i = 0; i < count - 1; i++)
            {
                if (array[i] < array[i + 1])
                {
                    delta[i] = 'a';
                    continue;
                }
                if (array[i] == array[i + 1])
                {
                    delta[i] = 'b';
                    continue;
                }
                if (array[i] > array[i + 1])
                {
                    delta[i] = 'c';
                    continue;
                }
            }
            var str = new string(delta);
            Console.Write(Regex.IsMatch(str, "^[a]{0,}b+[c]{0,}$") || Regex.IsMatch(str, "^[a]{1,}[c]{1,}$") ? "YES" : "NO");
            //Console.Write(string.Join("", delta));
        }
    }
}

using System;
using System.Text.RegularExpressions;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var count = int.Parse(input);
            if (count == 1)
            {
                Console.Write("YES");
                return;
            }
            var array = new int[count];
            input = Console.ReadLine();
            var split = input.Split(new[] { ' ' });
            for (int i = 0; i < count; i++)
            {
                array[i] = int.Parse(split[i]);
            }

            var delta = new char[count - 1];
            for (int i = 0; i < count - 1; i++)
            {
                if (array[i] < array[i + 1])
                {
                    delta[i] = 'a';
                    continue;
                }
                if (array[i] == array[i + 1] || (array[i] > array[i - 1] && array[i] > array[i + 1]))
                {
                    delta[i] = 'b';
                    continue;
                }
                if (array[i] > array[i + 1])
                {
                    delta[i] = 'c';
                    continue;
                }
            }
            var str = new string(delta).Trim();
            Console.Write(Regex.IsMatch(str, "^[a]{0,}b+[c]{0,}$") || Regex.IsMatch(str, "^[a]{1,}[c]{1,}$") ? "YES" : "NO");
            //Console.Write(string.Join("", delta));
        }
    }
}

using System;
using System.Text.RegularExpressions;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var count = int.Parse(input);
            var array = new int[count];
            input = Console.ReadLine();
            var split = input.Split(new[] { ' ' });
            for (int i = 0; i < count; i++)
            {
                array[i] = int.Parse(split[i]);
            }

            var delta = new char[count - 1];
            for(int i = 0; i < count - 1; i++)
            {
                if (array[i] < array[i + 1])
                {
                    delta[i] = 'a';
                    continue;
                }
                if (array[i] == array[i + 1])
                {
                    delta[i] = 'b';
                    continue;
                }
                if (array[i] > array[i + 1])
                {
                    delta[i] = 'c';
                    continue;
                }
            }
            var str = new string(delta);
            Console.Write(Regex.IsMatch(str, "^[a]{0,}b+[c]{0,}$") || Regex.IsMatch(str, "^[a]{1,}[c]{1,}$") ? "YES" : "NO");
            //Console.Write(string.Join("", delta));
        }
    }
}

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

namespace Codeforces
{

    class Program
    {
        public void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (n == 1)
            {
                Console.WriteLine("YES");
                return;
            }
            bool incr = false, decr = false, cons = false;
            var curr = arr[0];
            for (int i = 1; i < n; i++)
            {
                if (arr[i] > arr[i - 1])
                {
                    incr = true;
                    if (decr || cons)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
                else if (arr[i] < arr[i - 1])
                {
                    decr = true;
                    if (!cons && incr)
                        cons = true;
                    if (!cons && !incr)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
                else if (arr[i] == arr[i - 1] || (i + 1 < n && arr[i] > arr[i - 1] && arr[i] < arr[i + 1]))
                {
                    cons = true;
                    if (decr)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
            }
            Console.WriteLine("YES");
        }

        static void Main(string[] args)
        {
            var p = new Program();
            p.Solve();
            //Console.ReadLine();
        }
    }

}

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

namespace Codeforces
{

    class Program
    {
        public void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (n == 1)
            {
                Console.WriteLine("YES");
                return;
            }
            //bool incr = true, decr = false, cons = false;
            bool incrAllTheTime = true;
            bool decrAllTheTime = true;
            for (int i = 1; i < n; i++)
            {
                if (arr[i] >= arr[i - 1])
                    continue;
                else
                    incrAllTheTime = false;
            }

            for (int i = 1; i < n; i++)
            {
                if (arr[i] <= arr[i - 1])
                    continue;
                else
                    decrAllTheTime = false;
            }
            if(incrAllTheTime || decrAllTheTime)
            {
                Console.WriteLine("YES");
                return;
            }

            bool incr = false, decr = false;
            for (int i = 1; i < n; i++)
            {
                if (arr[i] > arr[i - 1])
                {
                    incr = true;
                    if (decr)
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                }
                else if(arr[i] < arr[i - 1])
                {
                    decr = true;
                    if (!incr)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
            }
            Console.WriteLine("YES");
        }

        static void Main(string[] args)
        {
            var p = new Program();
            p.Solve();
            //Console.ReadLine();
        }
    }

}

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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = Convert.ToInt32(Console.ReadLine());
            int[] blocks = new Int32[size];
            string[] s = Console.ReadLine().Split(' ');
            for (int i = 0; i < size; i++)
                blocks[i] = Convert.ToInt32(s[i]);
            if ((double)size / 2.0 % 2 == 0)
            {
                if (blocks[size / 2] != blocks[size / 2 + 1])
                {
                    Console.WriteLine("NO");
                    return;
                }
                for (int i = 0; i < size / 2 - 1; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2 - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size - 1; i > size / 2 ; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i - 1] != blocks[size / 2 ])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            else
            {
                for (int i = 0; i < size / 2 + 1; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2 - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size -1; i > size / 2 +1  ; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i] != blocks[size / 2])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = Convert.ToInt32(Console.ReadLine());
            int[] blocks = new Int32[size];
            string[] s = Console.ReadLine().Split(' ');
            for (int i = 0; i < size; i++)
                blocks[i] = Convert.ToInt32(s[i]);
            if (size == 1)
            {
                Console.WriteLine("YES");
                return;
            }
            if (size / 2 % 2 != 0)
            {
                if (blocks[size / 2] != blocks[size / 2 - 1])
                {
                    Console.WriteLine("NO");
                    return;
                }
                for (int i = 0; i < size / 2 - 1; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2 - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size - 1; i > size / 2 ; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i - 1] != blocks[size / 2 ])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            else
            {
                for (int i = 0; i < size / 2-1; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2 - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size -1; i > size / 2; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i] != blocks[size / 2])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = Convert.ToInt32(Console.ReadLine());
            int[] blocks = new Int32[size];
            string[] s = Console.ReadLine().Split(' ');
            for (int i = 0; i < size; i++)
                blocks[i] = Convert.ToInt32(s[i]);
            if (size == 1)
            {
                Console.WriteLine("YES");
                return;
            }
            if (size / 2 % 2 != 0)
            {
                if (blocks[size / 2] != blocks[size / 2 - 1])
                {
                    Console.WriteLine("NO");
                    return;
                }
                for (int i = 0; i < size / 2 - 1; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2 - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size - 1; i > size / 2 ; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i - 1] != blocks[size / 2 ])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            else
            {
                for (int i = 0; i < size / 2 + 1; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2 - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size -1; i > size / 2 +1  ; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i] != blocks[size / 2])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = Convert.ToInt32(Console.ReadLine());
            int[] blocks = new Int32[size];
            string[] s = Console.ReadLine().Split(' ');
            for (int i = 0; i < size; i++)
                blocks[i] = Convert.ToInt32(s[i]);
            if (size == 1)
            {
                Console.WriteLine("YES");
                return;
            }
            if ((double)size / 2.0 % 2.0 == 0)
            {
                if (blocks[size / 2] != blocks[size / 2 - 1])
                {
                    Console.WriteLine("NO");
                    return;
                }
                for (int i = 0; i < size / 2 - 1; i++)
                    if (blocks[i] >= blocks[i + 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size - 1; i > size / 2 ; i--)
                    if (blocks[i] >= blocks[i - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            else
            {
                for (int i = 0; i < size / 2; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size -1; i > size / 2; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i] != blocks[size / 2])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = Convert.ToInt32(Console.ReadLine());
            int[] blocks = new Int32[size];
            string[] s = Console.ReadLine().Split(' ');
            for (int i = 0; i < size; i++)
                blocks[i] = Convert.ToInt32(s[i]);
            if (size == 1)
            {
                Console.WriteLine("YES");
                return;
            }
            if ((double)size / 2.0 % 2.0 == 0)
            {
                if (blocks[size / 2] != blocks[size / 2 - 1])
                {
                    Console.WriteLine("NO");
                    return;
                }
                for (int i = 0; i < size / 2 - 1; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2 - 1])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size - 1; i > size / 2 ; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i - 1] != blocks[size / 2 ])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            else
            {
                for (int i = 0; i < size / 2; i++)
                    if (blocks[i] >= blocks[i + 1] && blocks[i + 1] != blocks[size / 2])
                    {
                        Console.WriteLine("NO");
                        return;
                    }

                for (int i = size -1; i > size / 2; i--)
                    if (blocks[i] >= blocks[i - 1] && blocks[i] != blocks[size / 2])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
            }
            Console.WriteLine("YES");
        }
    }
}

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

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString();
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int n;

        int[] array;

        bool IsUniModal()
        {
            int i = 0;
            int sec = 0;

            if (n == 1)
                return true;

            for(i=2;i<n;i++)
            {
                if(array[i]-array[i-1] == 0)
                { sec = 1; break; }

                if(array[i]-array[i-1]>0)
                { sec = 0; }

                if(array[i] - array[i-1]<0)
                { sec = 2; break; }
            }
            i++;

            if (sec == 0)
                return true;

            if (sec == 1)
            {
                for (; i < n; i++)
                {
                    if (array[i] - array[i - 1] > 0)
                        return false;

                    if (array[i] - array[i - 1] < 0)
                    {
                        sec = 2; break;
                    }
                }
                i++;
            }

            if (sec == 2)
                for (; i < n; i++)
                    if (array[i] - array[i - 1] >= 0)
                        return false;

            return true;

        }

        public void Solve()
        {
            n = ioHelper.ReadNextInt();

            array = new int[n + 1];

            int i;

            for (i = 0; i < n; i++)
                array[i] = ioHelper.ReadNextInt();

            bool rez = IsUniModal();

            if (rez)
                ioHelper.WriteLine("YES");
            else
                ioHelper.WriteLine("NO");
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}

using System;
namespace _831A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine()), constStart = 0, constEnd = 0;
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            bool result = true;
            for (int i = 1; i < n; i++)
            {
                if (a[i] <= a[i - 1])
                {
                    constStart = i - 1;
                    constEnd = i;
                    break;
                }
            }
            for (int i = constStart + 1; i < n; i++)
                if (a[i] == a[i - 1])
                    constEnd = i;
                else if (a[i] < a[i - 1])
                {
                    break;
                }
                else if (a[i] > a[i - 1])
                {
                    result = false;
                    break;
                }
            for (int i = constEnd + 1; i < n; i++)
                if (a[i] >= a[i - 1])
                {
                    result = false;
                    break;
                }
            result = n == 1 || (result && constEnd - constStart > 0);
            Console.WriteLine(result ? "YES" : "NO");
        }
    }
}

using System;
using System.Linq;

namespace CodeForce
{
    public class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();
            var answer = Solve(input1, input2);
            Console.WriteLine(answer);
        }

        public static string Solve(string input1, string input2)
        {
            var n = int.Parse(input1);
            if (n == 1) return "YES";
            var array = input2.Split(' ').Select(c => int.Parse(c)).ToArray();

            var previous = array[0];
            var i = 1;

            //increase
            for (; i < n; i++)
            {
                if (previous == array[i]) break; //constant began
                if (previous > array[i]) break; //constant of 1 and begin decrease
                previous = array[i];
            }

            //constant
            for (; i < n; i++)
            {
                if (array[i] > previous) return "NO"; //cannot increase again
                if (previous > array[i]) break; //begin decrease
            }

            //decrease
            for (; i < n; i++)
            {
                if (array[i] > previous) return "NO";
                if (array[i] == previous) return "NO";
            }

            return "YES";
        }
    }
}

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

namespace Contest1UnimodalArrayA00817810
{
    class Program
    {
        static void Main(string[] args)
        {
            string stringInput  = Console.ReadLine();
            int arrayLength = int.Parse(stringInput);

            stringInput = Console.ReadLine();
            string[] inputs = stringInput.Split(' ');
            int[] array = new int[arrayLength];
            for (int i = 0; i < arrayLength; i++)
            {

                array[i] = int.Parse(inputs[i]);
            }

            bool isFirstBlock = true;
            bool isMediumBlock = false;
            bool isLastBlock = false;
            bool isUnimodal = true;
            int lastNumber = array[0];

            for (int i=1; i< arrayLength; i++)
            {
                if (isFirstBlock)
                {
                    if(array[i] < lastNumber)
                    {
                        Console.WriteLine("NO");
                        isUnimodal = false;
                        break;
                    }else if(array[i] == lastNumber)
                    {
                        isFirstBlock = false;
                        isMediumBlock = true;
                    }
                }else if (isMediumBlock)
                {
                    if (array[i] > lastNumber)
                    {
                        Console.WriteLine("NO");
                        isUnimodal = false;
                        break;
                    }
                    else if (array[i] < lastNumber)
                    {
                        isMediumBlock = false;
                        isLastBlock = true;
                    }
                }
                else if(isLastBlock)
                {
                    if (array[i] > lastNumber || array[i] == lastNumber)
                    {
                        Console.WriteLine("NO");
                        isUnimodal = false;
                        break;
                    }
                }
                lastNumber = array[i];
            }
            if (isUnimodal)
            {
                Console.WriteLine("YES");
            }
        }
    }
}

using System;
using System.IO;

namespace archivess1488
{
    class MainClass
    {
        public static void Main()
        {
            int n =  int.Parse(Console.ReadLine());
            string nubms = Console.ReadLine();
            string[] num;
            int[] numbers = new int[n];
            num = nubms.Split(' ');
            for (int i = 0; i < n; i++)
                numbers[i] = int.Parse(num[i]);
            bool down = false, constant = false, up = false;
            if (n < 3) constant = true;
            else
            {
				if (numbers[0] < numbers[1]) up = true;
				else up = false;
                for (int i = 1; i < numbers.Length; i++)
                {
                    if (!constant)
                    {
                        if (numbers[i] > numbers[i - 1] && !up) break;
                        if (numbers[i] == numbers[i - 1]) constant = true;
                        if (numbers[i] < numbers[i - 1]) { constant = true; down = true; }
                    }
                    else if (constant && !down)
                    {
                        if (numbers[i] > numbers[i - 1]) { constant = false; break;  }
                        if (numbers[i] < numbers[i - 1] && !down) down = true;
                    }
                    else if (constant && down)
                    {
                        if (numbers[i] > numbers[i - 1]) { constant = false; break;  }
                        if (numbers[i] == numbers[i - 1]) { constant = false; break;  }
                    }
                }
            }
            if (constant == false) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}