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):
import sys
N=int(input())

H=[int(x) for x in input().rstrip().split()]
flag=0
mi=-1
for i in range(N-1):

  if H[i]<=H[i+1] and mi<=H[i]:
    mi=max(mi,H[i]-1)
    continue
  elif H[i+1]<H[i]:
    H[i]=H[i]-1
    mi=max(mi,H[i])
    if H[i+1]<H[i] or H[i]<mi:
      flag=1
      print("No")
      sys.exit()

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

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

target = []
for i in range(1,n):
    d = h_ls[i] - h_ls[i-1]
    if d > 0:
        target = []
    elif d == 0:
        target.append(i-1)
    else:
        target.append(i-1)
        for j in target:
            h_ls[j] -= 1
        target = []
res = 'Yes'
for i in range(1,n):
    d = h_ls[i] - h_ls[i-1]
    if d < 0:
        res = 'No'
print(res)

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

minnum = h[n-1]
for i in range(n-1,0,-1):
  if h[i-1]<=minnum:
    minnum = min(minnum,h[i-1])
  elif h[i-1]-1<=minnum:
    minnum = min(minnum,h[i-1]-1)
  else:
    print('No')
    exit()
print('Yes')

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

ans = True
h[0] -= 1
for i in range(1, n):
    if h[i - 1] > h[i]:
        ans = False
        break
    if h[i - 1] < h[i]:
        h[i] -= 1

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

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

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

    print("Yes")

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

result = True
for i in range(len(H) - 1, 0, -1):
    current = H[i]
    left = H[i - 1]

    diff = current - left
    if diff == -1:
        H[i - 1] -= 1
    elif diff < -1:
        result = False
        break


answer = 'Yes' if result else 'No'

print(answer)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N-1):
  if ans > A[i+1]:
    print('No')
    exit()
  if A[i+1]-A[i] >= -1:
    ans = max(A[i+1]-1,A[i]-1,ans)
    if A[i+1] >= A[i] and A[i+1] > ans :
      A[i+1] -=1
  else:
    print('No')
    exit()
print('Yes')

Solution (Python):
import sys
n = int(input())
H = list(map(int, input().split()))
dp = [False] * n

for i in range(n-1):
  if H[i+1] - H[i] < -1:
    print("No")
    break
  elif H[i+1] - H[i] == -1:
    for j in range(i+1, 0, -1):
      if dp[j-1] == True:
        print("No")
        sys.exit()
      elif H[j] - H[j-1] >= 1:
        break
      else:
        dp[j-1] = True
else:
  print("Yes")

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
i=n-1
flag=False
while 1<=i and i<=n-1:
    if l[i]+2<=l[i-1]:
        print('No')
        flag=True
        break
    elif l[i]+1==l[i-1]:
        l[i-1]-=1
        i-=1
    else:
        i-=1
if flag==False:
    print('Yes')

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

Solution (Python):
n, *h = map(int, open(0).read().split())

for i in range(n-1):
    s = h[-i-2] - h[-i-1]
    if s == 1:
        h[-i-2] -= 1
    elif s > 1:
        print("No")
        exit()
print("Yes")

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

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

print("Yes")

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

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

mx = [0] * n
mx[0] = h[0]
for i in range(1,n):
    mx[i] = max(mx[i-1], h[i])

mn = [0] * n
mn[0] = h[n-1]
for i in range(1,n):
    mn[i] = min(mn[i-1], h[n-1-i])

if all([mx[i]-mn[n-2-i]<=1 for i in range(n-1)]):
    print('Yes')
else:
    print('No')

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


