Problem:
 Score : 300 points    Problem Statement There are N squares arranged in a row from left to right. The height of the i -th square from the left is H_i .  For each square, you will perform either of the following operations once:   Decrease the height of the square by 1 .  Do nothing.   Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.      Constraints  All values in input are integers.  1 \leq N \leq 10^5  1 \leq H_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  H_1  H_2  ...  H_N       Output If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes ; otherwise, print No .        Sample Input 1 5
1 2 1 1 3      Sample Output 1 Yes  You can achieve the objective by decreasing the height of only the second square from the left by 1 .       Sample Input 2 4
1 3 2 1      Sample Output 2 No       Sample Input 3 5
1 2 3 4 5      Sample Output 3 Yes       Sample Input 4 1
1000000000      Sample Output 4 Yes

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

up = 0
flag = 1
for i in range(n-1):
    ma = h[i]+up
    if ma<=h[i+1]:
        up = 0
    elif ma<=h[i+1]+1:
        up = 1
    else:
        flag = 0
        break

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

flag = True

for i in range(1,len(H)):
    if H[i-1] > H[i]:
        H[i] += 1

    if H[i-1] > H[i]:
        flag = False
        break
        
        
if flag == True:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
hs=list(map(int,input().split()))
mx=0
for h in hs:
    if h+1<mx:
        print("No")
        exit()
    if h>mx:
        mx=h
print("Yes")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n):
    if a[i-1]<a[i]:
        a[i]-=1
    if a[i-1]>a[i]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import sys

N = int(input())
H = list(map(int,input().split()))

if N == 1:
    print("Yes")
    sys.exit()
if H[0] >= H[1]:
    H[0] -= 1
if H[0] > H[1]:
    print("No")
else:
    for i in range(1, N-1):
        H[i] -= 1
        if H[i-1] <= H[i] and H[i] <= H[i+1]:
            continue
        else:
            H[i] += 1
        if H[i-1] <= H[i] and H[i] <= H[i+1]:
            continue
        else:
            print("No")
            sys.exit()
    print("Yes")

Solution (Python):
N = int(input())
heights = [int(i) for i in input().split()]
ans = "Yes"
minv = heights[0]
for i in range(N):
    if 1 < minv - heights[i]:
        ans = "No"
        break
    minv = max(minv,heights[i])
print(ans)

Solution (Python):
n = int(input())
h = [int(x) for x in input().split()]
l = len(h)
h.append(10 ** 9 + 1)
flag = 0
for i in range(l):
    if h[i] - h[i+1] > 1:
        print("No")
        exit()
    elif h[i] - h[i+1] == 1:
        if flag == 1:
            print("No")
            exit()
        else:
            flag = 1
    elif h[i] - h[i+1] < 0:
        flag = 0
print("Yes")

Solution (Python):
N = int(input())

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

H[0] -= 1

flag = True
for i in range(1, len(H)):
	if H[i] > H[i-1]:
		H[i] -= 1
	if H[i] < H[i-1]:
		flag = False
		break

if flag:
	print('Yes')
else:
	print('No')

Solution (Python):
import sys

n = int(sys.stdin.readline())
h_list = [int(x) for x in sys.stdin.readline().split()]
h_list[0] -= 1
for i in range(len(h_list)):
    if i == 0:
        continue
    try:
        if h_list[i] > h_list[i - 1]:
            h_list[i] -= 1
        elif h_list[i] == h_list[i - 1]:
            continue
        elif h_list[i] < h_list[i - 1]:
            print("No")
            sys.exit(0)
    except IndexError:
        continue
else:
    print("Yes")

Solution (Python):



def solv(n, h):
    hh = 10**9+1
    for hi in reversed(h):
        if hh >= hi:
            hh = hi
        elif hh != hi-1:
            return 'No'
    return 'Yes'


if __name__ == '__main__':

    N = int(input())
    H = list(map(int, input().split()))

    ans = solv(N, H)

    print(ans)

Solution (Python):
n=int(input())
c=list(map(int, input().split()))
max = 0

for h in c:
    if h > max:
        max = h
    elif h < max - 1:
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys


def main():
  n = int(input())
  hlist = list(map(int, input().split()))
  for i in range(n-2, -1, -1):
    if hlist[i+1] < hlist[i]:
      hlist[i] -= 1
  for prevh, h in zip(hlist, hlist[1:]):
    if prevh > h:
      print('No')
      sys.exit(0)
  print('Yes')


