Array of integers is unimodal, if:

  it is strictly increasing in the beginning;  after that it is constant;  after that it is strictly decreasing. 

The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

Write a program that checks if an array is unimodal.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1 000) — the elements of the array.


-----Output-----

Print "YES" if the given array is unimodal. Otherwise, print "NO".

You can output each letter in any case (upper or lower).


-----Examples-----
Input
6
1 5 5 5 4 2

Output
YES

Input
5
10 20 30 20 10

Output
YES

Input
4
1 2 1 2

Output
NO

Input
7
3 3 3 3 3 3 3

Output
YES



-----Note-----

In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).

Difficulty: interview

Starter code:

Solutions:
n = int(input())
L = list(map(int, input().split()))
i = 0
a = 0
while i < n and L[i] > a:
    a = L[i]
    i += 1
while i < n and L[i] == a:
    i += 1
while i < n and L[i] < a:
    a = L[i]
    i += 1
if i == n:
    print("YES")
else:
    print("NO")


n = int(input())
a = list(map(int, input().split()))
i = 0
while i + 1 < n and a[i] < a[i + 1]:
    i += 1
if i + 1 == n:
    print('YES')
else:
    while i + 1 < n and a[i] == a[i + 1]:
        i += 1
    if i + 1 == n:
        print('YES')
    else:
        while i + 1 < n and a[i] > a[i + 1]:
            i += 1
        if i + 1 == n:
            print('YES')
        else:
            print('NO')

n = int(input())
a = list(map(int, input().split()))


i = 1
while i < n and a[i] > a[i - 1]:
    i += 1
while i < n and a[i] == a[i - 1]:
    i += 1
while i < n and a[i] < a[i - 1]:
    i += 1

if i == n:
    print('YES')
else:
    print('NO')


n = int(input())
a = list(map(int, input().split()))

d = [a[i] - a[i - 1] for i in range(1, n)]

# print(d)

for i in range(len(d) - 1):
	if d[i] <= 0 and d[i + 1] > 0:
		print('NO')
		return
	if d[i] < 0 and d[i + 1] == 0:
		print('NO')
		return

print('YES')


n = int(input())
a = list(map(int, input().split()))
i = 0
while i + 1 < n and a[i] < a[i + 1]:
    i += 1
j = n - 1
while j > 0 and a[j] < a[j - 1]:
    j -= 1
flag = True
for x in range(i, j + 1):
    if a[x] != a[i]:
        flag = False
        break
print("YES" if flag else "NO")


n = int(input())
a = list(map(int, input().split()))
curr = 1
while curr < n and a[curr] > a[curr - 1]:
    curr += 1
while curr < n and a[curr] == a[curr - 1]:
    curr += 1
while curr < n and a[curr] < a[curr - 1]:
    curr += 1
if curr == n:
    print('YES')
else:
    print('NO')

n=int(input())
l=[int(i)for i in input().split()]
ans = "YES"
mod= "up"
if n>1:
	for i in range(1,n):
		if l[i-1]<l[i] :
			if mod=="up":
				continue
			else:
				ans = "NO"
				break
		elif l[i-1]==l[i] :
			if (mod =="up" or mod =="same"):
				mod = "same"
			else :			
				ans = "NO"
				break
		else  :
			mod = "down"
print(ans)

n = input()
n = [int(I) for I in input().split(" ")]

up = False
down = False
constant = False

for I in range(1,len(n)):
	if n[I] == n[I-1]: #CONSTANT
		if down == True:
			print("NO")
			return
		else:
			constant = True
	elif n[I] > n[I-1]: #UP
		if (constant or down) == True:
			print("NO")
			return
		else:
			up = True
	else:
		down = True
print("YES")

n = int(input())

prev = 0
f = 0

for v in map(int, input().split()):
	if v > prev:
		if f > 0:
			print("NO")
			return
	elif v == prev:
		if f == 2:
			print("NO")
			return
		f = 1
	else:
		f = 2
	prev = v

print("YES")

import sys 

def main():
    n = int(sys.stdin.readline())
    x = list(map(int,sys.stdin.readline().split()))
    i=0
    n+=1
    x = [0] + x + [0]
    while i < n and x[i] < x[i+1]:
        i+=1
    while i < n and x[i] == x[i+1]:
        i+=1
    while i < n and x[i] > x[i+1]:
        i+=1

    if i==n:
        print("YES")
    else:
        print("NO")  

    

main()


n = int(input())
a = list(map(int, input().split()))
f = 0
for i in range(1, n):
	if f == 0 and a[i] == a[i-1]:
		f = 1
	elif f == 0 and a[i] < a[i-1]:
		f = 2
	elif f == 1 and a[i] < a[i-1]:
		f = 2
	elif f == 0 and a[i] > a[i-1] or f == 1 and a[i] == a[i-1] or f == 2 and a[i] < a[i-1]:
		continue
	else:
		f = -1
		break
if f == -1:
	print('NO')
else:
	print('YES')

n = int(input())
m = [int(i) for i in input().split()]
s = 0
f = 0
for j in range(n-1):
    if m[j] < m[j+1]:
        s2 = 0
    elif m[j] == m[j+1]:
        s2 = 1
    else:
        s2 = 2
    if s2 > s:
        s = s2
    elif s2 < s:
        f = 1