for i in range(n-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=list(map(int,input().split()))

H.reverse()


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

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

Solution (Python):

n = int(input())
h = list(map(int,input().split()))
flg = True

for i in range(n-2,-1,-1):
    if h[i] > h[i+1]:
        h[i] -= 1
        
        if h[i] > h[i+1]:
            flg = False
            break
    
if flg:
    print('Yes')
    
else:
    print('No')

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

ok = True
for i in range(N-1,0,-1):
  l = H[i-1]
  r = H[i]
  
  if l <= r:
    continue
  else:
    l -= 1
    if l <= r:
      H[i-1] -= 1
      continue
    else:
      ok = False
      break

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

Solution (Python):
def main():
    n = int(input())
    h = list(map(int,input().split()))
    before = h[-1]
    for i in range(2,n+1):
        if before >= h[-i]:
            before = h[-i]
        elif before >= h[-i] - 1:
            before = h[-i] - 1
        else:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
H = iil()
mh = 0
for i in H:
    if mh - 1 > i:
        print('No')
        exit()
    else:
        mh = max(mh,i)
print('Yes')

Solution (Python):
import sys

n = int(input())
h = list(map(int,input().split()))
h = h[::-1]

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

print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
import sys
prev = -999
for i in range(N):
    if prev <= H[i] - 1:
        prev = H[i] - 1
    elif prev == H[i]:
        prev = H[i]
    else:
        print('No')
        sys.exit(0)
print('Yes')

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    H=[int(_) for _ in input().split()]
    H[0]-=1
    for i in range(1,n):
        if H[i-1]<H[i]:H[i]-=1
        elif H[i-1]>H[i]:
            print("No")
            break
    else:print("Yes")
if __name__=='__main__':
    main()

Solution (Python):
from sys import stdin
def main():
    input=stdin.readline 
    n=int(input())
    H=[int(_) for _ in input().split()]
    H[0]-=1
    for i in range(1,n):
        if H[i-1]<H[i]:H[i]-=1
        elif H[i-1]>H[i]:
            print("No")
            break
    else:print("Yes")
if __name__=='__main__':
    main()

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
m = H[0]
for h in H[1:]:
    if m - h > 1:
        print('No')
        break
    m = max(m, h)
else:
    print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
prev = float('inf')
for h in H[::-1]:
    if h - prev > 1:
        print('No')
        break
    prev = h - (h > prev)
else:
    print('Yes')

Solution (Python):
N=int(input())
h=list(map(int,input().split()))
Min=h[N-1]
for i in range(len(h)):
	Min=min(Min,h[N-1-i])
	if  Min==h[N-1-i] or Min+1==h[N-1-i]:
		h[N-1-i]=Min
	else:
		print('No')
		break
else:
	print('Yes')

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

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

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(n-1):
  if ans > A[i+1]:
    print('No')
    exit()
  if A[i+1]-A[i] >= -1:
    ans = max(A[i+1]-1,A[i]-1,ans)
    if A[i+1] >= A[i] and A[i+1] > ans :
      A[i+1] -=1
  else:
    print('No')
    exit()
print('Yes')

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

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

flag = True
for i in range(n-1,0,-1):
  if h[i]>=h[i-1]:
    continue
  elif h[i-1]-h[i]==1:
    h[i-1] -= 1
  else:
    flag = False
    break
    
if flag:
  print('Yes')
else:
  print('No')

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

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

Solution (Python):
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
Hs=(LI())
if n==1:
    print("Yes")
    sys.exit()
for i in range(1,n):
    
    if Hs[-i-1]==Hs[-i]+1:
        Hs[-i-1]-=1
    elif Hs[-i-1]>Hs[-i]+1:
        print("No")
        sys.exit()
if i==n-1:
    print("Yes")

Solution (Python):
n = int(input())
h_list = list(map(int,input().split()))
flag = True
for i in range(0,n-1):
    if h_list[i] > h_list[i+1]+1:
        flag = False
        break
    if h_list[i] == h_list[i+1]+1:
        h_list[i+1] += 1
        
if flag == True:
    print('Yes')
    
else:
    print('No')

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

H[0]=H[0]-1
flag=0
for i in range(N-1):
    if H[i] > H[i+1]:
        flag=1
        break
    elif H[i] == H[i+1]:
        continue
    else:
        H[i+1]=H[i+1]-1

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

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

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
H=nl()
flag=True

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

print('Yes' if flag==True else 'No')

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

result = "Yes"
top = 0
for i in range(len(H)):
    if (H[i] < top-1 ):
        result = "No"
        break
    top = max(top, H[i])

print(result)

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

ans = "Yes"
for i in range(N-1):
  dif = H[i+1] - H[i]
  if dif <= -2:
    ans = "No"
  elif dif == -1:
    H[i+1] += 1
print(ans)

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

h = H[0]

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

print('Yes')

Solution (Python):
def q3():
    N = int(input())
    H = [int(i) for i in input().split()]
    ans = 'Yes'
    if len(H) == 1:
        print(ans)
        return

    for i in range(len(H)):
        if i == 0:
            H[i] -= 1
        elif H[i-1] - H[i] < 0:
            H[i] -= 1
        elif H[i-1] - H[i] >= 1:
            ans = 'No'
            break

    print(ans)


if __name__ == '__main__':
    q3()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h = h[::-1]
f = True
for i in range(n-1):
    if h[i] < h[i+1]:
        h[i+1] -= 1
    if h[i] < h[i+1]:
        f = False
        break
if f: print('Yes')
else: print('No')

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

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

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

pre = h[0] - 1
for cur in h[1:]:
    if cur < pre:
        print('No')
        exit()
    if cur > pre:
        cur -= 1
    pre = cur

print('Yes')

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
for i in range(2, n + 1):
    if h[n-i] > h[n-i+1]:
        if h[n-i] - 1 == h[n-i+1]:
            h[n-i] -= 1
        else:
            print("No")
            exit()

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

print("Yes")

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

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
pre=0
for h in H:
    if h<pre:
        print("No");exit()
    elif h>pre:
        pre=h-1
print("Yes")

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

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

Solution (Python):
n = int(input())
ns = list(map(int, input().split()))
mx = 0
flag = True
for i in ns:
    if i+2 <= mx:
        print('No')
        flag = False
        break
    mx = max(i, mx)
if flag:
    print('Yes')

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

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

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


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

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

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

mx=hl[0]
flag=True
for i in range(n):
    mx=max(mx,hl[i])
    if hl[i]>=mx-1:
        pass
    else:
        flag=False
        break
if flag:
    print("Yes")
else:
    print("No")

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

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  H = list(map(int, readline().split()))
  prev = 0
  ans = 'Yes'
  for i in range(n):
    if H[i] -1 >= prev:
      H[i] -= 1
    if H[i] < prev:
      ans = 'No'
      break
    prev = H[i]
  
  print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())