if __name__ == '__main__':
  main()

Solution (Python):

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



result = True
for i in range(1,N)[::-1]:
    if a[i-1]<=a[i]:
        pass
    elif a[i-1]-1==a[i]:
        a[i-1] -= 1
    else:
        result = False
        break

print("Yes" if result else "No")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
tmp = h[0]
flg = True
for i in h:
    if tmp == i:
        pass
    elif tmp < i:
        tmp = i - 1
    else:
        flg = False
        break

if flg:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
list1 = list(map(int, input().split()))
max = 0
ans = "Yes"
for i in list1:
    if max < (i-1):
        max = (i-1)
    if max > i :
        ans = "No"

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))
ans = []

for i in range(N-1,0,-1):
    if H[i] < H[i-1]:
        H[i-1] -= 1
    if H[i] < H[i-1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
N = int(input())
H = [int(_) for _ in input().split()] 

flag = True

ushiro = H[-1]
for i in H[::-1]:
   hitotsumae = i
   if hitotsumae > ushiro:
           if hitotsumae - 1 == ushiro:
                   ushiro = i -1
           else:
                   flag = False
   else:
           ushiro = i


    

if flag:
        print("Yes")
else:
        print("No")

Solution (Python):
import sys
N = int(input())
l = list(map(int, input().split()))

if N == 1:
    print("Yes")
    sys.exit()


if l[0] - l[1] > 1:
    print("No")
    sys.exit()


for i in range(1, N-1):
    if l[i] - l[i-1] >= 1:
        l[i] -= 1
    if l[i] - l[i+1] >= 1:
        print("No")
        sys.exit()

print("Yes")

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    H = list(map(int, input().split()))

    answer = 'Yes'
    for i in reversed(range(0, N-1)):
        if H[i] - H[i+1] <= 0:
            continue
        elif H[i] - H[i+1] == 1:
            H[i] = H[i] - 1
        else:
            answer = 'No'
            break
    print(answer)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
ok = False
for i in range(N-2, -1, -1):
    if H[i] <= H[i+1]:
        continue
    H[i] -= 1
    if H[i] <= H[i+1]:
        continue
    break
else:
    ok = True

print("Yes" if ok else "No")

Solution (Python):


import sys
n = int(input())
h = list(map(int, input().split()))

tmp = 0

for i in range(1, n):
    if (h[i-1]-h[i]) >= 2:
        print("No")
        sys.exit()
    elif (h[i-1]-h[i]) == 1:
        if tmp == 1:
            print("No")
            sys.exit()
        else:
            tmp = 1
    elif (h[i-1]-h[i]) < 0:
        tmp = 0
print("Yes")

Solution (Python):
N = int(input())
H = list(map(int,input().split()))

if N == 1:
  print('Yes')
  exit()

ans = 'No'
var = H[0] - 1
for i in range(1, N):
  if H[i] < var:
    break
  else:
    var = max(var, H[i]-1)
else:
  ans = 'Yes'
  
print(ans)

Solution (Python):
N = int(input())
H_list = list(map(int,input().split()))

if N ==1:
    print('Yes')
    exit(0)
h_max = H_list[1]
for i in range(1,N):
    h_max = max(H_list[i],h_max)
    if H_list[i-1] > H_list[i]:
        if H_list[i-1] == H_list[i] + 1 and h_max < H_list[i] + 2:
            continue
        else:
            print('No')
            exit(0)
print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

line = 0

for i in range(1, N):
    if H[i] < line:
        print('No')
        break
    line = max(line, H[i] - 1)
else:
    print('Yes')

Solution (Python):
def solve():
    N = int(input())
    H = map(int, input().split())
    min_h = 0
    ret = True
    for h in H:
        if min_h > h:
            ret = False
            break
        min_h = max(min_h, h-1)
    print('Yes' if ret else 'No')

solve()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

fl = 0

for i in range(n-1):
    if a[i] < a[i+1]:
        a[i+1] -= 1

    if a[i] > a[i+1]:
        print('No')
        fl = 1
        break

if fl==0:
    print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
tmp = h[-1]
for i in range(n-1)[::-1]:
	if h[i] <= tmp:
		tmp = h[i]
	elif h[i] == tmp+1:
		continue
	else:
		print("No")
		exit()
print("Yes")

Solution (Python):
N= int(input())
H=list(map(int, input().split()))
old=H[-1]
flag=0
for h in (reversed(H)):
    new = h
    if new > old:
        new=h-1
    if new > old:
        flag=1
        break
    
    old=new

if flag==0:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())

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


