There are $n$ pillars aligned in a row and numbered from $1$ to $n$.

Initially each pillar contains exactly one disk. The $i$-th pillar contains a disk having radius $a_i$.

You can move these disks from one pillar to another. You can take a disk from pillar $i$ and place it on top of pillar $j$ if all these conditions are met:

  there is no other pillar between pillars $i$ and $j$. Formally, it means that $|i - j| = 1$;  pillar $i$ contains exactly one disk;  either pillar $j$ contains no disks, or the topmost disk on pillar $j$ has radius strictly greater than the radius of the disk you move. 

When you place a disk on a pillar that already has some disks on it, you put the new disk on top of previously placed disks, so the new disk will be used to check the third condition if you try to place another disk on the same pillar.

You may take any disk and place it on other pillar any number of times, provided that every time you do it, all three aforementioned conditions are met. Now you wonder, is it possible to place all $n$ disks on the same pillar simultaneously?


-----Input-----

The first line contains one integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of pillars.

The second line contains $n$ integers $a_1$, $a_2$, ..., $a_i$ ($1 \le a_i \le n$), where $a_i$ is the radius of the disk initially placed on the $i$-th pillar. All numbers $a_i$ are distinct.


-----Output-----

Print YES if it is possible to place all the disks on the same pillar simultaneously, and NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).


-----Examples-----
Input
4
1 3 4 2

Output
YES

Input
3
3 1 2

Output
NO



-----Note-----

In the first case it is possible to place all disks on pillar $3$ using the following sequence of actions:

  take the disk with radius $3$ from pillar $2$ and place it on top of pillar $3$;  take the disk with radius $1$ from pillar $1$ and place it on top of pillar $2$;  take the disk with radius $2$ from pillar $4$ and place it on top of pillar $3$;  take the disk with radius $1$ from pillar $2$ and place it on top of pillar $3$.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
idx = list(range(n))
idx.sort(key=lambda i: a[i], reverse=True)
imin = imax = idx[0]
for i in idx[1:]:
    if i == imin - 1 or i == imax + 1:
        imin = min(imin, i)
        imax = max(imax, i)
    else:
        print('NO')
        return
print('YES')


import sys

n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
i = a.index(max(a))
v = True
for j in range (0, i):
    if a[j] > a[j+1]:
        v = False
for j in range (i, n-1):
    if a[j] < a[j+1]:
        v = False
if v == True:
    print("YES")
else:
    print("NO")

def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = list(map(int, input().split()))
    idx = arr.index(n)
    ok = 1
    for i in range(1, idx):
        if arr[i] < arr[i - 1]:
            ok = 0
    for i in reversed(range(idx, n - 1)):
        if arr[i] < arr[i + 1]:
            ok = 0
    if ok:
        print("YES")
    else:
        print("NO")
    
    return 0

main()

n = int(input())
arr = [int(x) for x in input().split()]
x = arr.index(max(arr))
cur = max(arr)
l = x - 1
r = x + 1
ok = 1
for i in range(n - 1):
    if l < 0:
        ok *= (arr[r] < cur)
        cur = arr[r]
        r += 1
    elif r >= n:
        ok *= (arr[l] < cur)
        cur = arr[l]
        l -= 1
    else:
        if arr[l] > arr[r]:
            ok *= (arr[l] < cur)
            cur = arr[l]
            l -= 1
        else:
            ok *= (arr[r] < cur)
            cur = arr[r]
            r += 1
print("YES" if ok else "NO")

n=int(input())
arr=list(map(int,input().split()))
maxval=max(arr)
maxindex=-1
for i in range(n):
	if(arr[i]==maxval):
		maxindex=i
		break

flag=0
temp=maxval
for i in range(maxindex-1,-1,-1):
	if(temp<=arr[i]):
		flag=1
		break
	else:
		temp=arr[i]

temp=maxval
for i in range(maxindex+1,n):
	if(arr[i]>=temp):
		flag=1
		break
	else:
		temp=arr[i]

if(flag==0):
	print("YES")
else:
	print("NO")


n = int(input())
a = list(map(int,input().split()))
fl = False
ans = True
for i in range(n-1):
    if a[i+1]>a[i]:
        if fl:
            ans = False
    else:
        fl = True
if ans:
    print('YES')
else:
    print('NO')

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

c = 0

for i in range(1, n-1):
    if a[i] > a[i-1] and a[i] > a[i+1]:
        c +=1
    if a[i] == a[i-1] or a[i] == a[i+1]:
        print('NO')
        return
    if a[i] <= a[i-1] and a[i] <= a[i+1]:
        print('NO')
        return
if c>1:
    print('NO')
else:
    print('YES')

n = int(input())
a = list(map(int,input().split()))
rev = [-1] * (n + 1)
for i, j in enumerate(a):
    rev[j] = i

mx = max(a)

# [l, r]
l = a.index(mx)
r = l