H = list(map(int, input().split(" ")))
H.reverse()
possible = True
for i in range(1, N):
    if H[i] == H[i - 1] + 1:
        H[i] -= 1
    elif H[i] > H[i - 1]:
        possible &= False
print('Yes' if possible else 'No')

Solution (Python):
n = int(input())
S = list(map(int, input().split()))[::-1]

flag = True
for i in range(1, n):
  if S[i] > S[i-1]:
    S[i] -= 1
    
  if S[i] > S[i-1]:
    flag = False
    break

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

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

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

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

print(ans)

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

check = 0

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

else:
	for i in range(n-2):
		if h[i] < h[i+1]:
			h[i+1] -= 1
	for i in range(n-1):
		if h[i] > h[i+1]:
			print('No')
			break
		if h[i] <= h[i+1]:
			check += 1
	if check == n-1:
		print('Yes')

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:
        h[i-1] -= 1
    elif h[i-1] - h[i] >=2:
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys
N = int(input())
H = list(map(int,input().split()))
H[0] -= 1
for i in range(N-1):
  if H[i+1] > H[i]:
    H[i+1] -= 1
   
  if H[i+1] < H[i]:
    print('No')
    sys.exit()

print('Yes')

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
m = 0
flag = True
for n in h:
    if m < n:
        m = n
    elif n <= m - 2:
        flag = False
        break
if flag:
    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:
        h[i-1] -= 1
    elif h[i-1] - h[i] >=2:
        print("No")
        exit()
print("Yes")

Solution (Python):
def ok(hs):
    m = 0
    for h in hs:
        if h < m - 1:
            return False
        m = max(m, h)
    return True
 
n = int(input())
print('Yes' if ok(map(int, input().split())) else 'No')

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
h = na()

flag = True
for i in range(n - 1, 0, -1):
    if h[i] < h[i - 1]:
        h[i - 1] -= 1
        if h[i] < h[i - 1]:
            flag = False

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

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


flag = True
for i in range(1, N):
    if H[i-1] > H[i]:
        H[i] += 1
    if H[i-1] > H[i]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):

n = int(input())
h = [int(i) for i in input().split()] 

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


if h != sorted(h):
    print("No")
else:
    print("Yes")

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

N = int(input())
H = list(map(int, input().split()))
prev = -1
for h in H:
    if prev > h:
        print('No')
        exit()
    if prev <= h - 1:
        prev = h - 1
    else:
        prev = h
print('Yes')

Solution (Python):
n, *k = map(int, open(0).read().split())
mx = cant = 0
for i in k:
        mx = max(mx, i)
        if mx-i>1: cant = True
print("YNeos"[cant::2])

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

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

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
for i in range(n-1)[::-1]:
  if h[i]==h[i+1]+1:
    h[i]-=1
  elif h[i]>h[i+1]+1:
    print('No')
    exit()
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):
N = int(input())
h = list(map(int, input().split()))

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

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

print('Yes')

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

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

maximizer = A[0]
flag = 1
for i in range(N):
  if A[i] >= maximizer - 1:
    maximizer = max(maximizer, A[i])
  else:
    flag = 0
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
ok = True
for i in range(n):
    if i == 0:
        a[i] -= 1
        continue
    if a[i] < a[i-1]:
        ok = False
        break 
    elif a[i] > a[i-1]:
        a[i] -= 1
