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: EASY

Solutions:
n = int(input())
array = list(map(int, input().split()))
if n == 1:
	print('YES')
if n >= 2:
	begin = 0
	end = len(array) - 1
	while array[begin] < array[begin + 1] if begin < end else False:
		begin += 1
	while array[end] < array[end - 1] and end != begin:
		end -= 1
	test = set()
	for i in range(begin, end + 1):
		test.add(array[i])
	if len(test) == 1 or begin == end:
		print('YES')
	else:
		print('NO')


length = int(input())
nums = list(map(int, input().split(' ')))
asc = True
equal = False
descending = False
correct = True
for (i, n) in enumerate(nums):
	if i == 0:
		continue
	elif asc and nums[i - 1] < n:
		continue
	elif asc and nums[i - 1] == n:
		asc = False
		equal = True
	elif asc and nums[i - 1] > n:
		asc = False
		descending = True
	elif equal and nums[i - 1] == n:
		continue
	elif equal and nums[i - 1] > n:
		equal = False
		descending = True
	elif descending and nums[i - 1] > n:
		continue
	else:
		print('NO')
		correct = False
		break
if correct:
	print('YES')


input()
a = list(map(int, input().split()))
t = 1
k = 1
for i in range(len(a) - 1):
	if a[i] < a[i + 1]:
		if k != 1:
			t = 0
	elif a[i] == a[i + 1]:
		if k == 1:
			k = 2
		elif k == 3:
			t = 0
	else:
		k = 3
print('YES' if t else 'NO')


n = input()
inp = input().split()
mark1 = 0
mark2 = 0
judge = 0
num = int(inp[0])
for i in range(1, int(n)):
	if int(inp[i]) > num:
		num = int(inp[i])
		if mark1 == 1 or mark2 == 1:
			judge = 1
			break
	elif int(inp[i]) == num:
		mark1 = 1
		if mark2 == 1:
			judge = 1
			break
	else:
		num = int(inp[i])
		mark2 = 1
if judge == 0:
	print('YES')
else:
	print('NO')


import sys
fin = sys.stdin
fout = sys.stdout
n = int(fin.readline())
array = list(map(int, fin.readline().split()))
unimodal = True
state = 0
for i in range(1, n):
	if array[i - 1] < array[i]:
		if state == 1 or state == 2:
			unimodal = False
			break
	elif array[i - 1] == array[i]:
		if state == 0 or state == 1:
			state = 1
		else:
			unimodal = False
			break
	else:
		state = 2
if unimodal:
	fout.write('YES')
else:
	fout.write('NO')
fout.close()


input()
mode = 0
first_entry = True
last_num = 0
for x in input().split():
	num = int(x)
	if not first_entry:
		if mode == 0:
			if num < last_num:
				mode = 2
			elif num == last_num:
				mode = 1
		elif mode == 1:
			if num > last_num:
				print('NO')
				exit()
			elif num < last_num:
				mode = 2
		elif num >= last_num:
			print('NO')
			exit()
	else:
		first_entry = False
	last_num = num
print('YES')


def list_input():
	return list(map(int, input().split()))
n = int(input())
a = list_input()
p = n - 1
for i in range(n - 1):
	if a[i] >= a[i + 1]:
		p = i
		break
q = 0
for i in range(n - 1, 0, -1):
	if a[i] >= a[i - 1]:
		q = i
		break
for i in range(p, q + 1):
	if a[i] != a[p]:
		print('NO')
		exit(0)
print('YES')


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


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 = list(map(int, input().split()))
li = []
a = l[0]
c = 1
q = 0
for i in range(1, len(l)):
	if l[i] == a:
		e = i
		q = 1
		break
	elif l[i] < a:
		e = i
		q = 2
		break
	else:
		a = l[i]
		c = c + 1
if c == len(l):
	print('YES')
else:
	li = l[e:]
	if q == 1:
		c = 1
		a = li[0]
		for i in range(1, len(li)):
			if li[i] == a and a == li[0]:
				c = c + 1
			elif li[i] < a:
				c = c + 1
				a = li[i]
			else:
				break
		if c == len(li):
			print('YES')
		else:
			print('NO')
	elif q == 2:
		c = 1
		a = li[0]
		for i in range(1, len(li)):
			if li[i] < a:
				c = c + 1
				a = li[i]
			else:
				break
		if c == len(li):
			print('YES')
		else:
			print('NO')


def unimodal(a):
	i = a.index(max(a))
	incr = a[:i]
	decr = a[i:]
	m = 0
	while m < len(decr) and decr[m] == max(a):
		m += 1
	const = decr[:m]
	decr = decr[m:]
	for n in range(len(incr) - 1):
		if incr[n] >= incr[n + 1]:
			return 'NO'
	for n in range(len(decr) - 1):
		if decr[n] <= decr[n + 1]:
			return 'NO'
	return 'YES'
size = input()
a = input()
b = a.split()
print(unimodal(list(map(int, b))))


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


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


(a, lst) = (int(input()), input().split())
lst = [int(ch) for ch in lst]

def is_modal(a, lst):
	i = 1
	for i in range(i, a):
		if not lst[i - 1] < lst[i]:
			break
	else:
		return 'YES'
	for i in range(i, a):
		if not lst[i - 1] == lst[i]:
			break
	else:
		return 'YES'
	for i in range(i, a):
		if not lst[i - 1] > lst[i]:
			return 'NO'
	else:
		return 'YES'
print(is_modal(a, lst))


n = int(input())
arr = list(map(int, input().split()))
ans = 0
inc = 0
i = 0
while ans == 0 and i + 1 < len(arr):
	if arr[i] == arr[i + 1]:
		const = arr[i]
		arr = arr[i + 2:]
		while len(arr) > 1 and arr[0] == const:
			arr.remove(const)
		arr = [const] + arr
		dec = arr.copy()
		dec.sort(reverse=True)
		ans = 1
		if arr == dec:
			x = set(arr)
			if len(x) == len(arr) or arr[0] == arr[1]:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
		break
	elif arr[i] > arr[i + 1]:
		ans = 1
		arr = arr[i + 1:]
		dec = arr.copy()
		dec.sort(reverse=True)
		if arr == dec:
			x = set(arr)
			if len(x) == len(arr):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
		break
	i = i + 1
if ans == 0:
	x = arr.copy()
	x.sort()
	if len(arr) == 1 or x == arr:
		print('YES')
	else:
		print('NO')


n = int(input())
l = [int(i) for i in input().split()]
if n == 1:
	print('YES')
else:
	inc = False
	const = False
	dec = False
	i = 1
	while i < n and l[i] > l[i - 1]:
		i += 1
	while i < n and l[i] == l[i - 1]:
		i += 1
	while i < n and l[i] < l[i - 1]:
		i += 1
	if i == n:
		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())
arr = list(map(int, input().split()))
bl = 0
for i in range(1, n):
	j = i - 1
	if arr[j] < arr[i]:
		tp = 0
	elif arr[j] == arr[i]:
		tp = 1
	else:
		tp = 2
	if tp < bl:
		print('NO')
		break
	bl = tp
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
	print('YES')
	quit()
else:
	c = 0
	for x in range(n):
		if a[x] > c:
			c = a[x]
		else:
			break
	while x < n and a[x] == c:
		x += 1
	while x < n:
		if a[x] < c:
			c = a[x]
			x += 1
		else:
			print('NO')
			quit()
print('YES')


def main():
	read = lambda : tuple(map(int, input().split()))
	n = read()[0]
	l = read()
	if len(l) == 1:
		return 'YES'
	lv = l[0]
	ss = []
	for v in l[1:]:
		state = 'inc' if v > lv else 'dec' if v < lv else 'norm'
		if len(ss) == 0:
			if state == 'dec':
				ss += ['norm']
			ss += [state]
		elif ss[-1] != state:
			if ss[-1] == 'inc' and state == 'dec':
				ss += ['norm']
			ss += [state]
		lv = v
	for state in ('inc', 'dec', 'norm'):
		if ss.count(state) > 1:
			return 'NO'
	if len(ss) == 1:
		return 'YES'
	if len(ss) == 2:
		return 'YES' if ss == ['norm', 'dec'] or ss == ['inc', 'norm'] else 'NO'
	return 'YES' if ss == ['inc', 'norm', 'dec'] else 'NO'
print(main())


def p8(arr):
	a = 0
	for i in range(0, len(arr) - 1):
		if arr[i] < arr[i + 1] and a == 0:
			a = 0
		elif arr[i] == arr[i + 1] and (a == 0 or a == 1):
			a = 1
		elif arr[i] > arr[i + 1]:
			a = 2
		else:
			return 'NO'
	return 'YES'
input()
print(p8([int(x) for x in input().split()]))


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
	if a[i] == a[i + 1]:
		b.append(0)
	if a[i] < a[i + 1]:
		b.append(1)
	if a[i] > a[i + 1]:
		b.append(-1)
if b == sorted(b, reverse=True):
	print('YES')
else:
	print('NO')


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')


n = int(input())
flag = 0
flag_prev = 0
result = 'YES'
string = str(input()).split(' ')
first = int(string[0])
for c in string[1:]:
	intc = int(c)
	if first < intc:
		flag = 1
	if first == intc:
		flag = 2
	if first > intc:
		flag = 3
	if flag < flag_prev:
		result = 'NO'
		break
	flag_prev = flag
	first = intc
print(result)


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


n = int(input())
t = list(map(int, input().split()))
if len(set(t)) == 1:
	print('YES')
elif t == sorted(t) and len(set(t)) == n:
	print('YES')
elif t == sorted(t)[::-1] and len(set(t)) == n:
	print('YES')
else:
	u = max(t)
	x = t.index(u)
	h = 0
	for j in range(1, x):
		if t[j] > t[j - 1]:
			pass
		else:
			print('NO')
			h += 1
			break
	if h == 0:
		for y in range(x + t.count(u), n):
			if t[y] < t[y - 1]:
				pass
			else:
				print('NO')
				h += 1
				break
		if h == 0:
			print('YES')


size = int(input())
array = list(map(int, input().split()))
index = 0
value = 0
while index < size and array[index] > value:
	value = array[index]
	index += 1
while index < size and array[index] == value:
	index += 1
while index < size and array[index] < value:
	value = array[index]
	index += 1
print('YES' if index == size else 'NO')


n = int(input())
a = list(map(int, input().split()))
p = 0
while p < n:
	if p + 1 >= n or a[p + 1] <= a[p]:
		break
	p += 1
q = n - 1
while q >= 0:
	if q - 1 < 0 or a[q - 1] <= a[q]:
		break
	q -= 1
while p < q:
	if a[p] != a[p + 1]:
		print('NO')
		exit()
	p += 1
print('YES')


n = input()
my_array = [int(k) for k in input().split(' ')]

def check_increasing(lis):
	for l in range(1, len(lis)):
		if lis[l] <= lis[l - 1]:
			return False
	return True

def check_decreasing(lis):
	for i in range(1, len(lis)):
		if lis[i] >= lis[i - 1]:
			return False
	return True

def get_indices(lis):
	element = None
	final = []
	for i in range(1, len(lis)):
		if lis[i] <= lis[i - 1]:
			element = lis[i - 1]
			final.append(i - 1)
			break
	if len(final) > 0:
		for l in range(final[0] + 1, len(lis)):
			if lis[l] != element:
				final.append(l - 1)
				break
		if len(final) == 1:
			final.append(-1)
	else:
		final = [-1, -1]
	return final

def solve():
	indices = get_indices(my_array)
	i = my_array[:indices[0]]
	d = my_array[indices[1]:]
	if check_increasing(i) and check_decreasing(d):
		print('YES')
		return
	else:
		print('NO')
		return
solve()


n = int(input())
a = list(input().split(' '))
a = [int(i) for i in a]
b = max(a)
c = []
s = 1
for i in range(0, n):
	if a[i] == b:
		c.append(i)
ma = max(c)
mi = min(c)
if ma - mi + 1 != len(c):
	s = 0
for i in range(1, mi + 1):
	if a[i] <= a[i - 1]:
		s = 0
		break
for i in range(ma + 1, n):
	if a[i] >= a[i - 1]:
		s = 0
		break
if s == 0:
	print('NO')
else:
	print('YES')


while True:
	try:
		n = int(input())
		a = input().split()
		for i in range(0, len(a)):
			a[i] = int(a[i])
		l = 0
		r = n - 1
		flag = 0
		if n == 1:
			print('YES')
			continue
		while a[l] < a[l + 1]:
			l += 1
			if l == len(a) - 1:
				break
		while a[r] < a[r - 1]:
			r -= 1
			if r == 0:
				break
		while l < r:
			if a[l] != a[l + 1]:
				print('NO')
				flag = 1
				break
			l += 1
		if flag == 0:
			print('YES')
	except EOFError:
		break


input()
pastUp = False
pastLevel = False
last = 0
for n in map(int, input().split()):
	if n < last:
		pastUp = True
		pastLevel = True
	elif n == last:
		if pastLevel:
			print('NO')
			break
		pastUp = True
	elif n > last:
		if pastUp or pastLevel:
			print('NO')
			break
	last = n
else:
	print('YES')


n = int(input())
a = [int(i) for i in input().split()]
k = True
top = a[0]
stage = 0
for i in range(1, len(a)):
	if a[i] > top:
		if stage == 2 or stage == 3:
			k = False
			break
		stage = 1
		top = a[i]
	elif a[i] == top:
		if stage == 3:
			k = False
			break
		stage = 2
	else:
		stage = 3
		top = a[i]
if k:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
inc = False
const = False
dec = False
for i in range(n - 1):
	if a[i] < a[i + 1]:
		if dec or const:
			print('NO')
			exit()
		else:
			inc = True
	elif a[i] > a[i + 1]:
		dec = True
	elif a[i] == a[i + 1]:
		if dec:
			print('NO')
			exit()
		else:
			const = True
print('YES')


n = int(input())
l = list(map(int, input().split(' ')))
pos1 = 0
pos2 = n - 1
while pos1 < n - 1 and l[pos1 + 1] > l[pos1]:
	pos1 += 1
while pos2 > 0 and l[pos2 - 1] > l[pos2]:
	pos2 -= 1
x = l[pos2]
ans = 'YES'
for i in range(pos1, pos2):
	if l[i] != x:
		ans = 'NO'
		break
print(ans)