for i in range(n - 1, 0, -1):
    idx = rev[i]
    if idx == l - 1:
        l -= 1
    elif idx == r + 1:
        r += 1
    else:
        print('NO')
        return
print('YES')

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

n = int(input())
a = list(map(int, input().split()))
s = sorted(a)
q = a.index(max(a))
q1, q = min(len(a)-1, q+1), max(0, q-1)
for q2 in range(len(a)-2, -1, -1):
    if a[q] == s[q2]:
        q = max(0, q-1)
    elif a[q1] == s[q2]:
        q1 = min(len(a)-1, q1+1)
    else:
        print("NO")
        break
else:
    print("YES")


t=int(input())
g=list(map(int,input().split()))
k=max(g)
flag=True
i=0
while g[i]!=k:
    if i!=0 and g[i]<g[i-1]:
        print("NO")
        return
    i+=1
i+=1
while i<t and g[i]!=k:
    if i!=0 and g[i]>g[i-1]:
        print("NO")
        return
    i+=1
print("YES")

n = int(input())
a = list(map(int, input().split()))
idx = a.index(max(a))
for i in range(idx, 0, -1):
	if a[i] < a[i - 1]:
		print('NO')
		return
for i in range(idx, n - 1):
	if a[i] < a[i + 1]:
		print('NO')
		return
print('YES')

n = int(input())
l = [*list(map(int, input().split()))]
i = l.index(n)
left, right = i - 1, i + 1
cur = n - 1
while left >= 0 or right < n:
    if left >= 0 and l[left] == cur:
        left -= 1
        cur -= 1
    elif right < n and l[right] == cur:
        right += 1
        cur -= 1
    else:
        print("NO")
        return
print("YES")


n = int( input() )
a = list( map( int, input().split() ) )
i = a.index( max( a ) )
f = True
j = i + 1
while j < n:
    if a[ j ] >= a[ j - 1 ]:
        f = False
    j += 1

j = i - 1
while j >= 0:
    if a[ j ] >= a[ j + 1 ]:
        f = False
    j -= 1

print( "YES" if f else "NO" )



n = int(input())
li = list(map(int, input().split()))
x = li.index(max(li))
if li[:x] == sorted(li[:x]) and li[x:] == sorted(li[x:])[::-1]:
    print("YES")
else:
    print("NO")

n = int(input())
arr = list(map(int,input().split()))
maxa= max(arr)
maxi = arr.index(maxa)
flag=0
for i in range(maxi):
	if arr[i]>=arr[i+1]:
		flag=1
		break
if flag==1:
	print("NO")
else:
	flag = 0
	for i in range(maxi+1,n):
		if arr[i]>=arr[i-1]:
			flag=1
			break
	if flag==1:
		print("NO")
	else:
		print("YES")

n = int(input().strip())
nums = list(map(int, input().strip().split()))
has_dups = (len(nums) > len(set(nums)))
mx = nums.index(max(nums))
if has_dups or nums[:mx+1]!=sorted(nums[:mx+1]) or nums[mx:]!=sorted(nums[mx:], reverse=True):
    print("NO")
else:
    print("YES")

a = int(input())
b = list(map(int,input().split()))
d = set(b)
if len(d) != a:
    print('NO')
    return
ima = 0
for i in range(a):
    if b[ima] < b[i]:
        ima = i
for i in range(1, ima):
    if b[i] < b[i - 1]:
        print('NO')
        return
for i in range(ima, a - 1):
    if b[i] < b[i + 1]:
        print('NO')
        return
print('YES')


n = int(input())
data = [int(i) for i in input().split()]
ind = [0] * (n+1)
for i in range(n):
    ind[data[i]] = i
li = ind[n] - 1
ri = ind[n] + 1
good = True
for i in range(n - 1, 0, -1):
    if ind[i] == ri:
        ri += 1
        continue
    if ind[i] == li:
        li -= 1
        continue
    good = False
    break
if good:
    print("YES")
else:
    print("NO")

n = int(input())
array = list(map(int, input().split()))
ind = array.index(max(array))
i, j = ind - 1, ind + 1
now = array[ind]
while i != -1 or j != n:
    if i == -1:
        if array[j] < now:
            now = array[j]
            j += 1
        else:
            print('NO')
            return
    elif j == n:
        if array[i] < now:
            now = array[i]
            i -= 1
        else:
            print('NO')
            return
    else:
        if array[i] > array[j]:
            if array[i] < now:
                now = array[i]
                i -= 1
            else:
                print('NO')
                return
        else:
            if array[j] < now:
                now = array[j]
                j += 1
            else:
                print('NO')
                return
print('YES')

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
aa = inpl()

maxi = aa.index(N)

for i in range(maxi,N-1):
    if aa[i] < aa[i+1]:
        print('NO')
        return

for i in reversed(list(range(0,maxi))):
    if aa[i] > aa[i+1]:
        print('NO')
        return

print('YES')