for i in range(n-1, 0, -1):
  if cells[i] >= cells[i-1]:
    continue
  else:
    cells[i-1] -= 1
    if cells[i] < cells[i-1]:
      print('No')
      break
else:
  print('Yes')

Solution (Python):
import sys

input = sys.stdin.readline

N = int(input().strip())
Hs = list(map(int, input().strip().split(' ')))

current_max = 0
for i in range(N - 1):
    if Hs[i] > current_max:
        Hs[i] -= 1
        current_max = Hs[i]

    if Hs[i] > Hs[i+1]:
        print('No')
        sys.exit(0)

print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split(" ")))
memo = [0] * N

for i in range(N):
  if i == 0:
    memo[i] = H[i] - 1
    continue
  if H[i] >= H[i - 1]:
    memo[i] = max(H[i] - 1, memo[i - 1])
    continue
  else:
    if H[i - 1] - H[i] > 1:
      print("No")
      break
    if H[i] < memo[i - 1]:
      print("No")
      break
    memo[i] = max(H[i] - 1, memo[i - 1])
else:
  print("Yes")

Solution (Python):
n=int(input())
i=0
s=[]
s=list(map(int,input().split(" ")))

ans=1
i=1
while i!=n:
    if s[i]>s[i-1]:
        s[i]=s[i]-1
    if s[i]<s[i-1]:
        ans=0
    i+=1
if ans==1:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

ans = "Yes"
for i in range(n - 1, 0, -1):
    if h[i - 1] - 1 == h[i]:
       h[i - 1] -= 1
    elif h[i - 1] > h[i]:
       ans = "No"
       break
print(ans)

Solution (Python):
N = int(input())
Hn = list(map(int,input().split()))
check = True
kijyun = Hn[0]
for i in range(1,N):
    if Hn[i]-Hn[i-1]<-1:
        check=False
        break
    elif Hn[i]-kijyun<-1:
        check=False
        break
    kijyun = max(kijyun,Hn[i])
if check:
    print("Yes")
else:
    print("No")

Solution (Python):
def main():
    n = int(input())
    h = list(map(int, input().split()))

    for i in range(1, n):
        if h[i-1] < h[i]:
            h[i] -= 1
        elif h[i-1] == h[i]:
            pass
        else:
            print('No')
            return
    print('Yes')


main()

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
H=LIST()+[INF]

for i in range(N-2, -1, -1):
    if H[i]>H[i+1]:
        H[i]-=1

for i in range(N-1):
    if H[i]>H[i+1]:
        No()
        exit()
Yes()

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
minh=h[n-1]

for i in range(n-1,-1,-1):
  
    minh=min(minh,h[i])
    if h[i]-minh>1.1:
        ans="No"
        break
    
print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

is_fail = False

for i in list(range(1, N))[::-1]:
    if H[i-1] <= H[i]:
        continue
    elif H[i-1] == H[i] + 1:
        H[i-1]  -= 1
    if H[i-1] > H[i]:
        is_fail = True
        break

if not is_fail:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
H = list(map(int, input().split()))
for i in reversed(range(1, n)):
    if H[i-1] - H[i] > 1:
        print("No")
        exit()
    else:
        if H[i-1] - H[i] == 1:
            H[i-1] -= 1
print("Yes")

Solution (Python):
def debug(*args):
    if 1 == 1:
        print(*args)

def solve(N, A):
    A[0] -= 1
    for i in range(1, N):
        if A[i-1] <= A[i] - 1: 
            A[i] -= 1
        if A[i-1] > A[i]:
            return "No"
    return "Yes"

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(N, A))

main()

Solution (Python):
N = int(input())
H  = [int(x) for x in input().split()]

for i in range(N-1):
  if H[i+1]>H[i]:
    H[i+1] -= 1
  if H[i+1] < H[i]:
    print("No")
    exit()