if f == 0:
    print('YES')
else:
    print('NO')

n = int(input())
ar = input().split()
cur = 0
count = 0
bo = False
for i in range(n):
    if int(ar[i]) > cur and count == 0:
        cur = int(ar[i])
    elif int(ar[i]) == cur and count <= 1:
        count = 1
    elif int(ar[i]) < cur and count <= 1:
        count = 2
        cur = int(ar[i])
    elif int(ar[i]) < cur and count == 2:
        cur = int(ar[i])
    else:
        bo = True
        break
if bo:
    print('NO')
else:
    print('YES')


n = int(input())
a = list(map(int, input().split()))
i = 0
while i < n - 1 and a[i] < a[i+1]:
    i += 1
if i == n - 1:
    print('YES')
else:
    while i < n - 1 and a[i] == a[i+1]:
        i += 1
    if i == n - 1:
        print('YES')
    else:
        while i < n - 1 and a[i] > a[i+1]:
            i += 1
        if i == n - 1:
            print('YES')
        else:
            print('NO')

import re

input()

a, s = [int(x) for x in input().split()], ''
for i in range(1, len(a)):
    if a[i] > a[i - 1]:
        s += '1'
    elif a[i] == a[i - 1]:
        s += '2'
    else:
        s += '3'

pattern = re.compile('^1*2*3*$')
if pattern.match(s):
    print('YES')
else:
    print('NO')


n = int(input())
a = [int(i) for i in input().split()]
st = 0
ans = "YES"
for i in range(len(a) - 1):
    if a[i] < a[i + 1]:
        if st != 0:
            ans = 'NO'
    elif a[i] == a[i + 1]:
        if st == 0:
            st = 1
        elif st == 2:
            ans = 'NO'
    else:
        st = 2
print(ans)


#!/bin/python3

import sys

n=int(input())
num=list(map(int,input().split()))
i=0
while(i<n-1 and num[i]<num[i+1]):
    i+=1
while(i<n-1 and num[i]==num[i+1]):
    i+=1
while(i<n-1 and num[i]>num[i+1]):
    i+=1
if(i==n-1):
    print("YES")
else:   
    print("NO")



#!/usr/bin/env python3
from sys import stdin, stdout

def rint():
    return list(map(int, stdin.readline().split()))
#lines = stdin.readlines()


n = int(input())
a = list(rint())

if n == 1:
    print("YES")
    return

stage = 0
for i in range(n-1):
    diff = a[i+1] - a[i]
    if stage == 0:
        if diff > 0:
            pass
        elif diff == 0:
            stage = 1
        else:
            stage = 2
    elif stage == 1:
        if diff > 0 :
            print("NO")
            return
        elif diff == 0:
            pass
        else:
            stage = 2
    elif stage == 2:
        if diff > 0 or diff == 0:
            print("NO")
            return
        else:
            pass
print("YES")







n = int(input())

a = list(map(int, input().split()))

i = 0
while i < n - 1 and a[i] < a[i + 1]:
    i += 1

while i < n - 1 and a[i] == a[i + 1]:
    i += 1

while i < n - 1 and a[i] > a[i + 1]:
    i += 1

if i == n - 1:
    print('YES')
else:
    print('NO')


from sys import stdin

n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))

if n == 1:
    print("YES")
    return

up, hor, down = True, True, True

for i in range(1, len(data)):
    if data[i] > data[i - 1]:
        if not up:
            print("NO")
            return
    elif data[i] == data[i - 1]:
        up = False
        if not hor:
            print("NO")
            return
    else:
        up = False
        hor = False
        if not down:
            print("NO")
            return
print("YES")


n = int(input())
s = [int(i) for i in input().split()]
a = 0
for i in range(1, n):
    if a ==0:
        if s[i] <= s[i-1]:
            a =1
    if a == 1:
        if s[i] < s[i-1]:
            a =2
        if s[i] > s[i - 1]:
            a = 3
            break
    if a == 2:
        if s[i] < s[i-1]:
            a =2
        else:
            a = 3
            break
if a != 3:
    print("YES")
else:
    print("NO")

def check(lst):
    b = True
    sost = 0
    for i in range(1, len(a)):
        if lst[i] > lst[i - 1]:
            if sost != 0:
                b = False
                break
            sost = 0
        elif lst[i] == lst[i - 1]:
            if sost == 2:
                b = False
                break
            sost = 1
        else: 
            sost = 2
    return b
n = int(input())
a = list(map(int, input().split()))
if check(a):
    print('YES')
else:
    print('NO')


n = int(input())
A = list(map(int,input().split()))
flag = 0
for i,a in enumerate(A):
	if i == 0:
		continue
	if flag == 0:
		if A[i - 1] < a:
			pass
		elif A[i - 1] == a:
			flag = 1
		else:
			flag = 2
	elif flag == 1:
		if A[i - 1] < a:
			flag = -1
			break
		elif A[i - 1] == a:
			pass
		else:
			flag = 2
	elif flag == 2:
		if A[i - 1] > a:
			pass
		else:
			flag = -1
			break
if flag >= 0:
	print("YES")
else:
	print("NO")