n = input()
m = input()
m = m.split()
m = list(map(int, m))
a = 1
flag = True
while a < len(m):
	if m[a] > m[a - 1]:
		a += 1
		continue
	else:
		break
while a < len(m):
	if m[a] == m[a - 1]:
		a += 1
		continue
	else:
		break
while a < len(m):
	if m[a] < m[a - 1]:
		a += 1
		continue
	else:
		print('NO')
		flag = False
		a += 1
		break
if flag:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
pn = 0
f = 0
for i in l:
	if i > pn:
		if f > 0:
			exit(print('NO'))
	elif i == pn:
		if f > 1:
			exit(print('NO'))
		f = 1
	else:
		f = 2
	pn = i
print('YES')


a = int(input())
b = list(map(int, input().split()))
for i in range(a - 2):
	if b[i + 1] == b[i]:
		if b[i + 2] > b[i + 1]:
			print('NO')
			exit()
	elif b[i + 1] < b[i]:
		if b[i + 2] >= b[i + 1]:
			print('NO')
			exit()
print('YES')


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


n = int(input())
l = list(map(int, input().strip().split()))
i = 1
while i < n:
	if l[i] <= l[i - 1]:
		break
	else:
		i = i + 1
while i < n:
	if l[i] != l[i - 1]:
		break
	else:
		i = i + 1
while i < n:
	if l[i] >= l[i - 1]:
		break
	else:
		i = i + 1
if i == n:
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(x) for x in input().split()]
wasc = wcon = wdes = False
uni = True
for x in range(1, n):
	if a[x] > a[x - 1]:
		wasc = True
		if wdes or wcon:
			uni = False
			break
		continue
	elif a[x] == a[x - 1]:
		wcon = True
		if wdes:
			uni = False
			break
		continue
	elif a[x] < a[x - 1]:
		wdes = True
		continue
if uni:
	print('YES')
else:
	print('NO')


n = int(input())
x = [int(q) for q in input().split()]
l = []
for i in range(len(x) - 1):
	if x[i] == x[i + 1]:
		l.append(1)
	elif x[i] < x[i + 1]:
		l.append(0)
	elif x[i] > x[i + 1]:
		l.append(2)
if l == sorted(l):
	print('YES')
else:
	print('NO')


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


n = int(input())
t = [int(s_temp) for s_temp in input().strip().split(' ')]
block = 0
flag = 0
if len(t) == 1:
	print('YES')
	exit()
for i in range(0, len(t) - 1):
	if t[i] < t[i + 1]:
		block = 0
	elif t[i] == t[i + 1]:
		block = 1
	else:
		block = 2
	if flag > block:
		flag = -1
		break
	else:
		flag = block
if flag == -1:
	print('NO')
else:
	print('YES')


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


n = int(input())
l = list(map(int, input().split()))
left = 0
right = n - 1
for i in range(0, n - 1):
	if l[i] < l[i + 1]:
		left += 1
	else:
		break
for i in range(n - 1, 0, -1):
	if l[i] < l[i - 1]:
		right -= 1
	else:
		break
for i in range(left, right):
	if l[i] != l[i + 1]:
		exit(print('NO'))
print('YES')


n = int(input())
arr = list(map(int, input().split()))
diff = []
for i in range(1, n):
	if arr[i] - arr[i - 1] > 0:
		diff.append(1)
	elif arr[i] - arr[i - 1] == 0:
		diff.append(0)
	else:
		diff.append(-1)
op = diff[:]
diff.sort(reverse=True)
if op == diff:
	print('YES')
else:
	print('NO')


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()


a = int(input())
b = list(map(int, input().split()))
k = 0
for i in range(1, a):
	if b[i] > b[i - 1]:
		if k <= 1:
			k = 1
		else:
			exit(print('NO'))
	elif b[i] == b[i - 1]:
		if k <= 2:
			k = 2
		else:
			exit(print('NO'))
	elif k <= 3:
		k = 3
	else:
		exit(print('NO'))
print('YES')


import sys
n = int(input())
data = [int(x) for x in input().split()]
if len(data) > 1:
	flgVV = data[0] < data[1]
	flgVn = data[-2] > data[-1]
	if flgVV:
		i = 0
		while i < len(data) - 1 and data[i] < data[i + 1]:
			i += 1
		if i == len(data) - 1:
			print('YES')
			sys.exit()
		while i < len(data) - 1 and data[i] == data[i + 1]:
			i += 1
		if i == len(data) - 1 and (not flgVn):
			print('YES')
			sys.exit()
		while flgVn and i < len(data) - 1 and (data[i] > data[i + 1]):
			i += 1
		if i < len(data) - 1:
			print('NO')
			sys.exit()
		print('YES')
	else:
		i = 0
		while i < len(data) - 1 and data[i] == data[i + 1]:
			i += 1
		if i == len(data) - 1 and (not flgVn):
			print('YES')
			sys.exit()
		while flgVn and i < len(data) - 1 and (data[i] > data[i + 1]):
			i += 1
		if i < len(data) - 1:
			print('NO')
			sys.exit()
		print('YES')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split(' ')))
l1 = 0
l2 = n - 1
while l1 < n - 1 and a[l1 + 1] > a[l1]:
	l1 += 1
while l2 > 0 and a[l2 - 1] > a[l2]:
	l2 -= 1
x = a[l2]
ans = 'YES'
for i in range(l1, l2):
	if a[i] != x:
		ans = 'NO'
		break
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
dfx = list(map(int, input().split()))
index = [0, n - 1]
for i in range(n - 1):
	if dfx[i + 1] > dfx[i]:
		index[0] = i + 1
	else:
		break
for i in range(n - 1, -1, -1):
	if dfx[i - 1] > dfx[i]:
		index[1] = i - 1
	else:
		break
print('YES' if len(set(dfx[index[0]:index[1] + 1])) == 1 else 'NO')


n = int(input())
a = list(map(int, input().split()))
assert len(a) == n
b = 1
const_num = max(a)
const_index = a.index(const_num)
const_count = a.count(const_num)
for i in range(0, const_index):
	if a[i] >= a[i + 1]:
		b = 0
for i in range(const_index, const_index + const_count):
	if a[i] != const_num:
		b = 0
for i in range(const_index + const_count, len(a) - 1):
	if a[i] <= a[i + 1]:
		b = 0
if b == 0:
	print('NO')
elif b == 1:
	print('YES')


a = input()
b = list(map(int, input().split(' ')))
m = max(b)
n = 0
flag = 1
res = 1
for i in b:
	if flag == 1:
		if i > n:
			n = i
		elif i <= n:
			flag = -1
			n = i
	elif flag == -1:
		if n <= i and n != m:
			res = 0
		elif n > i:
			n = i
if res == 0:
	print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
m = max(a)
mi = a.index(m)
y = True
p = mi
i = mi - 1
while i >= 0 and y:
	if a[p] <= a[i]:
		y = False
	p = i
	i -= 1
while mi < n and m == a[mi]:
	mi += 1
p = mi - 1
i = mi
while i < n and y:
	if a[p] <= a[i]:
		y = False
	p = i
	i += 1
print('YES' if y else 'NO')


n = int(input())
arr = [int(x) for x in input().split()]
out = True
stage = 1
for i in range(len(arr) - 1):
	if stage == 1:
		if arr[i] > arr[i + 1]:
			stage = 3
		elif arr[i] == arr[i + 1]:
			stage = 2
	elif stage == 2:
		if arr[i] > arr[i + 1]:
			stage = 3
		elif arr[i] < arr[i + 1]:
			out = False
			break
	elif stage == 3:
		if arr[i] == arr[i + 1]:
			out = False
			break
		elif arr[i] < arr[i + 1]:
			out = False
			break
print('YES' if out else 'NO')


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


x = int(input())
y = input().split()
nope = False
lmax = -1
fmax = -1
fmaxpos = -1
lmaxpos = -1
funi = True
Luni = True
for i in range(x):
	if int(y[i]) > fmax:
		fmax = int(y[i])
		fmaxpos = i
	if int(y[i]) >= lmax:
		lmax = int(y[i])
		lmaxpos = i
for i in range(0, fmaxpos):
	funi = False
	if int(y[i]) < int(y[i + 1]):
		funi = True
	else:
		break
for i in range(lmaxpos, x - 1):
	Luni = False
	if int(y[i]) > int(y[i + 1]):
		Luni = True
	else:
		break
for i in range(fmaxpos, lmaxpos):
	if int(y[i]) != int(y[i + 1]):
		nope = True
		break
if x == 1 or x == 2:
	print('YES')
elif nope == True:
	print('NO')
elif funi and Luni:
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
a = []
b = []
a = s.split()
for i in range(len(a)):
	a[i] = int(a[i])
a.append(0)
i = 0
while i < len(a):
	if a[i] < a[i + 1]:
		b.append(a[i])
		i += 1
	else:
		break
while i < len(a):
	if a[i] == a[i + 1]:
		b.append(a[i])
		i += 1
	else:
		break
while i < len(a) - 1:
	if a[i] > a[i + 1]:
		b.append(a[i])
		i += 1
	else:
		break
if len(b) == len(a) - 1:
	print('YES')
else:
	print('NO')


n = int(input())
dfx = list(map(int, input().split()))
index = [0, n - 1]
for i in range(n - 1):
	if dfx[i + 1] > dfx[i]:
		index[0] = i + 1
	else:
		break
for i in range(n - 1, -1, -1):
	if dfx[i - 1] > dfx[i]:
		index[1] = i - 1
	else:
		break
print('YES' if len(set(dfx[index[0]:index[1] + 1])) == 1 else 'NO')


arr_size = int(input())
arr = list(map(int, input().split()))
b = [0]
result = True
for i in range(1, arr_size):
	if arr[i - 1] < arr[i]:
		b.append(0)
	elif arr[i - 1] == arr[i]:
		b.append(1)
	else:
		b.append(2)
	if b[i - 1] > b[i]:
		result = False
		break
if result:
	print('YES')
else:
	print('NO')


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


n = int(input())
sl = list(map(int, input().split()))
b = 0
c = 0
d = 0
i = 0
j = 0
for i in range(1, n):
	if sl[i] > sl[i - 1]:
		if b == 1 or c == 1:
			print('NO')
			exit()
		d = 1
	if sl[i] == sl[i - 1]:
		if b == 1:
			print('NO')
			exit()
		c = 1
	if sl[i] < sl[i - 1]:
		b = 1
print('YES')
exit()


def unimodal_new(mylist):
	if len(mylist) == 1:
		return 'YES'
	i = 0
	while mylist[i] < mylist[i + 1] and i < len(mylist) - 2:
		i += 1
	if i == len(mylist) - 2:
		return 'YES'
	while mylist[i] == mylist[i + 1] and i < len(mylist) - 2:
		i += 1
	if i == len(mylist) - 2 and mylist[i] == mylist[i + 1]:
		return 'YES'
	for j in range(i, len(mylist) - 1):
		if mylist[j] <= mylist[j + 1]:
			return 'NO'
	return 'YES'
n = int(input())
arrlist = [int(x) for x in input().split()]
print(unimodal_new(arrlist))


(num, arr) = (int(input()), input().split())
arr = [int(x) for x in arr]

def problem8(num, arr):
	i = 1
	for i in range(i, num):
		if not arr[i - 1] < arr[i]:
			break
	else:
		return 'YES'
	for i in range(i, num):
		if not arr[i - 1] == arr[i]:
			break
	else:
		return 'YES'
	for i in range(i, num):
		if not arr[i - 1] > arr[i]:
			return 'NO'
	else:
		return 'YES'
print(problem8(num, arr))


l = ['C', 'I', 'D', 'IC', 'CD', 'ID', 'ICD']
m = int(input())
a = [int(i) for i in input().split()]
e = ''
if m == 1:
	print('YES')
else:
	for i in range(1, len(a)):
		if a[i] - a[i - 1] == 0:
			if len(e) == 0:
				e = e + 'C'
			elif e[-1] != 'C':
				e = e + 'C'
		elif a[i] - a[i - 1] > 0:
			if len(e) == 0:
				e = e + 'I'
			elif e[-1] != 'I':
				e = e + 'I'
		elif a[i] - a[i - 1] < 0:
			if len(e) == 0:
				e = e + 'D'
			elif e[-1] != 'D':
				e = e + 'D'
	if e in l:
		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')


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)


n = int(input())
aStr = input().split()
a = []
for v in aStr:
	a.append(int(v))
p1 = 1
p2 = len(a)
while p1 < p2 and a[p1 - 1] < a[p1]:
	p1 += 1
while p1 < p2 and a[p1 - 1] == a[p1]:
	p1 += 1
while p1 < p2 and a[p1 - 1] > a[p1]:
	p1 += 1
if p1 == p2:
	print('YES')
else:
	print('NO')


def find(A):
	s = ''
	for i in range(len(A) - 1):
		if A[i] < A[i + 1]:
			s += 'i'
		elif A[i] == A[i + 1]:
			s += 'c'
		else:
			s += 'd'
	s = s.lstrip('i')
	s = s.rstrip('d')
	s = s.strip('c')
	if s == '':
		return 1
	else:
		return 0
N = input()
A = list(map(int, input().strip().split(' ')))
if find(A) == 1:
	print('YES')
else:
	print('NO')


(a, lst) = (int(input()), input().split())
lst = [int(ch) for ch in lst]

def f(m, n, flag):
	if flag == 1:
		return m < n
	elif flag == 2:
		return m == n
	else:
		return m > n

def is_modal(a, lst):
	flag = 1
	for i in range(1, a):
		if f(lst[i - 1], lst[i], flag):
			continue
		else:
			if flag == 3:
				return 'NO'
			flag += 1
			if f(lst[i - 1], lst[i], flag):
				continue
			else:
				if flag == 3:
					return 'NO'
				flag += 1
				if f(lst[i - 1], lst[i], flag):
					continue
				else:
					return 'NO'
	return 'YES'
print(is_modal(a, lst))


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

def no():
	print('NO')
	exit()
phase = 0
for i in range(n - 1):
	if phase == 0:
		if L[i] < L[i + 1]:
			continue
		if L[i] > L[i + 1]:
			phase = 2
			continue
		phase += 1
	elif phase == 1:
		if L[i] < L[i + 1]:
			no()
		if L[i] == L[i + 1]:
			continue
		phase += 1
	elif phase == 2:
		if L[i] > L[i + 1]:
			continue
		no()
print('YES')


def int_map():
	return map(int, input().split(' '))