print("Yes")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
mm = h[0]
for i in range(1,n):
    if mm > h[i]:
        print("No")
        exit()
    mm = max(mm, h[i]-1)
print("Yes")

Solution (Python):
n=int(input())
h=list(map(int,input().split()))

for i in range(1,n):
    if h[i]>h[i-1]:
        h[i]-=1
    elif h[i]==h[i-1]:
        continue
    else:
        print('No')
        exit()
print("Yes")

Solution (Python):
import sys
n = int(input())
row = list(map(int, input().split()))

left = row[0]
for r in row:
  if r-1>= left:
    left = r-1
  elif r>= left:
    left=r
  else:
    print('No')
    sys.exit(0)

print('Yes')

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
h = list(map(int, input().split()))
if len(h) == 0:
    print('Yes')
    exit()
ma = 0
ans = True
for hi in h:
    t = hi + 1
    if t < ma:
        ans = False
        break
    if ma < hi:
        ma = hi
if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())

h = []
h_li = input().split()

for i in range(n):
    h.append(int(h_li[i]))
    
ans = "Yes"

memo = 0
for i in range(n):
    if memo >= h[i] +2:
        ans = "No"
        break
    
    if memo <= h[i]:
        memo = h[i]
    
print(ans)

Solution (Python):
import sys
n = int(input())
h = list(map(int, input().split()))

for i in range(1, n):
    if h[i] > h[i-1]:
        h[i] = h[i] - 1

for i in range(1, n):
    if h[i] < h[i-1]:
        print('No')
        sys.exit()

print('Yes')

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l.reverse()
f = True

for i in range(len(l)-1):
    if l[i] < l[i+1]:
        if l[i+1] - l[i] == 1:
            l[i+1] -= 1
        else:
            f = False
            break

print("Yes" if f == True else "No")

Solution (Python):
n=int(input())
H=list(map(int,input().split()))
max_ = 1
ans = "Yes"
for h in H:
    if h < max_ - 1:
        ans = "No"
    if h > max_:
        max_ = h
print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
old = H[0]
for i in range(1, N):
    if H[i-1] > H[i] + 1:
        print("No")
        break
    else:
        if H[i-1] > H[i]:
            H[i] += 1
else:
    print("Yes")

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
n = H[N-1]
state = "Yes"
for i in range(N-1,0,-1):
    m = H[i-1]
    if n < m:
        m -= 1
        if n < m:
            state = "No"
            break
    n = m
print(state)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

t = h[n - 1]
for i in range(n - 2, -1, -1):
    if t <= h[i] - 2:
        print("No")
        exit()
    if t == h[i] - 1:
        continue
    t = h[i]

print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

ans = True

for i in range(1, N) :
    if H[i - 1] <= H[i] :
        continue
    if H[i - 1] <= H[i] + 1 :
        H[i] += 1
        continue
    ans = False

if ans :
    print('Yes')
else :
    print('No')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

now = H[-1]
ans = True
for h in H[::-1]:
    if h <= now:
        now = h
    else:
        if h-1 == now:
            now = h-1
        else:
            ans = False

if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
def int_multiple():
    return  [int(c) for c in input().split()]

def int_single():
    return int(input())

def str_multiple():
    return [c for c in input().split()]

def str_single():
    return input()




n = int_single()

h = int_multiple()

pno = False
curr_max = h[0] - 1
for i in range(1, n):
    if (h[i] < curr_max):
        pno = True
        break
    else:
        curr_max = max(h[i]-1, curr_max)

if pno:
    print("No")
else:
    print("Yes")

Solution (Python):


import os
import sys

N = int(input())

H = list(map(lambda x: int(x), input().split(" ")))




H.reverse()



res = "Yes"

for i in range(N-1):
	if H[i+1] > H[i]+1:
		res = "No"
		break
	elif H[i+1] == H[i]+1:
		H[i+1] -= 1
	else:
		pass

print(res)

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

c = 0

for i in range(n-1):
    if a[i] > a[i+1] + 1:
        print('No')
        exit()
    elif a[i] == a[i+1]+1:
        if c == 1:
            print('No')
            exit()
        c += 1
    elif a[i] < a[i+1]:
        c = 0
    elif a[i] > a[i+1]:
        c += 1
    