print('Yes' if ok else 'No')

Solution (Python):
def main():
    N = int(input())
    H = [int(i) for i in input().split()]
    pre = H[-1]
    for i, h in enumerate(H[::-1], start=1):
        if i == 1:
            continue
        if h - pre > 1:
            return print("No")
        elif h - pre == 1:
            pre = h - 1
        else:
            pre = h
    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    h = LI()
    m = h[0]-1
    for i in h[1:]:
        if m > i:
            print("No")
            return
        m = max(m,i-1)
    print("Yes")
    return


if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
lst = [int(i) for i in input().split()]
lst_be = lst[:n-1]
lst_af = lst[1:]
judge = True
tmp_max = lst[0]
for be, af in zip(lst_be, lst_af):
	if af + 1 < tmp_max:
		judge = False
		break
	tmp_max = max(tmp_max, af)
if (judge):
	print ('Yes')
else:
	print ('No')

Solution (Python):
def ok(hs):
    last = -1
    margin = 1
    for h in hs:
        if h < last - margin:
            return False
        elif h < last:
            margin = 0
        elif h > last:
            margin = 1
        last = h
    return True
n = int(input())
print('Yes' if ok(map(int, input().split())) else 'No')

Solution (Python):
N = int(input())
H = [int(s) for s in input().split(' ')]
max_h = H[0]
for h in H[1:]:
    if max_h == h - 1 or max_h == h:
        continue
    elif max_h < h:
        max_h = h - 1
    else:
        print('No')
        exit(0)

print('Yes')

Solution (Python):

import sys
def LI():
	return [int(s) for s in input().split()]
    
N = int(input())
H = LI()

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

    if H[i - 1] <= H[i] - 1:
        H[i] -= 1

print('Yes')

Solution (Python):
import os, sys, re, math

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

possible = True
for i in range(N - 1, 0, -1):
    if H[i - 1] >= H[i] + 2:
        possible = False
        break
    elif H[i - 1] == H[i] + 1:
        H[i - 1] -= 1

print('Yes' if possible else 'No')

Solution (Python):
n = int(input())
aaa = list(map(int, input().split(' ')))
before = 0
ans = 'Yes'
for i in range(n-2, -1, -1):
    if aaa[i] == aaa[i+1] + 1:
        aaa[i] -= 1
for i in range(n-1):
    if aaa[i] > aaa[i+1]:
        ans = 'No'
print(ans)

Solution (Python):
n = int(input())
klist = list(map(int,input().split()))
hlist = klist[::-1]
for i in range(n-1):
  if hlist[i]+1 < hlist[i+1]:
    print('No')
    break

  if hlist[i]+1 == hlist[i+1]:
    hlist[i+1] -= 1
else:print('Yes')

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    n = int(input())
    h = list(map(int, input().split()))
    h[0] -= 1
    for i in range(n-1):
        if h[i]==h[i+1]:
            continue
        if h[i] > h[i+1]:
            print('No')
            exit()
        else:
            h[i+1] -= 1
    print('Yes')

if __name__ == '__main__':
    main()

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

if n == 1:
    print("Yes")

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

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

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

Solution (Python):
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    H = il()
    tmp = -1
    for n in range(N):
        if tmp-1 <= H[n]:
            tmp = max(tmp, H[n])
        else:
            print('No')
            exit()
    else:
        print('Yes')


if __name__ == '__main__':
    main()

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

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

prev = 0
for item in h_list:
    if item == prev:
        continue
    elif item > prev:
        prev = item - 1
    else:
        print('No')
        exit()
print('Yes')

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


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

print('Yes' if x==h else 'No')

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

cnt = 0
tmp = H[0]
for i in range(N-1):
    tmp = max(H[i], tmp)
    if(H[i] - H[i+1] > 1):
        Flg = "No"
        break
    if(H[i] > H[i+1] and tmp-H[i+1] > 1):
        Flg = "No"
        break
print(Flg)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans='Yes'
a[0]-=1
for i in range(n-1):
  if a[i]>a[i+1]:
    ans='No'
  elif a[i+1]>a[i]:
    a[i+1]-=1
print(ans)

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
res = 'Yes'
for i in range(N-1):
    if H[i] < H[i+1]:
        H[i+1] -= 1
    elif H[i+1] - H[i] == 0:
        continue
    else:
        res = 'No'
        break
print(res)

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

Solution (Python):
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    H = il()
    tmp = -1
    for n in range(N):
        if tmp > H[n]:
            if tmp == H[n] + 1:
                tmp = H[n] + 1
            else:
                print('No')
                break
        else:
            tmp = H[n]

    else:
        print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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