n = int(input())
if n == 1:
	print('YES')
	exit()
(v, r, u) = (False, False, False)
a = list(int_map())
a.append(0)
i = 0
while a[i] < a[i + 1] and i < n - 1:
	i += 1
while a[i] == a[i + 1] and i < n - 1:
	i += 1
while a[i] > a[i + 1] and i < n - 1:
	i += 1
if i == n - 1:
	print('YES')
else:
	print('NO')


def list_input():
	return list(map(int, input().split()))

def map_input():
	return map(int, input().split())

def map_string():
	return input().split()
n = int(input())
a = list_input()
a1 = []
for i in range(1, n):
	if a[i - 1] < a[i]:
		a1.append(1)
	elif a[i - 1] > a[i]:
		a1.append(3)
	else:
		a1.append(2)
if sorted(a1) == a1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
unimodal = True
increasing = True
constant = False
decreasing = False
i = 1
number = a[0]
while i < n and unimodal == True:
	if i < n and a[i] > number and (increasing == True):
		number = a[i]
		i += 1
	elif i < n and a[i] == number and (increasing == True):
		increasing = False
		constant = True
		number = a[i]
		i += 1
	elif i < n and a[i] < number and (increasing == True):
		increasing = False
		decreasing = True
		number = a[i]
		i += 1
	if i < n and a[i] == number and (constant == True):
		number = a[i]
		i += 1
	elif i < n and a[i] < number and (constant == True):
		decreasing = True
		constant = False
		number = a[i]
		i += 1
	elif i < n and a[i] > number and (constant == True):
		unimodal = False
	if i < n and a[i] < number and (decreasing == True):
		number = a[i]
		i += 1
	elif i < n and (a[i] > number or a[i] == number) and (decreasing == True):
		unimodal = False
if unimodal:
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(x) for x in input().split()]
themax = max(a)
for i in range(n):
	if a[i] == themax:
		maxindex = i
		break
low = maxindex
while low > 0 and a[low - 1] == a[low]:
	low -= 1
high = maxindex
while high < n - 1 and a[high + 1] == a[high]:
	high += 1
answer = 'YES'
testleft = low
while testleft > 0:
	if a[testleft - 1] >= a[testleft]:
		answer = 'NO'
		break
	else:
		testleft -= 1
testright = high
while testright < n - 1:
	if a[testright + 1] >= a[testright]:
		answer = 'NO'
		break
	else:
		testright += 1
print(answer)


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())
arr = list(map(int, input().split()))
part = 0
if n == 1:
	print('YES')
	exit(0)
for i in range(n - 1):
	if arr[i] == arr[i + 1]:
		if part == 2:
			print('NO')
			exit(0)
		part = 1
	elif arr[i] < arr[i + 1]:
		if part:
			print('NO')
			exit(0)
		part = 0
	else:
		part = 2
print('YES')


import math
n = int(input())
a = list(map(int, input().strip().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:
	if a[i] <= a[i + 1]:
		print('NO')
		exit(0)
	i += 1
print('YES')


def get(l):
	z = l[0]
	flag = 0
	for i in l[1:]:
		if i - z > 0 and flag == 0:
			flag = 0
		elif i - z == 0 and flag <= 1:
			flag = 1
		elif i - z < 0 and flag <= 2:
			flag = 2
		else:
			return 'NO'
		z = i
	return 'YES'
_ = input()
l = list(map(int, input().split()))
print(get(l))


import sys

def is_unimodal(arr):
	if len(arr) == 0:
		return False
	if len(arr) == 1:
		return True
	(increasing, constant, decreasing) = (True, False, False)
	for (curr, prev) in zip(arr[1:], arr[:-1]):
		if curr > prev:
			if not increasing:
				return False
		elif curr == prev:
			if increasing or constant:
				(increasing, constant) = (False, True)
			else:
				return False
		elif increasing or constant:
			(increasing, constant, decreasing) = (False, False, True)
	return True
N = int(sys.stdin.readline())
arr = [int(x) for x in sys.stdin.readline().split()]
if is_unimodal(arr):
	print('YES')
else:
	print('NO')


import sys
nu = input()
m = [int(i) for i in input().split()]
if len(m) == 1:
	print('YES')
	sys.exit()
prev_ind = 1
prev = m[0]
ind = lambda x, y: int((y - x) / abs(y - x)) if y != x else 0
for i in m[1:]:
	if ind(prev, i) <= prev_ind:
		prev_ind = ind(prev, i)
		prev = i
	else:
		print('NO')
		sys.exit()
print('YES')


import sys
n = int(sys.stdin.readline())
array = [int(i) for i in sys.stdin.readline().split()]
state = 0
good = True
last = array[0]
for i in array[1:]:
	if last < i:
		if state > 0:
			good = False
			break
	elif last == i:
		if state > 1:
			good = False
			break
		state = 1
	else:
		state = 2
	last = i
if good:
	print('YES')
else:
	print('NO')


def is_sorted(l):
	return all((a < b for (a, b) in zip(l[:-1], l[1:])))
n = int(input())
arr = input().split()
arr = list(map(int, arr))
arr = arr[:n]
j = 1
ind1 = 0
ind2 = 0
flag = False
for i in range(1, n):
	if arr[i] == arr[j - 1]:
		ind1 = j - 1
		ind2 = i
		j -= 1
		flag = True
		break
	j += 1
for i in range(ind1 + 1, n):
	if arr[ind1] == arr[i]:
		ind2 = i
	else:
		break
if not flag:
	ind1 = arr.index(max(arr))
	ind2 = arr.index(max(arr))
arrIn = arr[:ind1 + 1]
arrDe = arr[ind2:]
arrDe.reverse()
flag = is_sorted(arrIn) and is_sorted(arrDe)
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(i) for i in input().split()]
lasti = a[0]
dd = 0
for i in range(1, n):
	cur = a[i]
	if cur == lasti:
		if dd == 2:
			dd = 5
			break
		dd = 1
	elif cur < lasti:
		dd = 2
	elif cur > lasti and dd:
		dd = 5
		break
	lasti = cur
if dd != 5 or n == 1:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
n = int(input())
a = list(rint())
if n == 1:
	print('YES')
	exit()
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')
			exit()
		elif diff == 0:
			pass
		else:
			stage = 2
	elif stage == 2:
		if diff > 0 or diff == 0:
			print('NO')
			exit()
		else:
			pass
print('YES')


I = lambda : list(map(int, input().split()))

def sign(x):
	if x == 0:
		return 0
	return x // abs(x)
n = int(input())
a = I()
d = [sign(i - j) for (i, j) in zip(a[1:], a[:-1])]
md = 2
for i in d:
	if i <= md:
		md = i
	else:
		md = -2
print('NO' if md == -2 else 'YES')


n = int(input())
x = list(map(int, input().split()))
flag = 0
if len(set(x)) == 1:
	print('YES')
else:
	for i in range(1, n):
		if flag == 0:
			if x[i] < x[i - 1]:
				flag = 1
			elif x[i] == x[i - 1]:
				flag = 2
		elif flag == 1:
			if x[i] >= x[i - 1]:
				print('NO')
				break
		elif flag == 2:
			if x[i] > x[i - 1]:
				print('NO')
				break
			elif x[i] < x[i - 1]:
				flag = 1
		if i == n - 1:
			print('YES')


def check_unimodal_array(arr, n):
	ind = 0
	while ind + 1 < n and int(arr[ind + 1]) > int(arr[ind]):
		ind += 1
	while ind + 1 < n and int(arr[ind + 1]) == int(arr[ind]):
		ind += 1
	for x in range(ind, n - 1):
		if int(arr[x + 1]) >= int(arr[x]):
			return 'NO'
	return 'YES'
n = int(input())
arr = input().split()
print(check_unimodal_array(arr, n))


import sys

def f(n, x):
	if n == 1:
		return 'YES'
	ans = 'YES'
	phase = 1
	for (i, v) in enumerate(x):
		if i == 0:
			continue
		if phase == 1:
			if v <= x[i - 1]:
				phase = 2
				if v < x[i - 1]:
					phase = 3
		elif phase == 2:
			if v != x[i - 1]:
				phase = 3
				if v > x[i - 1]:
					return 'NO'
		elif phase == 3:
			if v >= x[i - 1]:
				return 'NO'
	return ans
for line in sys.stdin:
	n = int(line)
	x = [int(a) for a in sys.stdin.readline().split()]
	ans = f(n, x)
	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]:
		if down == True:
			print('NO')
			return
		else:
			constant = True
	elif n[I] > n[I - 1]:
		if (constant or down) == True:
			print('NO')
			return
		else:
			up = True
	else:
		down = True
print('YES')


countOfElement = int(input())
sNumbers = str(input())
res = 0
index = 0
arrNumbers = [int(i) for i in sNumbers.split(' ')]
while index < countOfElement - 1:
	if arrNumbers[index] < arrNumbers[index + 1]:
		res += 1
	else:
		break
	index += 1
while index < countOfElement - 1:
	if arrNumbers[index] == arrNumbers[index + 1]:
		res += 1
	else:
		break
	index += 1
while index < countOfElement - 1:
	if arrNumbers[index] > arrNumbers[index + 1]:
		res += 1
	else:
		break
	index += 1
if res == countOfElement - 1:
	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 = int(input())
l = list(map(int, input().split()))
l.append(0)
d = []
for i in range(n):
	if l[i] < l[i + 1]:
		d.append(l[i])
	else:
		break
for j in range(i, n):
	if l[j] == l[j + 1]:
		d.append(l[j])
	else:
		break
for k in range(j, n):
	if l[k] > l[k + 1]:
		d.append(l[k])
	else:
		break
if d == l[:n]:
	print('YES')
else:
	print('NO')


import sys
n = int(input())
arr = [int(i) for i in input().split()]
i = 0
while i < n - 1 and arr[i] < arr[i + 1]:
	i += 1
if i == n - 1:
	print('YES')
	sys.exit(0)
else:
	while i < n - 1 and arr[i] == arr[i + 1]:
		i += 1
	if i == n - 1:
		print('YES')
		sys.exit(0)
	else:
		while i < n - 1 and arr[i] > arr[i + 1]:
			i += 1
		if i == n - 1:
			print('YES')
			sys.exit(0)
print('NO')


def unimodal(lst):
	if len(lst) == 1:
		return 'YES'
	i = 0
	while i + 1 < len(lst) and lst[i] < lst[i + 1]:
		i += 1
	while i + 1 < len(lst) and lst[i] == lst[i + 1]:
		i += 1
	while i + 1 < len(lst) and lst[i] > lst[i + 1]:
		i += 1
	if i + 1 != len(lst):
		return 'NO'
	return 'YES'
n = int(input())
a = [int(j) for j in input().split()]
print(unimodal(a))


a = int(input())
l = list(map(int, input().split()))
q = 0
(x, y, z) = (1, 1, 1)
for i in l:
	if i > q:
		if x == 0:
			z = 0
			print('NO')
			break
	elif i == q:
		x = 0
		if y == 0:
			z = 0
			print('NO')
			break
	else:
		(x, y) = (0, 0)
	q = i
if z == 1:
	print('YES')


n = int(input())
data = list(map(int, input().split()))
m = max(data)
state = 0
last = None
for v in data:
	if v == m:
		if state < 3:
			state = 2
		else:
			print('NO')
			break
	elif state == 0:
		state = 1
	elif state == 1:
		if v <= last:
			print('NO')
			break
	else:
		state = 3
		if v >= last:
			print('NO')
			break
	last = v
else:
	print('YES')


n = int(input())
bool = True
m = [int(i) for i in input().split()]
k = 0
for i in range(0, n - 1):
	if m[i] < m[i + 1]:
		bool = True
		k += 1
	elif not m[i] >= m[i + 1]:
		bool = False
		break
	else:
		break
m = m[k:]
k = 0
if bool:
	for i in range(0, len(m) - 1):
		if m[i] == m[i + 1]:
			bool = True
			k += 1
		elif not len(m) >= i + 1:
			bool = False
		else:
			break
m = m[k:]
k = 0
if bool:
	for i in range(0, len(m) - 1):
		if not m[i] > m[i + 1]:
			bool = False
if bool:
	print('YES')
else:
	print('NO')


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')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = LI()
	m = max(a)
	mi = a.index(m)
	ma = mi
	while ma < n - 1 and a[ma + 1] == m:
		ma += 1
	for i in range(mi - 1, -1, -1):
		if a[i] >= a[i + 1]:
			return 'NO'
	for i in range(ma + 1, n):
		if a[i] >= a[i - 1]:
			return 'NO'
	return 'YES'
print(main())


import sys
n = int(input())
arr = list(map(int, input().split()))
s = ''
pre = arr[0]
for i in range(1, n):
	if pre < arr[i]:
		if len(s) == 0 or (len(s) > 0 and s[-1] != 'i'):
			s += 'i'
	elif pre == arr[i]:
		if len(s) == 0 or (len(s) > 0 and s[-1] != 'c'):
			s += 'c'
	elif pre > arr[i]:
		if len(s) == 0 or (len(s) > 0 and s[-1] != 'd'):
			s += 'd'
	pre = arr[i]
if n == 1 or s == 'icd' or s == 'c' or (s == 'i') or (s == 'd') or (s == 'ic') or (s == 'cd') or (s == 'id'):
	print('YES')
else:
	print('NO')


n = int(input())
daf = list(map(int, input().split()))
daf2 = daf[::-1]
if n == 1:
	print('YES')
else:
	for i in range(n - 1):
		if daf[i] >= daf[i + 1]:
			break
	else:
		i == n - 1
	for j in range(n - 1):
		if daf2[j] >= daf2[j + 1]:
			break
	else:
		j == n - 1
	daf3 = daf[i:n - j]
	if i == 0 and j == n - 2 or (j == 0 and i == n - 2):
		print('YES')
	elif len(set(daf3)) == 1:
		print('YES')
	else:
		print('NO')


def main():
	n = int(input())
	aa = [*map(int, input().split()), 0]
	res = True
	i = j = max(range(n + 1), key=aa.__getitem__)
	a = aa[i]
	while aa[i] == a:
		i -= 1
	while i >= -1:
		if a <= aa[i]:
			res = False
			break
		a = aa[i]
		i -= 1
	a = aa[j]
	while aa[j] == a:
		j += 1
	while j <= n:
		if a <= aa[j]:
			res = False
			break
		a = aa[j]
		j += 1
	print(('NO', 'YES')[res])