print('Yes')

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
for i in range(N-1,0,-1):
    if H[i-1]>H[i] and abs(H[i-1]-H[i])>1:
        print("No")
        exit()
    elif H[i-1]>=H[i] and H[i-1]-H[i]>0:
        H[i-1] -=1
    elif H[i-1]<=H[i]:
        continue
print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

min_H = 0
f = True
for i in range(N):
    if min_H > H[i]:
        f = False
        break
    else:
        if min_H < H[i]:
            min_H = H[i]-1
if f:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
block = list(map(int, input().split()))
block.reverse()
for i in range(len(block)):
    if i == len(block)-1:
        break
    if block[i] >= block[i+1]:
        continue
    elif block[i] < block[i+1] - 1:
        print("No")
        exit(0)
    else:
        block[i+1] -= 1
print("Yes")

Solution (Python):
N=int(input())
h=list(map(int,input().split()))
tmp=0
ans=True
for i in h:
    if i>tmp:
        tmp=i
    elif tmp-i>1:
        ans=False
if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
import decimal
decimal.getcontext().prec = 100
def sum1(pre,l,r):
    l=max(l,0)
    if(l==0):
        return pre[r]
    return pre[r] - pre[l - 1]

x=int(raw_input())
arr=map(int,raw_input().split())
b=[arr[0]-1]
mi=b[0]
for i in range(1,len(arr)):
    if(arr[i]-1>=mi):
        b.append(arr[i]-1)
    else:
        b.append(arr[i])
    mi=b[-1]
if b==sorted(b):
    print 'Yes'
else:
    print 'No'

Solution (Python):
N = int(input())
H = list(map(int,input().split()))

H[0] -= 1
flag = True
for i in range(1, N):
    if H[i-1] > H[i]:
        flag = False
    elif H[i-1] < H[i]:
        H[i] -= 1
    
print('Yes' if flag else 'No')

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
flag = 0
l[0] -= 1

for x in range(1, n):
    if l[x - 1] < l[x]:
        l[x] -= 1
    elif l[x - 1] > l[x]:
        flag = 1
        break

print("Yes" if (flag == 0) else "No")

Solution (Python):
n = int(input())
data = [int(x) for x in input().split(" ")]
data[0] -= 1

for i in range(n-1):
    if data[i] < data[i+1]:
        data[i+1] -= 1
    elif data[i] == data[i+1]:
        pass
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''

gi = lambda : list(map(int,input().split()))
n, = gi()
l = gi()
l[0] -= 1
for k in range(1, n):
	if l[k] > l[k - 1]:
		l[k] -= 1
	if l[k] < l[k - 1]:
		print("No")
		exit()
print("Yes")

Solution (Python):
n = int(input())
H = [int(x) for x in input().split()]
H.reverse()
ans = 'Yes'
for i in range(n-1):
  if H[i] >= H[i+1]:
    continue
  elif H[i] + 1 == H[i+1]:
    H[i+1] = H[i]
  else:
    ans = "No"
    break
print(ans)

Solution (Python):
import sys

def resolve():
    N = int(input())
    h = list(map(int, input().split()))
    tmp = h[0]
    for i in range(N):
        if tmp > h[i]:
            print('No')
            return
        if tmp == h[i]:
            continue
        tmp = h[i]-1
    print('Yes')

if __name__ == "__main__":
    resolve()

Solution (Python):
A = int(input())
x = list(map(int, input().split()))
highest=0
kotae="Yes"
for i in range(A):
    if x[i]>highest:
        highest = x[i]
    elif highest-x[i]>1:
        kotae="No"
        break
print(kotae)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

ans = "Yes"
max = h[0]

for i in range(n):
    if h[i] < max-1:
        ans = "No"
    if h[i] > max:
        max = h[i]
    

print(ans)

Solution (Python):
n = int(input())
h = list(map(int, input().split()))

if n == 1:
    print("Yes")
else:
    h[0] -= 1
    for i in range(1,n-1):
        if h[i] >= h[i+1] and h[i-1] < h[i]:
            h[i] -= 1
        
    if h == sorted(h):
        print("Yes")
    else:
        print("No")

Solution (Python):
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  
  

n = inn()
h = inl()
if n==1:
    print('Yes')
    exit()

for i in range(n-2,-1,-1):
    if h[i] > h[i+1]+1:
        print('No')
        exit()
    elif h[i] == h[i+1]+1:
        h[i] -= 1