main()


n = int(input())
arr = [int(a) for a in input().split()]
ok = True
a = 1
for i in range(1, len(arr) + 1):
	a = i
	if i == len(arr):
		break
	if arr[i - 1] >= arr[i]:
		break
for i in range(a, len(arr) + 1):
	a = i
	if i == len(arr):
		break
	if arr[i - 1] != arr[i]:
		break
for i in range(a, len(arr) + 1):
	a = i
	if i == len(arr):
		break
	if arr[i - 1] <= arr[i]:
		ok = False
if ok:
	print('YES')
else:
	print('NO')


def check(c):
	combs = [['i', 'c', 'd'], ['c'], ['c', 'd'], ['i', 'c'], ['i', 'd'], ['i'], ['d']]
	if removeNeighbours(list(c)) in combs:
		return True
	return False

def removeNeighbours(l):
	i = 0
	while i < len(l) - 1:
		if l[i] == l[i + 1]:
			del l[i]
		else:
			i = i + 1
	return l

def solve(a):
	c = ''
	for i in range(len(a) - 1):
		if a[i] < a[i + 1]:
			c += 'i'
		elif a[i] == a[i + 1]:
			c += 'c'
		elif a[i] > a[i + 1]:
			c += 'd'
	if len(a) == 1:
		return True
	elif check(c):
		return True
	return False
N = int(input())
A = [int(i) for i in input().split()]
print('YES' if solve(A) else 'NO', end='')


n = int(input())
l = list(map(int, input().split()))
count = 0
f = True
s = True
t = True
for i in range(0, n - 1):
	if l[i + 1] > l[i]:
		if f:
			count += 1
		else:
			f = False
	elif l[i] == l[i + 1]:
		f = False
		if s:
			count += 1
		else:
			s = False
	elif l[i + 1] < l[i]:
		f = False
		s = False
		if t:
			count += 1
		else:
			t = False
if count == n - 1:
	print('YES')
else:
	print('NO')


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


def unimodal():
	import sys
	nList = []
	count = 0
	N = int(input())
	S = input()
	nList = S.split()
	nList = [int(i) for i in nList]
	for x in range(len(nList) - 2):
		if nList[x + 1] - nList[x] > 0:
			pass
		elif nList[x + 1] - nList[x] == 0:
			if nList[x + 2] - nList[x + 1] > 0:
				print('NO')
				sys.exit()
			pass
		else:
			if nList[x + 1] - nList[x] < 0:
				if nList[x + 2] - nList[x + 1] > 0:
					print('NO')
					sys.exit()
				elif nList[x + 2] - nList[x + 1] == 0:
					print('NO')
					sys.exit()
			pass
	print('YES')
unimodal()


fu = int(input())
array = list(map(int, input().split()))
check = k = 0
try:
	while array[k] < array[k + 1]:
		k += 1
	else:
		while array[k] == array[k + 1]:
			k += 1
		else:
			if array[k] < array[k + 1]:
				print('NO')
			else:
				while array[k] > array[k + 1]:
					k += 1
				else:
					print('NO')
except:
	print('YES')


n = int(input())
l = [int(i) for i in input().split()]
i = 1
c = 0
while i < n and l[i] > l[i - 1]:
	i += 1
	c += 1
while i < n and l[i] == l[i - 1]:
	i += 1
	c += 1
while i < n and l[i] < l[i - 1]:
	i += 1
	c += 1
print('YES' if c == n - 1 else 'NO')


import sys
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('NO')
else:
	print('YES')


(n, r, p) = (int(input()), 0, 0)
for i in map(int, input().split()):
	if i > p and r > 0 or (i == p and r == 2):
		exit(print('NO'))
	elif i > p and r == 0:
		p = i
	elif i == p:
		r = 1
	else:
		r = 2
	p = i
print('YES')


lectura = lambda : map(int, input().split())
total = int(list(lectura())[0])
total1 = total - 1
a = list(lectura())
posicion = 0
while posicion < total1 and a[posicion] < a[posicion + 1]:
	posicion += 1
while posicion < total1 and a[posicion] == a[posicion + 1]:
	posicion += 1
while posicion < total1 and a[posicion] > a[posicion + 1]:
	posicion += 1
posicion += 1
print(['YES', 'NO'][posicion != total])


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


LArray = list(map(int, input().split()))
Array = list(map(int, input().split()))
Increasing = False
Middle = False
Decreasing = False
if len(Array) == 2 and len(Array) == 1:
	print('YES')
else:
	i = 0
	while i < len(Array) - 1:
		if Array[i] < Array[i + 1]:
			i += 1
		else:
			break
	while i < len(Array) - 1:
		if Array[i] == Array[i + 1]:
			i += 1
		else:
			break
	while i < len(Array) - 1:
		if Array[i] > Array[i + 1]:
			i += 1
		else:
			break
if i == LArray[0] - 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
flag = True
f = f3 = True
for i in range(1, n):
	if flag == True:
		if a[i] == a[i - 1]:
			flag = False
			prev = a[i - 1]
		elif a[i] < a[i - 1]:
			flag = False
			f3 = False
	elif f3 == True and a[i] == prev:
		f = True
	else:
		f3 = False
		if a[i] >= a[i - 1]:
			f = False
			break
if f == True:
	print('YES')
else:
	print('NO')


num = []
n = int(input())
string = input()
for each in string.split(' '):
	num.append(int(each))
isMax = 0
isEqual = 0
isDec = 0
cnt = 0
while cnt < n - 1 and isMax == 0:
	if num[cnt] < num[cnt + 1]:
		cnt += 1
	else:
		isMax = 1
while cnt < n - 1 and isEqual == 0:
	if num[cnt] == num[cnt + 1]:
		cnt += 1
	else:
		isEqual = 1
while cnt < n - 1 and isDec == 0:
	if num[cnt] > num[cnt + 1]:
		cnt += 1
	else:
		isDec = 1
if cnt == n - 1:
	print('YES\n')
else:
	print('NO\n')


n = int(input())
l = list(map(int, input().split()))
mode = ''

def f():
	if n == 1:
		print('YES')
		return
	if l[1] > l[0]:
		mode = '+'
	if l[1] < l[0]:
		mode = '-'
	if l[1] == l[0]:
		mode = '0'
	for i in range(1, n - 1):
		if l[i + 1] < l[i]:
			mode = '-'
		if l[i + 1] > l[i]:
			if mode != '+':
				print('NO')
				return
		if l[i + 1] == l[i]:
			if mode == '-':
				print('NO')
				return
			mode = '0'
	print('YES')
f()


from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
t = 0
res = 'YES'
for i in range(1, n):
	if a[i] == a[i - 1]:
		if t == 2:
			res = 'NO'
			break
		t = 1
	elif a[i] > a[i - 1]:
		if t != 0:
			res = 'NO'
			break
	elif a[i] < a[i - 1]:
		t = 2
print(res)


n = int(input())
a = [int(x) for x in input().split(' ')]
m = 'YES'
s = 0
v = 0
for i in range(n):
	if s == 0:
		if v >= a[i]:
			s = 1
	if s == 1:
		if v < a[i]:
			m = 'NO'
			break
		elif v > a[i]:
			s = 2
	if s == 2:
		if v <= a[i]:
			m = 'NO'
			break
	v = a[i]
print(m)


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su
n = inin()
ans = 'YES'
arr = inar()
mode = 0
prev = 0
currmode = 0
for i in arr:
	if i > prev:
		currmode = 1
	elif i == prev:
		currmode = 2
	else:
		currmode = 3
	prev = i
	if currmode < mode:
		ans = 'NO'
	mode = currmode
print(ans)


n = int(input())
a = list(map(int, input().split()))
d = [a[i] - a[i - 1] for i in range(1, n)]
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')


import sys

def strictly_inc(list):
	for i in range(len(list)):
		if i > 0 and list[i] <= list[i - 1]:
			return False
	return True
n = int(sys.stdin.readline().strip())
list = [int(i) for i in sys.stdin.readline().split()]
max = max(list)
end = len(list) - 1 - list.index(max)
list.reverse()
start = list.index(max)
left = list[:start]
mid = list[start:end + 1]
right = list[end + 1:]
right.reverse()
if strictly_inc(left) and strictly_inc(right) and (min(mid) == max):
	print('YES')
else:
	print('NO')


(ans, x1, x2, x3) = (1, 1, 1, 1)
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n - 1):
	if a[i + 1] > a[i] and x1 == 0:
		ans = 0
	elif a[i + 1] == a[i] and x2 == 0:
		ans = 0
	elif a[i + 1] == a[i] and x2 == 1:
		x1 = 0
	elif a[i + 1] < a[i] and x2 == 1:
		x2 = 0
		x1 = 0
if ans == 1:
	print('YES')
else:
	print('NO')


def uni(a):
	global k
	i = 0
	while i < n - 1 and a[i] < a[i + 1]:
		k += 1
		i += 1
	while i < n - 1 and a[i] == a[i + 1]:
		k += 1
		i += 1
	while i < n - 1 and a[i] > a[i + 1]:
		k += 1
		i += 1
	return k
n = int(input())
a = [int(i) for i in input().split()]
k = 0
s = uni(a)
if s == n - 1:
	print('YES')
else:
	print('NO')


n = input()
n = int(n)
tmp2 = input()
strlist = tmp2.split(' ')
mylist = []
for x in strlist:
	mylist.append(int(x))
max = float('inf')
mylist.append(max)
idx = 1
while idx < n and mylist[idx] > mylist[idx - 1]:
	idx += 1
while idx < n and mylist[idx] == mylist[idx - 1]:
	idx += 1
while idx < n and mylist[idx] < mylist[idx - 1]:
	idx += 1
if idx == len(mylist) - 1:
	print('YES')
else:
	print('NO')


(n, array) = (int(input()), input().split())
array = [int(ch) for ch in array]

def is_unimodal(seq):
	i = 1
	end = len(seq)
	while i < end and seq[i - 1] < seq[i]:
		i += 1
	while i < end and seq[i - 1] == seq[i]:
		i += 1
	while i < end and seq[i - 1] > seq[i]:
		i += 1
	if i == end:
		print('YES')
	else:
		print('NO')
is_unimodal(array)


def get(n):
	if n < 0:
		return -1
	elif n == 0:
		return 0
	return 1
n = int(input())
nums = [int(j) for j in input().split()]
if n == 1:
	print('YES')
else:
	stream = [get(nums[1] - nums[0])]
	for j in range(2, n):
		diff = nums[j] - nums[j - 1]
		if get(diff) != stream[len(stream) - 1]:
			stream.append(get(diff))
	if stream == [1, 0, -1] or stream == [1, 0] or stream == [1, -1] or (stream == [0, -1]) or (stream == [1]) or (stream == [0]) or (stream == [-1]):
		print('YES')
	else:
		print('NO')


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


def check_arr(arr):
	(i, j) = (0, n - 1)
	while i < n - 1 and arr[i] < arr[i + 1]:
		i += 1
	while j > 0 and arr[j - 1] > arr[j]:
		j -= 1
	if arr[i] == arr[j]:
		for k in range(i, j + 1):
			if arr[k] != arr[i]:
				return 'NO'
		return 'YES'
	return 'NO'
n = int(input())
arr = list(map(int, input().split()))
print(check_arr(arr))


def isUnimodal(n, a):
	state = 0
	for i in range(1, n):
		if state == 0:
			if a[i - 1] > a[i]:
				state = 2
			if a[i - 1] == a[i]:
				state = 1
		elif state == 1:
			if a[i - 1] < a[i]:
				return 'NO'
			if a[i - 1] > a[i]:
				state = 2
		elif state == 2:
			if a[i - 1] <= a[i]:
				return 'NO'
	return 'YES'
n = int(input())
a = [int(x) for x in input().split()]
print(isUnimodal(n, a))


n = int(input())
a = list(map(int, input().split()))
mode = 0
old = a[0]
ans = 'YES'
for x in a[1:]:
	if old < x:
		if mode > 0:
			ans = 'NO'
			break
	elif old == x:
		if mode == 0:
			mode = 1
		elif mode == 2:
			ans = 'NO'
			break
	elif mode == 1 or mode == 0:
		mode = 2
	old = x
print(ans)


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


count = input()
chisla = [int(symbol) for symbol in input().split()]

def strictly_increasing(L):
	return all((x < y for (x, y) in zip(L, L[1:])))

def strictly_decreasing(L):
	return all((x > y for (x, y) in zip(L, L[1:])))
max_value = max(chisla)
max_indexes = [index for index in range(len(chisla)) if chisla[index] == max_value]
difference_is_one = True
for i in range(len(max_indexes) - 1):
	if max_indexes[i + 1] - max_indexes[i] > 1:
		difference_is_one = False
if difference_is_one and strictly_increasing(chisla[:max_indexes[0] + 1]) and strictly_decreasing(chisla[max_indexes[-1]:]):
	print('YES')
else:
	print('NO')


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, a) = (int(input()), list(map(int, input().split())))
x = []
for i in range(1, n):
	if a[i] > a[i - 1]:
		x.append(1)
	elif a[i] == a[i - 1]:
		x.append(2)
	else:
		x.append(3)
print('YES' if sorted(x) == x else 'NO')


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


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


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())
a = list(map(int, input().split()))
m = 0
for i in range(n - 1):
	if m == 0:
		if a[i] == a[i + 1]:
			m = 1
		elif a[i] > a[i + 1]:
			m = 2
	elif m == 1:
		if a[i] < a[i + 1]:
			print('NO')
			exit(0)
		elif a[i] > a[i + 1]:
			m = 2
	elif a[i] < a[i + 1] or a[i] == a[i + 1]:
		print('NO')
		exit(0)
print('YES')


input()
A = list(map(int, input().split()))
m = max(A)
i = A.index(m)
(L, R) = (A[:i], A[i:])
print('YES' if len(L) == len(set(L)) and L == sorted(L) and (len(R) + 1 == len(set(R)) + A.count(m)) and (R == sorted(R, reverse=True)) else 'NO')


n = int(input())
a = list(map(int, input().split()))
pre = -float('inf')
flag = True
state = 0
for i in range(n):
	if state == 0 and pre == a[i]:
		state = 1
	if state == 1 and pre > a[i]:
		state = 2
	if state == 0 and pre > a[i]:
		state = 2
	if state == 1 and pre < a[i]:
		print('NO')
		exit()
	elif state == 2 and pre <= a[i]:
		print('NO')
		exit()
	pre = a[i]