print('Yes')

Solution (Python):
n = int(input())
h = list(map(int,input().split()))

upper = 0
for x in h:
  if upper > x:
    print('No')
    exit()
  upper = max(upper, x-1)
print('Yes')

Solution (Python):
import numpy as np

N=int(input())
H=np.array(input().split(),dtype=np.int32)

flag=True

for i in range(N-1,0,-1):
    if(H[i]>=H[i-1]):
        continue
    else:
        H[i-1]=H[i-1]-1
        if(H[i]<H[i-1]):
            flag=False

if(flag):
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))[: : -1]
temp = H[0]
for i in range(N):
  temp = min(temp, H[i])
  if abs(H[i] - temp) > 1:
    print("No")
    exit(0)
print("Yes")

Solution (Python):
n = int(input())
H = map(int, input().split())
pre = 0
result = 'Yes'
for h in H:
	if pre>h:
		result = 'No'
		break
	if pre==h:
		pre=h
		continue
	if pre<h:
		pre=h-1
		continue
print(result)

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
hhh = get_nums_l()

next = 999999999999
for i in range(n-1,-1, -1):
    now = hhh[i]
    if now > next:
        if (now - next) >= 2:
            print("No")
            exit()
        else:  
            next = now-1
    elif now == next:
        next = now
    else:
        next = now
print("Yes")

Solution (Python):
N = int(input())
h_ls = [int(i) for i in input().split()]
flg = True
for i in range(N-2, -1, -1):
    if h_ls[i] - h_ls[i + 1] > 1:
        flg = False
        break
    elif h_ls[i] - h_ls[i + 1] == 1:
        h_ls[i] -= 1
if flg:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

now = H[0] - 1
H[0] = H[0] - 1

for i in range(1, N):
    if H[i] > now:
        H[i] -= 1
    now = H[i]


for i in range(N - 1):
    if H[i + 1] >= H[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

height = H[-1]
for i in range(N-2, -1, -1):
    if H[i] <= height:
        height = H[i]
    elif H[i] == height + 1:
        pass
    else:
        print('No')
        exit()

print('Yes')

Solution (Python):
import numpy as np
import sys

N = int(input())

H = np.array(list(map(int, input().split())))

H = H[::-1]

for i in range(N-1):
    if H[i] >= H[i+1]:
        continue
    if H[i] < H[i+1]:
        H[i+1] -= 1

        if H[i] < H[i+1]:
            print('No')
            sys.exit()

print('Yes')

Solution (Python):
import sys, math
from collections import deque

readline = sys.stdin.readline

N = int(readline())
H = list(map(int, readline().split()))

H[0] -= 1
for i in range(1, N):
    if H[i] > H[i - 1]:
        H[i] -= 1
    if H[i] < H[i - 1]:
        print('No')
        exit(0)

print('Yes')

Solution (Python):
import sys


def main():
    n = int(sys.stdin.readline().strip())
    H = [int(s) for s in sys.stdin.readline().strip().split()]
    if is_possible(n, H):
        print('Yes')
    else:
        print('No')


def is_possible(n, H):
    prev = float('-inf')
    for i in range(n):
        if H[i] - 1 >= prev:
            prev = H[i] - 1
        elif H[i] >= prev:
            prev = H[i]
        else:
            return False
    return True


main()

Solution (Python):
N = int(input())
H = list(map(int, input().split()))

ans = "Yes"
for n in range(N):
    if n >= 1:
        if H[n] > H[n - 1]:
            H[n] -= 1
        if n < N-1 and H[n] > H[n + 1]:
            ans = "No"
            break

print(ans)

Solution (Python):
n = int(input())
H = list(map(int, input().split()))

ans = "Yes"
for i in reversed(range(n-1)):
    if H[i] <= H[i+1]:
        continue
    elif H[i] - H[i+1] == 1:
        H[i] -= 1
    else:
        ans = "No"
        break
    
print(ans)

Solution (Python):
N = int(input())
Hs = list(map(int, input().split()))
 
prev = Hs[0]
flag = True
for i in range(1,len(Hs)):
    if Hs[i] <prev:
      flag = False
      break
    elif Hs[i] == prev:
      prev = Hs[i]
    else:
      prev = Hs[i]-1
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))