print('YES')


n = int(input())
arr = list(map(int, input().split()))
ma = max(arr)
prima = arr[:arr.index(ma)]
ultimeIndex = None
for x in range(len(arr))[::-1]:
	if arr[x] == ma:
		ultimeIndex = x
		break
ultima = arr[ultimeIndex + 1:]
media = arr[arr.index(ma):ultimeIndex + 1]
if prima == sorted(list(dict.fromkeys(prima))) and len(set(media)) == 1 and (ultima == sorted(list(dict.fromkeys(ultima)), reverse=True)):
	print('YES')
else:
	print('NO')


def func():
	n = int(input())
	a = list(map(int, input().split()))
	mode = 1
	for i in range(1, n):
		if a[i] - a[i - 1] <= 0:
			if a[i] - a[i - 1] == 0 and mode == 3:
				return 'NO'
			elif a[i] - a[i - 1] == 0:
				mode = 2
			elif a[i] - a[i - 1] < 0:
				mode = 3
		elif mode == 2 or mode == 3:
			return 'NO'
	return 'YES'
print(func())


import itertools as it
sign = lambda x: (x > 0) - (x < 0)
(n, arr) = (input(), [int(x) for x in input().split()])
diff = (sign(a - b) for (a, b) in zip(arr, arr[1:]))
diff = (set(g) for (k, g) in it.groupby(diff))
diff = list(it.chain.from_iterable(diff))
if all((a < b for (a, b) in zip(diff, diff[1:]))):
	print('YES')
else:
	print('NO')


(n, arr) = (int(input()), list(map(int, input().split())))
mode = 1
vals = []
for i in range(1, n):
	if arr[i - 1] < arr[i]:
		vals.append(1)
	elif arr[i] == arr[i - 1]:
		vals.append(2)
	else:
		vals.append(3)
	if vals != sorted(vals):
		print('NO')
		break
else:
	print('YES')


n = int(input())
s = input()
a = [int(n) for n in s.split()]
l = 0
while l < n - 1:
	if a[l] < a[l + 1]:
		l += 1
	else:
		break
r = n - 1
while r > 0:
	if a[r] < a[r - 1]:
		r -= 1
	else:
		break
flag = 1
while l != r:
	if a[l] != a[l + 1]:
		flag = 0
		break
	else:
		l += 1
if flag == 1:
	print('YES')
else:
	print('NO')


N = int(input())
l = [int(i) for i in input().split()]
i = 1
while i < N and l[i] > l[i - 1]:
	i += 1
while i < N and l[i] == l[i - 1]:
	i += 1
while i < N and l[i] < l[i - 1]:
	i += 1
if i == N:
	print('YES')
else:
	print('NO')


n = int(input())
ar = [int(i) for i in input().split()]
flag = True
state = 0
i = 1
while i < n:
	if state == 0:
		if ar[i] <= ar[i - 1]:
			state = 1
		else:
			i += 1
	elif state == 1:
		if ar[i] != ar[i - 1]:
			state = 2
		else:
			i += 1
	elif state == 2:
		if ar[i] >= ar[i - 1]:
			flag = False
		else:
			i = i + 1
	if not flag:
		break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
numbers = list(map(int, input().split()))
j = 'YES'
increase = False
const = False
decr = False
if len(numbers) != 1:
	for i in range(len(numbers) - 1):
		if numbers[i] < numbers[i + 1]:
			if const or decr:
				j = 'NO'
				break
			increase = True
		elif numbers[i] == numbers[i + 1]:
			if decr:
				j = 'NO'
				break
			const = True
		elif numbers[i] > numbers[i + 1]:
			decr = True
print(j)


n = int(input())
data = list(map(int, input().split(' ')))
pos1 = 0
pos2 = n - 1
for i in range(1, len(data)):
	if data[i - 1] > data[i]:
		break
	else:
		pos1 += 1
for i in range(len(data) - 2, 0, -1):
	if data[i] < data[i + 1]:
		break
	else:
		pos2 -= 1
state = True
if pos1 > pos2:
	for i in range(pos2 + 1, pos1 + 1):
		if data[i] != data[i - 1]:
			state = False
elif pos1 < pos2:
	for i in range(pos1 + 1, pos2 + 1):
		if data[i] != data[i - 1]:
			state = False
main_element = data[pos1]
main_state = True
for i in range(1, len(data)):
	if data[i] == data[i - 1] and data[i] != main_element:
		state = False
		main_state = False
if pos1 == 0 and pos2 == 1 and main_state:
	state = True
print('YES') if state else print('NO')


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
	if a[i] < a[i + 1]:
		b.append(-1)
	elif a[i] == a[i + 1]:
		b.append(0)
	else:
		b.append(1)
c = sorted(b)
if len(b) == 0:
	print('YES')
elif b != c:
	print('NO')
else:
	print('YES')


n = int(input())
stringArr = input().split()
arr = [int(ch) for ch in stringArr]

def is_modal(n, arr):
	i = 1
	for i in range(i, n):
		if not arr[i - 1] < arr[i]:
			break
	else:
		return 'YES'
	for i in range(i, n):
		if not arr[i - 1] == arr[i]:
			break
	else:
		return 'YES'
	for i in range(i, n):
		if not arr[i - 1] > arr[i]:
			return 'NO'
	else:
		return 'YES'
print(is_modal(n, arr))


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


x = int(input())
a = list(map(int, input().split()))
b = []
a.append(0)
for i in range(x):
	if a[i] < a[i + 1]:
		b.append(a[i])
	else:
		break
for t in range(i, x):
	if a[t] == a[t + 1]:
		b.append(a[t])
	else:
		break
for p in range(t, x):
	if a[p] > a[p + 1]:
		b.append(a[p])
	else:
		break
del a[-1]
if b == a:
	print('YES')
else:
	print('NO')


import itertools
import math
from collections import defaultdict

def input_ints():
	return list(map(int, input().split()))

def solve():
	n = int(input())
	a = input_ints()
	x = 0
	while x < n - 1:
		if a[x] < a[x + 1]:
			x += 1
		else:
			break
	y = n - 1
	while y > 0:
		if a[y - 1] > a[y]:
			y -= 1
		else:
			break
	if y < x:
		print('NO')
		return
	x += 1
	for i in range(x, y):
		if a[i] != max(a):
			print('NO')
			return
	print('YES')
solve()


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


x = int(input())
arr = [int(x) for x in input().split()]
m = 1
a = True
if x == 1:
	print('YES')
else:
	for i in range(1, x):
		if m == 1:
			if arr[i] == arr[i - 1]:
				m = 0
			elif arr[i] < arr[i - 1]:
				m = -1
		elif m == 0:
			if arr[i] < arr[i - 1]:
				m = -1
			elif arr[i] > arr[i - 1]:
				a = False
		elif m == -1:
			if arr[i] < arr[i - 1]:
				m = -1
			else:
				a = False
	if a:
		print('YES')
	else:
		print('NO')


def unimodal(arr):
	state = 0
	for i in range(0, len(arr) - 1):
		if arr[i] < arr[i + 1] and state == 0:
			state = 0
		elif arr[i] == arr[i + 1] and (state == 0 or state == 1):
			state = 1
		elif arr[i] > arr[i + 1]:
			state = 2
		else:
			return 'NO'
			break
	return 'YES'
input()
print(unimodal([int(x) for x in input().split()]))


n = int(input())
a = list(map(int, input().split()))
(b, c, d) = (0, 0, 0)
(bb, cc, dd) = (0, 0, 0)
counter = 1
for i in range(n - 1):
	if a[i] < a[i + 1] and b == 0:
		b = 0
		bb += 1
	else:
		b = 1
		if a[i] == a[i + 1] and c == 0:
			c = 0
			cc += 1
		else:
			c = 1
			if a[i] > a[i + 1] and d == 0:
				d = 0
				dd += 1
			else:
				d = 1
if bb + cc + dd + 1 == n:
	print('YES')
else:
	print('NO')


n = int(input())
lista = []
[lista.append(int(i)) for i in input().split()]
maior = False
medio = False
menor = False
output = 'YES'
for i in range(0, len(lista) - 1):
	if lista[i + 1] > lista[i]:
		if maior or medio:
			output = 'NO'
			break
	elif lista[i + 1] == lista[i]:
		if not maior and (not medio):
			maior = True
		if medio:
			output = 'NO'
			break
	elif lista[i + 1] < lista[i]:
		if not maior and (not medio):
			medio = True
			maior = True
		elif maior and (not medio):
			medio = True
		if not maior and medio:
			output = 'NO'
			break
print(output)


__author__ = 'Esfandiar'
n = int(input())
a = list(map(int, input().split()))
f = 0
for i in range(1, n):
	if f == 0:
		if a[i] <= a[i - 1]:
			f = 1
		con = a[i - 1]
	elif a[i] > a[i - 1]:
		print('NO')
		exit()
	elif a[i] == a[i - 1]:
		if a[i] != con:
			print('NO')
			exit()
print('YES')


n = int(input())
a = list(map(int, input().split()))
flag = True
f1 = True
f2 = False
for i in range(1, n):
	if f1:
		if a[i] <= a[i - 1]:
			f1 = False
			if a[i] < a[i - 1]:
				f2 = True
	else:
		if a[i] < a[i - 1]:
			f2 = True
		elif a[i] > a[i - 1]:
			flag = False
		if f2:
			if flag and a[i] >= a[i - 1]:
				flag = False
if flag:
	print('YES')
else:
	print('NO')


int(input())
l = list(map(int, input().split()))
while len(l) > 1:
	if l[0] < l[1]:
		l = l[1:]
	else:
		break
while len(l) > 1:
	if l[-1] < l[-2]:
		l = l[:-1]
	else:
		break
i = 0
erg = True
while i < len(l) - 1:
	if l[i] != l[i + 1]:
		print('NO')
		erg = False
		break
	i += 1
if erg:
	print('YES')


from sys import stdin
input = lambda : stdin.readline().strip()
n = int(input())
a = [*map(int, input().split())]
state = None
answer = 'YES'
for i in range(1, n):
	if state == None:
		if a[i] == a[i - 1]:
			state = 'sam'
		elif a[i] < a[i - 1]:
			state = 'dec'
		else:
			state = 'inc'
	if state == 'dec':
		if a[i] == a[i - 1]:
			answer = 'NO'
		elif a[i] > a[i - 1]:
			answer = 'NO'
		else:
			continue
	if state == 'sam':
		if a[i] == a[i - 1]:
			continue
		elif a[i] > a[i - 1]:
			answer = 'NO'
			break
		else:
			state = 'dec'
	if state == 'inc':
		if a[i] == a[i - 1]:
			state = 'sam'
		elif a[i] > a[i - 1]:
			continue
		else:
			state = 'dec'
print(answer)


n = int(input())
stage = -1
string = list(map(int, input().split()))
x1 = string[0]
for i in range(1, n):
	x2 = string[i]
	if stage == -1 and x1 == x2:
		stage = 0
	elif stage == -1 and x1 > x2:
		stage = 1
	elif stage == 0 and x1 < x2:
		print('NO')
		exit()
	elif stage == 0 and x1 > x2:
		stage = 1
	elif stage == 1 and (x1 < x2 or x1 == x2):
		print('NO')
		exit()
	x1 = x2
print('YES')


input()
arr = [int(i) for i in input().split()]
mode = -1
could = True
i = 0
while i < len(arr) - 1:
	if mode == -1:
		if arr[i] < arr[i + 1]:
			i += 1
		else:
			mode += 1
	elif mode == 0:
		if arr[i] == arr[i + 1]:
			i += 1
		else:
			if arr[i] < arr[i + 1]:
				could = False
				break
			mode += 1
	elif arr[i] > arr[i + 1]:
		i += 1
	else:
		could = False
		break
print('YES' if could else 'NO')


def checkinc(s):
	a = len(s) - 1
	for i in range(a):
		if s[i + 1] <= s[i]:
			return False
	return True

def checkdec(s):
	a = len(s) - 1
	for i in range(a):
		if s[i + 1] >= s[i]:
			return False
	return True

def maxima(s):
	res = -100000000
	minidx = None
	for i in range(len(s)):
		if s[i] > res:
			res = s[i]
			minidx = i
	maxindx = minidx
	while maxindx < len(s):
		if s[maxindx] == res:
			maxindx += 1
		else:
			break
	return (minidx, maxindx)
n = int(input())
s = [int(each) for each in input().split()]
(minn, maxx) = maxima(s)
inc = checkinc(s[:minn])
dec = checkdec(s[maxx:])
if inc and dec:
	print('YES')
else:
	print('NO')


n = int(input().strip())
ll = list(map(int, input().split()))
k = 'B'
l = ll[0]
t = True
for i in range(1, n):
	if l < ll[i] and k == 'B':
		l = ll[i]
	elif l == ll[i] and k in ['B', 'K']:
		k = 'K'
	elif l > ll[i]:
		l = ll[i]
		k = 'Y'
	else:
		t = False
		break
print('YES' if t == True else 'NO')


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


def unimodal(inlist):
	state = 'up'
	last = 0
	if len(inlist) <= 2:
		return 'YES'
	for i in range(len(inlist)):
		val = inlist[i]
		if state == 'up':
			if inlist[i] > last:
				last = inlist[i]
			elif inlist[i] == last:
				state = 'peak'
				last = inlist[i]
			elif inlist[i] < last:
				state = 'down'
				last = inlist[i]
		elif state == 'peak':
			if inlist[i] > last:
				return 'NO'
			if inlist[i] < last:
				state = 'down'
				last = inlist[i]
		elif state == 'down':
			if inlist[i] >= last:
				return 'NO'
			else:
				last = inlist[i]
	return 'YES'
_ = input()
inlist = list(map(int, input().split()))
print(unimodal(inlist))


n = int(input())
l = list(map(int, input().split()))
p = 0
c = -1
r = -1
p1 = 0
for i in range(1, n):
	if l[i] > l[i - 1] and r == -1:
		p = 0
	else:
		if r == -1:
			r = l[i]
		elif l[i] != r and r < l[i]:
			print('NO')
			exit()
		if l[i] < l[i - 1]:
			c = i + 1
			break
if c != -1:
	for i in range(c, n):
		if l[i - 1] <= l[i]:
			print('NO')
			exit()
print('YES')


n = int(input())
array = [int(x) for x in input().split()]

def isdecreasing(a):
	for i in range(len(a) - 1):
		if a[i] <= a[i + 1]:
			return 'NO'
	return 'YES'

def isnonincreasing(a):
	for i in range(len(a) - 1):
		if a[i] < a[i + 1]:
			return 'NO'
		elif a[i] == a[i + 1]:
			continue
		if a[i] > a[i + 1]:
			return isdecreasing(a[i:])
	return 'YES'

def isunimodal(a):
	for i in range(len(a) - 1):
		if a[i] < a[i + 1]:
			continue
		elif a[i] == a[i + 1]:
			return isnonincreasing(a[i:])
		else:
			return isdecreasing(a[i:])
	return 'YES'
print(isunimodal(array))


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
	print('YES')
elif n == 1:
	print('YES')
else:
	checker = []
	for i in range(n - 1):
		if a[i + 1] - a[i] < 0:
			checker.append(-1)
		elif a[i + 1] == a[i]:
			checker.append(0)
		else:
			checker.append(1)
	temp = checker.copy()
	temp.sort(reverse=True)
	if temp == checker:
		print('YES')
	else:
		print('NO')


n = int(input())
a = (*map(int, input().split()),)
l = 0
r = n
while l + 1 < n and a[l] < a[l + 1]:
	l += 1
while r > 0 and a[r - 2] > a[r - 1]:
	r -= 1
print('YNEOS'[len({*a[l:r]}) != 1::2])


n = int(input())
arr = [int(x) for x in input().split()]
k = 0
while k + 1 < n and arr[k] < arr[k + 1]:
	k += 1
while k + 1 < n and arr[k] == arr[k + 1]:
	k += 1
while k + 1 < n and arr[k] > arr[k + 1]:
	k += 1
if k >= n - 1:
	print('YES')
else:
	print('NO')


import sys

def CF831A(l, state=0):
	if len(l) == 1:
		return 'YES'
	if l[1] > l[0] and state <= 0:
		return CF831A(l[1:], 0)
	elif l[1] == l[0] and state <= 1:
		return CF831A(l[1:], 1)
	elif l[1] < l[0] and state <= 2:
		return CF831A(l[1:], 2)
	else:
		return 'NO'
sys.stdin.readline()
rawl = sys.stdin.readline().split()
l = [int(i) for i in rawl]
print(CF831A(l))


n = input()
s = input()
a = [int(x) for x in s.split()]

def is_unimodal_array(a):
	last_base = -1
	base = 0
	state = 0
	for item in a:
		if item > base:
			if last_base >= base or state != 0:
				print('NO')
				return
		elif item == base:
			if state == 0 and last_base <= base:
				state = 1
			if last_base > base or state != 1:
				print('NO')
				return
		elif item < base:
			if state == 1 and last_base == base:
				state = 2
			elif state == 0 and last_base < base:
				state = 2
			if state != 2:
				print('NO')
				return
		last_base = base
		base = item
	print('YES')
is_unimodal_array(a)


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


n = int(input())
l = list(map(int, input().split()))
d = 1
for i in range(1, n):
	if d > 0:
		if l[i] == l[i - 1]:
			d = 0
		elif l[i] < l[i - 1]:
			d = -1
	elif d == 0:
		if l[i] > l[i - 1]:
			print('NO')
			break
		elif l[i] < l[i - 1]:
			d = -1
	elif l[i] >= l[i - 1]:
		print('NO')
		break
else:
	print('YES')


n = int(input())
arr = [int(c) for c in input().split()]

def unimodalArray(n, arr):
	pos2 = n - 1
	pos1 = 0
	for i in range(pos2):
		if arr[i] < arr[i + 1]:
			pos1 = pos1 + 1
		else:
			break
	for j in range(pos1, pos2):
		if arr[j] == arr[j + 1]:
			pos1 = pos1 + 1
		else:
			break
	for k in range(pos1, pos2):
		if arr[k] > arr[k + 1]:
			pos1 = pos1 + 1
	if pos1 == pos2:
		return 'YES'
	else:
		return 'NO'
print(unimodalArray(n, arr))


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


n = int(input())
arr = input().split()
ans = []
cnt = 0
cur = 0
left_sorted = []
right_sorted = []
for i in arr:
	ans.append(int(i))
left_max = ans.index(max(ans))
if len(ans) == 1:
	print('YES')
	exit()
for i in range(left_max, len(ans) - 1):
	if ans[i] == ans[i + 1]:
		cur += 1
for i in range(left_max):
	if ans[i] < ans[i + 1]:
		cnt += 1
for i in range(left_max + cur, len(ans) - 1):
	if ans[i] > ans[i + 1]:
		cnt += 1
cur += 1
if cnt == len(ans) - cur:
	print('YES')
else:
	print('NO')


length = int(input())
numbers = [int(x) for x in input().split()]

def inc(num1, num2):
	return num2 > num1

def cons(num1, num2):
	return num1 == num2

def dec(num1, num2):
	return num2 < num1
increase = True
constant = True
for i in range(length - 1):
	if inc(numbers[i], numbers[i + 1]):
		if increase:
			continue
		else:
			print('NO')
			exit()
	elif cons(numbers[i], numbers[i + 1]):
		if constant:
			increase = False
			continue
		else:
			print('NO')
			exit()
	elif dec(numbers[i], numbers[i + 1]):
		if constant:
			constant = False
			increase = False
print('YES')


n = int(input())
a = [int(s) for s in input().split()]
i = l = m = r = 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')


n = int(input())
a = [int(x) for x in input().split()]
check = []
for i in range(n - 1):
	if a[i] < a[i + 1]:
		check.append(0)
	elif a[i] == a[i + 1]:
		check.append(1)
	else:
		check.append(2)
result = 'YES'
for j in range(n - 2):
	if check[j] > check[j + 1]:
		result = 'NO'
		break
print(result)


n = int(input())
s = [int(a) for a in input().split()]
f = -1
ff = True
for i in range(n - 1):
	if f == -1:
		if s[i] > s[i + 1]:
			f = 1
		elif s[i] == s[i + 1]:
			f = 0
	elif f == 0:
		if s[i] < s[i + 1]:
			ff = False
		elif s[i] > s[i + 1]:
			f = 1
	elif f == 1:
		if s[i] == s[i + 1]:
			ff = False
		elif s[i] < s[i + 1]:
			ff = False
if ff:
	print('YES')
else:
	print('NO')


i = int(input())
a = list(map(int, input().split()))
u = False
s = 0
if i > 2:
	for x in range(1, i):
		if s == 0:
			if a[x] == a[x - 1]:
				s = 1
			elif a[x] < a[x - 1]:
				s = 2
		elif s == 1:
			if a[x] < a[x - 1]:
				s = 2
			elif a[x] > a[x - 1]:
				break
		elif s == 2:
			if a[x] >= a[x - 1]:
				break
		if x == i - 1:
			u = True
else:
	u = True
if u:
	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())
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())
arr = [int(x) for x in input().split()]
i = 0
while i < n - 1 and arr[i] < arr[i + 1]:
	i += 1
j = n - 1
while j > 0 and arr[j] < arr[j - 1]:
	j -= 1
print('YES' if all((x == arr[i] for x in arr[i:j + 1])) else 'NO')


import sys
t = int(input())
(inc, c, d) = (0, 0, 0)
arr = list(map(int, input().split(' ')))
for i in range(1, t):
	if arr[i] > arr[i - 1]:
		if d == 1 or c == 1:
			print('NO')
			sys.exit()
		inc = 1
	elif arr[i] == arr[i - 1]:
		if d == 1:
			print('NO')
			sys.exit()
		c = 1
	elif arr[i] <= arr[i - 1]:
		d = 1
print('YES')


l = int(input())
arr = list(map(int, input().split()))
inc = True
const = True
dec = True
unimodal = True
for i in range(0, l - 1):
	if arr[i] < arr[i + 1] and inc:
		continue
	elif arr[i] == arr[i + 1] and const:
		inc = False
	elif arr[i] > arr[i + 1] and dec:
		inc = const = False
	else:
		dec = unimodal = False
		break
if unimodal:
	print('YES')
else:
	print('NO')


int(input())
(b1, b2, m) = (0, 0, -1)
for x in map(int, input().split()):
	if (x > m) & b1 | (x == m) & b2:
		print('NO')
		m = -1
		break
	b2 |= x < m
	b1 |= (x == m) | b2
	m = x
if m != -1:
	print('YES')


def solve():
	n = get(int)
	ar = get([int])
	start = -inf
	i = 1
	while i < n and ar[i] > ar[i - 1]:
		i += 1
	while i < n and ar[i] == ar[i - 1]:
		i += 1
	while i < n and ar[i] < ar[i - 1]:
		i += 1
	if i == n:
		return 'YES'
	else:
		return 'NO'
_testcases = '\n6\n1 5 5 5 4 2\n\nYES\n\n5\n10 20 30 20 10\n\nYES\n\n4\n1 2 1 2\n\nNO\n\n7\n3 3 3 3 3 3 3\n\nYES\n\n'.strip()
import re
import sys
import math
import heapq
from heapq import heapify, heappop, heappush
import bisect
from bisect import bisect_left, bisect_right
import operator
from operator import itemgetter, attrgetter
import itertools
import collections
inf = float('inf')
sys.setrecursionlimit(10000)

def tree():
	return collections.defaultdict(tree)

def cache(func):
	cache_dict = {}

	def _cached_func(*args, _get_cache=False):
		if _get_cache:
			return cache_dict
		if args in cache_dict:
			return cache_dict[args]
		cache_dict[args] = func(*args)
		return cache_dict[args]
	return _cached_func

def equal(x, y, epsilon=1e-06):
	if -epsilon <= x - y <= epsilon:
		return True
	if -epsilon <= x <= epsilon or -epsilon <= y <= epsilon:
		return False
	return -epsilon <= (x - y) / x <= epsilon or -epsilon <= (x - y) / y <= epsilon

def get(_type):
	if type(_type) == list:
		if len(_type) == 1:
			_type = _type[0]
			return list(map(_type, input().strip().split()))
		else:
			return [_type[i](inp) for (i, inp) in enumerate(input().strip().split())]
	else:
		return _type(input().strip())
print(solve())


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


from itertools import cycle

def main():
	size = int(input())
	array = []
	for val in input().split():
		array.append(int(val))
	print(checkArray(array, size))

def checkArray(arr, size):
	licycle = cycle(arr)
	nextelem = next(licycle)
	state = 1
	for i in range(size - 1):
		(thiselem, nextelem) = (nextelem, next(licycle))
		if state == 1:
			if thiselem > nextelem:
				state = -1
			if thiselem == nextelem:
				state = 0
		if state == 0:
			if thiselem < nextelem:
				return 'NO'
			if thiselem > nextelem:
				state = -1
		if state == -1:
			if thiselem <= nextelem:
				return 'NO'
	return 'YES'
main()


def is_unimodal(seq):
	i = 1
	end = len(seq)
	while i < end and seq[i - 1] < seq[i]:
		i += 1
	while i < end and seq[i - 1] == seq[i]:
		i += 1
	while i < end and seq[i - 1] > seq[i]:
		i += 1
	return i == end
a = int(input())
lst = list(map(int, input().split()))
if is_unimodal(lst) == True:
	print('YES')
else:
	print('NO')


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


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

def check(t, n):
	c = d = i = False
	h = True
	for i in range(n - 1):
		if t[i] == t[i + 1]:
			c = True
			if d:
				return False
		elif t[i] < t[i + 1]:
			i = True
			if c or d:
				return False
		else:
			d = True
			if i == n - 1:
				return c
	return h
if check(t, n):
	print('YES')
else:
	print('NO')


x = int(input())
s = [int(n) for n in input().split()]
d = []
if x > 1:
	for n in range(1, x):
		j = s[n] - s[n - 1]
		if j != 0:
			j = j // abs(j)
		d.append(j)
	p = d[0]
	l = 0
	for n in range(len(d)):
		if d[n] <= p:
			p = d[n]
			l = 1
		else:
			l = 0
			print('NO')
			break
	if l == 1:
		print('YES')
else:
	print('YES')


n = int(input())
arr = list(map(int, input().split()))
(s, t, p) = (0, 0, 0)
for i in range(1, n):
	if arr[i] < arr[i - 1]:
		s = 1
	elif arr[i] == arr[i - 1] and s:
		t = 1
	elif arr[i] == arr[i - 1] and (not s):
		p = 1
	if arr[i] > arr[i - 1] and (s or p):
		t = 1
if t:
	print('NO')
else:
	print('YES')


def main():
	a = int(input())
	lst = input().split(' ')
	lst = [int(x) for x in lst]
	state = 0
	prev = 0
	printed = False
	for x in range(0, a):
		if state == 0:
			if lst[x] == prev:
				state = 1
			elif lst[x] < prev:
				state = 2
			prev = lst[x]
		elif state == 1:
			if lst[x] > prev:
				printed = True
				print('NO')
				break
			elif lst[x] < prev:
				state = 2
			prev = lst[x]
		elif state == 2:
			if lst[x] >= prev:
				printed = True
				print('NO')
				break
			prev = lst[x]
	if printed == False:
		print('YES')
main()


def read():
	return [int(x) for x in input().split()]
notimportant = read()
x = read()
j = 0
i = 0
b = True
while i < len(x) - 1:
	if x[i] < x[i + 1] and j != 1 and (j != 2):
		j = 0
	elif x[i] == x[i + 1] and j != 2:
		j = 1
	elif x[i] > x[i + 1]:
		j = 2
	else:
		b = False
		break
	i += 1
if b:
	print('YES')
else:
	print('NO')


def unimodalArray(n, x):
	estado = 1
	for i in range(0, n - 1):
		if estado == 1:
			if x[i] == x[i + 1]:
				estado = 2
			elif x[i] > x[i + 1]:
				estado = 3
		elif estado == 2:
			if x[i] > x[i + 1]:
				estado = 3
			elif x[i] < x[i + 1]:
				return 'NO'
		elif estado == 3:
			if x[i] < x[i + 1] or x[i] == x[i + 1]:
				return 'NO'
	return 'YES'
nRaw = input()
n = int(nRaw)
xRaw = input()
xStr = xRaw.split()
x = list(map(int, xStr))
print(unimodalArray(n, x))