H = H[::-1]
ans = 'Yes'
for i in range(N-1):
    
    if H[i] < H[i+1]:
        if H[i] == H[i+1] - 1:
            H[i+1] -= 1
            continue
        else:
            ans = 'No'

print(ans)

Solution (Python):
N = int(input())

if N == 1:
    print("Yes")
    exit()

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

last = -1
can_make_down = True

for h in H:
    if h > last:
        can_make_down = True
    elif h == last:
        pass
    elif h == last - 1:
        if can_make_down:
            can_make_down = False
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
        
    last = h

print("Yes")

Solution (Python):
from sys import exit
n=int(input())
h=list(map(int,input().split()))
can = True
if n==2:
    if (h[0]<=h[1]) or (h[0]-1 <= h[1]):
        print("Yes")
    else:
        print("No")
    exit()
for i in range(1,n-1):
    one = h[i-1]
    two = h[i]
    three = h[i+1]
    if (one<=two-1) and (two-1<=three):
        h[i]-=1
    elif (one<=two) and (two<=three):
        None
    else:
        print("No")
        exit()
print("Yes")

Solution (Python):



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

def rl():
    return list(input().split())

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

def main():
    n = ri()
    lh = rli()
    for i in range(len(lh)-1):
        if lh[i+1] > lh[i]:
            lh[i+1] -= 1
        if lh[i+1] < lh[i]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    hl = list(map(int, input().split()))

    if n == 1:
        print('Yes')
        return

    prev = None
    hl.reverse()
    for i in range(1, len(hl)):
        if hl[i-1] < hl[i]: 
            if hl[i-1] == hl[i] - 1:
                hl[i] = hl[i] - 1
            else:
                print('No')
                return
        else:
            continue

    print('Yes')
    return

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
Hs = list(map(int, input().split()))

for i in range(1, N):
    if Hs[N-i] >= Hs[N-i-1]:
        continue
    elif Hs[N-i-1] - Hs[N-i] >= 2:
        print("No")
        exit()
    else:
        Hs[N-i-1] -= 1
print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
before = H[0]
flag = True
magic = False
for i in range(1, N):
    now = H[i]
    if now >= before+1:
        before = now-1
        magic = True
    elif now == before:
        before = now
        magic = True
    elif now == before - 1 and magic == False:
        before = now
        magic = True
    else:
        flag = False
        break
    
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
ans = "Yes"
if n == 1:
    print(ans)
else:
    if h[0] == h[1]:
        h[0] -= 1
    
    for i in range(1,n):
        if h[i] > h[i-1]:
            h[i] -= 1
        if h[i] < h[i-1]:
            ans = "No"
            break
    print(ans)

Solution (Python):
N = int(input())
K = list(map(int, input().split()))
if K[0] != 0:
	K[0] -= 1
y_f = 1
	
for i in range(1, N):
	if K[i - 1] == K[i]:
		pass
	elif K[i - 1] > K[i] - 1:
		print("No")
		y_f = 0
		break
	else:
		if K[i] != 0:
			K[i] -= 1
if y_f == 1:
	print("Yes")

Solution (Python):
n = int(input())
H = list(map(int,input().split()))
ma = H[0]-1
ans = "Yes"
for i in range(1,n):
    if H[i-1] < H[i]:
        H[i] += -1
    elif H[i] < H[i-1]:
        ans = "No"
        break
print(ans)

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]
H[0] -= 1
for i in range(0,N-1):
  if H[i+1] >= H[i] + 1:
    H[i+1] -= 1
  elif H[i+1] == H[i]:
    continue
  else:
    print("No")
    exit()
print("Yes")

Solution (Python):
def c_build_stairs(N, H):
    for i in range(N - 1):
        if H[i] < H[i + 1]:
            H[i + 1] -= 1

    for i in range(N - 1):
        if H[i] > H[i + 1]:
            return 'No'
    return 'Yes'

N = int(input())
H = [int(i) for i in input().split()]
print(c_build_stairs(N, H))

Solution (Python):
n=int(input().rstrip())
h=input().split(" ")

ans=1
lim=int(h[n-1])
for i in range(n-2,-1,-1):
    h[i]=int(h[i])
    if(lim >h[i]):
        lim=h[i]
    else:
        if(lim+1< h[i]):
            ans=0
if ans==1:
    print("Yes")
else:
    print("No")