a = int(input())
b = [*map(int, input().split(' '))]
c = 0
d = 0
e = 0
i = 0
j = 0
k = 0
for i in range(a - 1):
	if b[i + 1] > b[i]:
		c += 1
	else:
		break
for j in range(i, a - 1):
	if b[j] == b[j + 1]:
		c += 1
	else:
		break
for k in range(j, a - 1):
	if b[k + 1] < b[k]:
		c += 1
	else:
		break
if c == a - 1:
	print('YES')
else:
	print('NO')


n = int(input())
mas = [int(i) for i in input().split()]
arr = []
for i in range(1, len(mas)):
	if mas[i] > mas[i - 1]:
		arr.append(1)
	if mas[i] < mas[i - 1]:
		arr.append(-1)
	if mas[i] == mas[i - 1]:
		arr.append(0)
res = 'YES'
for i in range(1, len(arr)):
	if arr[i] > arr[i - 1]:
		res = 'NO'
		break
print(res)


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

def fail():
	print('NO')
	exit()
if n == 1:
	print('YES')
else:
	r = [a[i + 1] - a[i] for i in range(n - 1)]
	bol = mal = sr = 0
	for i in r:
		if i == 0:
			if mal:
				fail()
			sr = 1
		if i > 0:
			if mal:
				fail()
			if sr:
				fail()
			bol = 1
		if i < 0:
			mal = 1
	print('YES')


def check(arr):
	(inc, index1) = increase(arr)
	if not inc:
		return 'NO'
	(con, index2) = constant(arr, index1)
	if not con:
		return 'NO'
	dec = decrease(arr, index2)
	if not dec:
		return 'NO'
	return 'YES'

def decrease(arr, index1):
	if index1 == len(arr) - 1:
		return True
	else:
		com = arr[index1]
		index = index1
		for i in range(index1 + 1, len(arr)):
			if arr[i] < com:
				com = arr[i]
				index = i
			else:
				return False
	return True

def increase(arr):
	com = arr[0]
	index = 0
	for i in range(1, len(arr)):
		if arr[i] > com:
			com = arr[i]
			index = i
		else:
			break
	return (True, index)

def constant(arr, index1):
	index = index1
	com = arr[index1]
	if index1 > 0:
		if arr[index1] < arr[index1 - 1]:
			return (False, -1)
	for i in range(index1 + 1, len(arr)):
		if arr[i] == com:
			com = arr[i]
			index = i
		else:
			break
	return (True, index)
n = int(input())
arr = [int(i) for i in str(input()).split()]
if len(arr) < 2:
	print('YES')
else:
	print(check(arr))


n = int(input())
l = list(map(int, input().split()))
if n == 1:
	print('YES')
	exit()
for i in range(n):
	if i < n - 1 and l[i] >= l[i + 1]:
		break
if i == n - 1:
	print('YES')
	exit()
for j in range(n - 1, -1, -1):
	if l[j - 1] <= l[j]:
		break
for k in range(i, j):
	if l[k] == l[k + 1]:
		continue
	else:
		print('NO')
		exit()
print('YES')


size = int(input())
numbers = [int(z) for z in input().split()]
slope = []
for x in range(1, size):
	slope.append(numbers[x] - numbers[x - 1])
flag = 0
if slope != []:
	prev = slope[0]
for duh in range(1, len(slope)):
	x = slope[duh]
	if prev == 0:
		if x > 0:
			flag = 1
			break
	elif prev < 0:
		if x >= 0:
			flag = 1
			break
	prev = x
if flag == 1:
	print('NO')
else:
	print('YES')


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


n = int(input())
l = [0] + list(map(int, input().split())) + [0]
i = 0
op = [lambda x, y: y > x, lambda x, y: y == x, lambda x, y: y < x]
for x in range(n + 1):
	(prev, current) = (l[x], l[x + 1])
	if i == 0 and op[0](prev, current):
		continue
	elif i == 0 and op[1](prev, current):
		i = 1
	elif i == 0 and op[2](prev, current):
		i = 2
	elif i == 1 and op[1](prev, current):
		continue
	elif i == 1 and op[2](prev, current):
		i = 2
	elif i == 2 and op[2](prev, current):
		continue
	else:
		print('NO')
		break
else:
	print('YES')


import sys

def solve():
	n = int(sys.stdin.readline())
	vec = list(map(int, sys.stdin.readline().split()))
	if n == 1:
		print('YES')
		return 0
	cur = 1
	while cur < len(vec) and vec[cur - 1] < vec[cur]:
		cur += 1
	while cur < len(vec) and vec[cur - 1] == vec[cur]:
		cur += 1
	while cur < len(vec) and vec[cur - 1] > vec[cur]:
		cur += 1
	if cur == len(vec):
		print('YES')
	else:
		print('NO')
solve()


n = int(input())
arr = [int(i) for i in input().split(' ')]
i = 1
if len(arr) == 1:
	print('YES')
else:
	while i < n and arr[i - 1] < arr[i]:
		i += 1
	while i < n and arr[i - 1] == arr[i]:
		i += 1
	while i < n and arr[i - 1] > arr[i]:
		i += 1
	print('YES' if i == n else 'NO')


n = int(input())
L = list(map(int, input().split()))
status = 0
t = 0
res = 1
for i in range(n):
	if t < L[i]:
		if status > 1:
			res = 0
			break
		status = 1
	elif t == L[i]:
		if status > 2:
			res = 0
			break
		status = 2
	else:
		status = 3
	t = L[i]
if res == 1:
	print('YES')
else:
	print('NO')


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


def main():
	n = int(input())
	a = [int(c) for c in input().split()]
	mx = max(a)
	idx = a.index(mx)
	for i in range(1, idx):
		if a[i] > mx or a[i] <= a[i - 1]:
			print('NO')
			return
	while idx + 1 < n and a[idx + 1] == mx:
		idx += 1
	for i in range(idx + 1, n - 1):
		if a[i] > mx or a[i + 1] >= a[i]:
			print('NO')
			return
	print('YES')
main()


n = int(input())
a = list(map(int, input().split()))
ans = 'YES'
ls = []
for i in range(n - 1):
	if a[i] < a[i + 1]:
		ls.append('<')
	elif a[i] > a[i + 1]:
		ls.append('>')
	else:
		ls.append('=')
for i in range(n - 2):
	for j in range(i + 1, n - 1):
		if ls[i] != ls[j] and (ls[i] == '>' or ls[j] == '<'):
			ans = 'NO'
			break
print(ans)


import sys
n = int(input())
lst = [int(x) for x in input().split()]
cnt = 0
while cnt < n - 1 and lst[cnt] < lst[cnt + 1]:
	cnt += 1
while cnt < n - 1 and lst[cnt] == lst[cnt + 1]:
	cnt += 1
while cnt < n - 1 and lst[cnt] > lst[cnt + 1]:
	cnt += 1
cnt += 1
if cnt != n:
	print('NO')
else:
	print('YES')


n = int(input())
s = input().split(' ')
s.append(str(int(s[n - 1]) - 1))
a = []
for i in range(n):
	x = int(s[i])
	y = int(s[i + 1])
	if x < y:
		a.append(2)
	if x == y:
		a.append(1)
	if x > y:
		a.append(0)
a.append(0)
ans = True
for i in range(n):
	if a[i] < a[i + 1]:
		ans = False
if ans:
	print('YES')
else:
	print('NO')


def solve(len_arr, arr):
	if len_arr == 1:
		return 'YES'
	i = 0
	state = -1
	if arr[i] < arr[i + 1]:
		state = 1
	elif arr[i] == arr[i + 1]:
		state = 2
	else:
		state = 3
	while i < len_arr - 1:
		if state == 1:
			if arr[i] == arr[i + 1]:
				state = 2
			elif arr[i] > arr[i + 1]:
				state = 3
		elif state == 2:
			if arr[i] > arr[i + 1]:
				state = 3
			elif arr[i] < arr[i + 1]:
				return 'NO'
		elif state == 3:
			if not arr[i] > arr[i + 1]:
				return 'NO'
		i += 1
	return 'YES'
len_arr = int(input())
arr = list(map(int, input().split()))
print(solve(len_arr, arr))


import sys
n = sys.stdin.readline()
while n:
	arr = [int(val) for val in sys.stdin.readline().split()]
	ans = ''
	if len(arr) == 1:
		ans = 'YES'
	else:
		err = False
		if arr[0] < arr[1]:
			status = 'i'
			for i in range(1, len(arr) - 1):
				if arr[i] < arr[i + 1]:
					if status == 'r' or status == 'd':
						err = True
						break
					else:
						status = 'i'
				if arr[i] == arr[i + 1]:
					if status == 'd':
						err = True
						break
					else:
						status = 'r'
				if arr[i] > arr[i + 1]:
					status = 'd'
		elif arr[0] == arr[1]:
			status = 'r'
			for i in range(1, len(arr) - 1):
				if arr[i] < arr[i + 1]:
					if status == 'r' or status == 'd':
						err = True
						break
					else:
						status = 'i'
				if arr[i] == arr[i + 1]:
					if status == 'd':
						err = True
						break
					else:
						status = 'r'
				if arr[i] > arr[i + 1]:
					status = 'd'
		else:
			status = 'd'
			for i in range(1, len(arr) - 1):
				if arr[i] < arr[i + 1]:
					if status == 'r' or status == 'd':
						err = True
						break
					else:
						status = 'i'
				if arr[i] == arr[i + 1]:
					if status == 'd':
						err = True
						break
					else:
						status = 'r'
				if arr[i] > arr[i + 1]:
					status = 'd'
		if err:
			ans = 'NO'
		elif status == 'r' and arr[-2] < arr[-1]:
			ans = 'NO'
		elif status == 'd' and arr[-2] <= arr[-1]:
			ans = 'NO'
		else:
			ans = 'YES'
	print(ans)
	n = sys.stdin.readline()


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import re

def tup():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
from math import log2, sqrt
from collections import defaultdict
(n, ls) = (I(), lint())
i = 0
while i < n - 1 and ls[i] < ls[i + 1]:
	i += 1
while i < n - 1 and ls[i] == ls[i + 1]:
	i += 1
while i < n - 1 and ls[i] > ls[i + 1]:
	i += 1
if i == n - 1:
	print('YES')
else:
	print('NO')


n = int(input())
string = input()
numbers = list(map(int, string.split()))
results = 'NO'
(a, b) = (numbers[:-1], n)
for x in range(n - 1):
	if not numbers[x] < numbers[x + 1]:
		a = numbers[x]
		b = x
		break
c = n
for x in range(b, n):
	if not numbers[x] == a:
		c = x
		d = numbers[x]
		break
results = 'YES'
if c != n:
	if numbers[c] < a:
		for x in range(c, n - 1):
			if not numbers[x] > numbers[x + 1]:
				results = 'NO'
				break
	else:
		results = 'NO'
print(results)


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
n = ri()
aa = rl()
ans = 'YES'
if n > 1:
	for i in range(n - 1):
		if aa[i + 1] <= aa[i]:
			end_up = i
			break
	else:
		end_up = n - 1
		start_down = n - 1
	for i in range(end_up, n - 1):
		if aa[i + 1] != aa[i]:
			start_down = i
			break
	else:
		start_down = n - 1
	for i in range(start_down, n - 1):
		if aa[i + 1] >= aa[i]:
			ans = 'NO'
			break
print(ans)


n = int(input())
asc = con = desc = False
ans = 'YES'
nums = list(map(int, input().split()))
for i in range(1, n):
	if nums[i] > nums[i - 1]:
		asc = True
		if desc or con:
			ans = 'NO'
			break
	elif nums[i] == nums[i - 1]:
		con = True
		if desc:
			ans = 'NO'
			break
	else:
		desc = True
print(ans)


import sys

def isUnimodal(size, arr):
	if size == 1:
		return True
	count = 1
	isUnimodal = True
	case = 1
	while count < size:
		num = arr[count]
		if case == 1:
			if arr[count - 1] >= arr[count]:
				case = 2
				continue
		elif case == 2:
			if arr[count - 1] != arr[count]:
				case = 3
				continue
		elif case == 3:
			if arr[count - 1] <= arr[count]:
				isUnimodal = False
				break
		count += 1
	return isUnimodal
arr_input = list(map(int, sys.stdin.read().split()))
isUnimodal = isUnimodal(arr_input[0], arr_input[1:])
print('YES' if isUnimodal else 'NO')


from sys import stdin, stdout
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
label = 1
current = 1
for i in range(1, n):
	if values[i] > values[i - 1] and current != 1:
		label = 0
	elif values[i] == values[i - 1]:
		if current == 1:
			current = 2
		elif current == 3:
			label = 0
	elif values[i] < values[i - 1]:
		current = 3
if label:
	stdout.write('YES')
else:
	stdout.write('NO')


n = int(input())
nums = [int(ch) for ch in input().split()]

def t(m, n, flag):
	if flag == 1:
		return m < n
	elif flag == 2:
		return m == n
	else:
		return m > n

def is_array_modal(ls):
	flag = 1
	n = len(ls)
	for i in range(1, n):
		if t(ls[i - 1], ls[i], flag):
			continue
		else:
			if flag == 3:
				return 'NO'
			flag += 1
			if t(ls[i - 1], ls[i], flag):
				continue
			else:
				if flag == 3:
					return 'NO'
				flag += 1
				if t(ls[i - 1], ls[i], flag):
					continue
				else:
					return 'NO'
	return 'YES'
print(is_array_modal(nums))


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


import math
length = int(input())
array = list(map(int, input().split()))
cur = 2
for each in range(1, length):
	dif = array[each] - array[each - 1]
	if (cur == 2 or cur == 1) and dif > 0:
		cur = 1
	elif (cur == 2 or cur == 1 or cur == 0) and dif == 0:
		cur = 0
	elif (cur == 2 or cur == 0 or cur == -1 or (cur == 1)) and dif < 0:
		cur = -1
	else:
		cur = 3
		break
if cur == 3:
	print('NO')
else:
	print('YES')


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

def increase(l, r):
	result = True
	for i in range(l + 1, r):
		if a[i - 1] >= a[i]:
			result = False
	return result

def stability(l, r):
	result = True
	for i in range(l + 1, r + 1):
		if a[i - 1] != a[i]:
			result = False
	return result and (a[l - 1] < a[l] if l > 0 else True) and (a[r] > a[r + 1] if r + 1 < n else True)

def decrease(l, r):
	result = True
	for i in range(l + 1, r):
		if a[i - 1] <= a[i]:
			result = False
	return result
for r in range(n):
	for l in range(r + 1):
		if increase(0, l) and stability(l, r) and decrease(r, n):
			print('YES')
			exit()
print('NO')


def main():
	n = int(input())
	lst = list(map(int, input().split()))
	state = None
	for i in range(1, n):
		if not state:
			if lst[i] < lst[i - 1]:
				state = -1
			elif lst[i] > lst[i - 1]:
				state = 1
			else:
				state = 2
		elif state == 1:
			if lst[i] == lst[i - 1]:
				state = 2
			elif lst[i] < lst[i - 1]:
				state = -1
		elif state == 2:
			if lst[i] > lst[i - 1]:
				return 'NO'
			elif lst[i] < lst[i - 1]:
				state = -1
		elif state == -1:
			if lst[i] > lst[i - 1] or lst[i] == lst[i - 1]:
				return 'NO'
	return 'YES'
print(main())


def main():
	n = int(input())
	L = [int(x) for x in input().split()]
	if isUnimodal(L):
		print('YES')
	else:
		print('NO')

def isUnimodal(L):
	for i in range(len(L) - 1):
		if L[i] == L[i + 1]:
			for j in range(i + 1, len(L) - 1):
				if L[j] < L[j + 1]:
					return False
				elif L[j] > L[j + 1]:
					return isDecreasing(L[j + 1:])
			return True
		elif L[i] > L[i + 1]:
			return isDecreasing(L[i + 1:])
	return True

def isDecreasing(L):
	for i in range(len(L) - 1):
		if L[i] <= L[i + 1]:
			return False
	return True
main()


def main(n, lst):
	if n == 1:
		return 'YES'
	if lst[0] < lst[1]:
		status = 0
	elif lst[0] == lst[1]:
		status = 1
	else:
		status = 2
	for i in range(len(lst) - 1):
		if status == 0:
			if lst[i] == lst[i + 1]:
				status += 1
			if lst[i] > lst[i + 1]:
				status += 2
		if status == 1:
			if lst[i] > lst[i + 1]:
				status += 1
			if lst[i] < lst[i + 1]:
				return 'NO'
		if status == 2:
			if lst[i] > lst[i + 1]:
				pass
			else:
				return 'NO'
	return 'YES'
n = eval(input())
lst = input().split()
lst = [eval(i) for i in lst]
print(main(n, lst))


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


def check(a):
	state = 1
	res = 'YES'
	for i in range(len(a) - 1):
		f = a[i]
		last = a[i + 1]
		if state == 1:
			if last == f:
				state = 0
			elif last < f:
				state = -1
		if state == 0:
			if f < last:
				res = 'NO'
			elif f > last:
				state = -1
		if state == -1:
			if last >= f:
				res = 'NO'
	print(res)

def main():
	try:
		input()
		astr = input()
		aa = astr.split(' ')
		a = []
		for i in range(len(aa)):
			a.append(int(aa[i]))
		check(a)
		main()
	except:
		print()
main()


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


a = int(input())
b = list(map(int, input().split()))
h = 'YES'
count = 0
k = '*'
if len(set(b)) == 1:
	h = 'YES'
	k = ''
else:
	for i in range(1, a):
		if b[i - 1] < b[i] and count == 0 and (k == '*'):
			count = 0
			k = ''
		elif b[i - 1] < b[i] and count == 0:
			count = 0
		elif count == 0 and b[i - 1] == b[i]:
			count = 1
			k = ''
		elif count == 1 and b[i - 1] == b[i]:
			count = 1
			k = ''
		elif count == 0 and b[i - 1] > b[i]:
			count = 3
			k = ''
		elif count == 1 and b[i - 1] > b[i]:
			count = 3
			k = ''
		elif count == 3 and b[i - 1] > b[i]:
			count = 3
			k = ''
		else:
			h = 'NO'
			break
if k == '*':
	h = 'NO'
print(h)


n = int(input())
arr = [int(i) for i in input().split()]
L = 0
R = n - 2
prev = arr[0]
last = arr[n - 1]
if n == 1:
	print('YES')
	exit()
while L < n - 1 and arr[L + 1] > prev:
	L += 1
	prev = arr[L]
while R >= 0 and arr[R] > last:
	last = arr[R]
	R -= 1
for el in range(L, R + 1):
	if arr[el] != arr[el + 1]:
		print('NO')
		exit()
print('YES')


def check_constant(num_lst):
	return num_lst == [l for l in num_lst if l == num_lst[0]]

def check_increasing(num_lst):
	if num_lst == sorted(num_lst):
		for i in range(len(num_lst) - 1):
			if num_lst[i] == num_lst[i + 1]:
				return num_lst[i:] == [n for n in num_lst[i:] if n == num_lst[i]]
		else:
			return True
	else:
		return False

def check_decreasing(num_lst):
	if num_lst == sorted(num_lst, reverse=True):
		num_lst.sort()
		for i in range(len(num_lst) - 1):
			if num_lst[i] == num_lst[i + 1]:
				return num_lst[i:] == [n for n in num_lst[i:] if n == num_lst[i]]
		else:
			return True
	else:
		return False

def check_complete(num_lst):
	lrgst_num = num_lst.index(max(num_lst))
	return check_increasing(num_lst[:lrgst_num + 1]) and check_decreasing(num_lst[lrgst_num:])
n = int(input())
numbers = list(map(int, input().split()[:n]))
if check_constant(numbers) or check_increasing(numbers) or check_decreasing(numbers) or check_complete(numbers):
	print('YES')
else:
	print('NO')


_ = input()
A = list(map(int, input().split()))
if len(A) == 1:
	print('YES')
else:
	increasing = False
	decreasing = True
	decreasingStarted = False
	correct = True
	if A[0] < A[1]:
		increasing = True
	for i in range(len(A) - 1):
		if A[i] < A[i + 1]:
			if not increasing or decreasingStarted:
				print('NO')
				correct = False
				break
		elif A[i] == A[i + 1]:
			if decreasingStarted:
				print('NO')
				correct = False
				break
			increasing = False
		else:
			decreasingStarted = True
			if decreasing:
				decreasing = False
	if correct:
		print('YES')


quantity = int(input())
alist = list(map(int, input().split()))
result = 'YES'
idx = 0
if quantity == 3:
	if alist[idx] > alist[idx + 1]:
		while idx < quantity - 2:
			idx += 1
			if alist[idx] == alist[idx + 1] or alist[idx] < alist[idx + 1]:
				result = 'NO'
				break
		print(result)
	elif alist[idx] < alist[idx + 1]:
		while idx < quantity - 2:
			idx += 1
			if alist[idx] > alist[idx + 1]:
				while idx < quantity - 2:
					idx += 1
				if alist[idx] == alist[idx + 1] or alist[idx] < alist[idx + 1]:
					result = 'NO'
					break
			if alist[idx] == alist[idx + 1]:
				while idx < quantity - 2:
					idx += 1
					if alist[idx] < alist[idx + 1]:
						result = 'NO'
						break
					if alist[idx] > alist[idx + 1]:
						while idx < quantity - 2:
							idx += 1
							if alist[idx] == alist[idx + 1] or alist[idx] < alist[idx + 1]:
								result = 'NO'
								break
		print(result)
	elif alist[idx] == alist[idx + 1]:
		while idx < quantity - 2:
			idx += 1
			if alist[idx] > alist[idx + 1]:
				while idx < quantity - 2:
					idx += 1
					if alist[idx] == alist[idx + 1] or alist[idx] < alist[idx + 1]:
						result = 'NO'
						break
			if alist[idx] < alist[idx + 1]:
				result = 'NO'
				break
		print(result)
elif quantity == 2:
	print('YES')
elif quantity == 1:
	print('YES')
elif quantity > 3:
	if alist[idx] > alist[idx + 1]:
		while idx < quantity - 2:
			idx += 1
			if alist[idx] < alist[idx + 1] or alist[idx] == alist[idx + 1]:
				result = 'NO'
		print(result)
	elif alist[idx] == alist[idx + 1]:
		idx += 1
		while idx < quantity - 1:
			if alist[idx] == alist[idx + 1]:
				idx += 1
			elif alist[idx] < alist[idx + 1]:
				result = 'NO'
				break
			elif alist[idx] > alist[idx + 1]:
				while idx < quantity - 2:
					idx += 1
					if alist[idx] == alist[idx + 1]:
						result = 'NO'
						break
					elif alist[idx] < alist[idx + 1]:
						result = 'NO'
						break
				break
		print(result)
	elif alist[idx] < alist[idx + 1]:
		idx += 1
		while idx < quantity - 1:
			if alist[idx] == alist[idx + 1]:
				idx += 1
				while idx < quantity - 1:
					if alist[idx] == alist[idx + 1]:
						idx += 1
					elif alist[idx] < alist[idx + 1]:
						result = 'NO'
						break
					elif alist[idx] > alist[idx + 1]:
						while idx < quantity - 2:
							idx += 1
							if alist[idx] == alist[idx + 1]:
								result = 'NO'
								break
							elif alist[idx] < alist[idx + 1]:
								result = 'NO'
								break
						break
				break
			elif alist[idx] < alist[idx + 1]:
				idx += 1
			elif alist[idx] > alist[idx + 1]:
				while idx < quantity - 1:
					if alist[idx] > alist[idx + 1]:
						idx += 1
					else:
						result = 'NO'
						break
		print(result)


n = int(input())
c = False
k = 0
p = 0
l_n = list(map(int, input().split()))
for n in l_n:
	if not c and n == p:
		k = n
		c = True
	if not c and n < p:
		c = True
	elif c and n > p:
		print('NO')
		quit()
	elif c and n == p and (n != k):
		print('NO')
		quit()
	p = n
print('YES')


n = int(input())
a = [int(i) for i in 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
i += 1
print(['YES', 'NO'][i != n])


import sys
m = input()
n = input()
l = n.split(' ')
l.append('1061109567')
i = 1
while int(l[i]) - int(l[i - 1]) > 0:
	if int(i) == int(m):
		break
	i = i + 1
while int(l[i]) - int(l[i - 1]) == 0:
	if int(i) == int(m):
		break
	i = i + 1
while int(l[i]) - int(l[i - 1]) < 0:
	if int(i) == int(m):
		break
	i = i + 1
if i == int(m):
	print('YES')
else:
	print('NO')


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


n = int(input())
l = list(map(int, input().split(' ')))
center = max(l)
inc = False
middle = False
dec = False
flag = False
for i in range(n - 1):
	if l[i] == l[i + 1] and l[i] == center:
		middle = True
		continue
	if l[i] <= l[i + 1] and middle:
		print('NO')
		flag = True
		break
	if l[i] == center:
		middle = True
	if l[i] >= l[i + 1] and (not middle):
		print('NO')
		flag = True
		break
if not flag:
	print('YES')


def main():
	size = int(input())
	array = [int(x) for x in input().split(' ')]
	has_constant = False
	has_fall = False
	for i in range(len(array) - 1):
		(a, b) = (array[i], array[i + 1])
		if a < b and (not has_fall) and (not has_constant):
			continue
		if a > b:
			has_fall = True
			continue
		if a == b and (not has_fall):
			has_constant = True
			continue
		return 'NO'
	return 'YES'
print(main())


n = int(input())
if n == 1:
	print('YES')
	exit()
(grow, const, down) = [False] * 3
array_data = list(map(int, input().split()))[:n]
array_data.append(0)
i = 0
while array_data[i] < array_data[i + 1] and i < n - 1:
	i += 1
while array_data[i] == array_data[i + 1] and i < n - 1:
	i += 1
while array_data[i] > array_data[i + 1] and i < n - 1:
	i += 1
if i == n - 1:
	print('YES')
else:
	print('NO')


N = int(input())
Numbers = list(map(int, input().split()))
if N == 1:
	print('YES')
	exit()
i = 1
while i < N and Numbers[i - 1] < Numbers[i]:
	i += 1
while i < N and Numbers[i] == Numbers[i - 1]:
	i += 1
Rest = Numbers[i - 1:]
if len(set(Rest)) == len(Rest) and sorted(Rest, reverse=True) == Rest:
	print('YES')
	exit()
print('NO')


n = int(input())
a = list(map(int, input().split()))
m = max(a)
mi = a.index(m)
for i in range(mi, n):
	if a[mi] == m:
		a.pop(mi)
print('YES' if len(set(a[:mi])) == len(a[:mi]) and len(set(a[mi:])) == len(a[mi:]) and (sorted(a[:mi]) == a[:mi]) and (sorted(a[mi:], reverse=True) == a[mi:]) else 'NO')


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


len = int(input())
arr = list(map(int, input().split()))
inc = const = dec = unimodal = True
for i in range(0, len - 1):
	if arr[i] < arr[i + 1] and inc:
		pass
	elif arr[i] == arr[i + 1] and const:
		inc = False
	elif arr[i] > arr[i + 1] and dec:
		inc = const = False
	else:
		dec = unimodal = False
if unimodal:
	print('YES')
else:
	print('NO')


n = int(input())
lst = [int(i) for i in input().split()]
nd = 0
if n == 1:
	print('YES')
else:
	if lst[0] < lst[1]:
		nd = 1
	elif lst[0] == lst[1]:
		nd = 0
	else:
		nd = -1
	nk = 0
	for i in range(1, n - 1):
		if nd == 1 and lst[i] < lst[i + 1]:
			nd = 1
		elif (nd == 0 or nd == 1) and lst[i] == lst[i + 1]:
			nd = 0
		elif (nd == 0 or nd == -1 or nd == 1) and lst[i] > lst[i + 1]:
			nd = -1
		else:
			nk = 1
			break
	if nk == 0:
		print('YES')
	else:
		print('NO')


import collections
import functools
import math
import sys

def In():
	return map(int, sys.stdin.readline().split())
input = sys.stdin.readline
import functools
import math
import sys

def In():
	return map(int, sys.stdin.readline().split())
input = sys.stdin.readline

def imar():
	n = int(input())
	flag = 1
	last = -1
	for i in input().split():
		i = int(i)
		if last == -1:
			last = i
		else:
			if (flag == -1 or not flag) and last < i:
				return 'NO'
			if flag == 1:
				if last == i:
					flag = 0
				if last > i:
					flag = -1
			elif flag == -1:
				if last == i:
					return 'NO'
			elif last > i:
				flag = -1
			last = i
	return 'YES'
print(imar())