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()))
h = h[::-1]

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

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

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

for i in range(N,1,-1):
    if lis_h[i - 1] < lis_h[i - 2]:
        lis_h[i - 2] -= 1
        if lis_h[i - 1] < lis_h[i - 2]:
            print("No")
            exit()
print("Yes")

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

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

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

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

    prev_h = h[-1]
    for cur_h in h[::-1][1:]:
        diff_h = cur_h - prev_h
        if diff_h > 1:
            print('No')
            return()
        prev_h = cur_h
        if diff_h == 1:
            prev_h -= 1

    print('Yes')
    return()

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

n = int(input())

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

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

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

for i in range(N):
  if(i != 0):
   dif = H[i]-H[i-1]
   if(dif == -1): 
     H[i] = H[i-1]      
   elif(dif < -1):
     judge = 0 
  
if(judge == 1): print('Yes')
else: print('No')

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

for i in range(n-1):
  if h[i] == h[i+1]:
    continue
  elif h[i] <= h[i+1]-1:
    h[i+1]-=1
    continue
  else:
    print("No")
    quit()
    
print("Yes")

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

    for i in range(1, N):
        if A[i - 1] > A[i]:
            return "No"
        elif A[i] != A[i - 1]:
            A[i] -= 1
    return "Yes"
print(main())

Solution (Python):
s=input()
t=list(map(int,input().split()))
s=int(s)
t.reverse()
for i in range(s-1):
  if t[i]<t[i+1]:
    t[i+1]=t[i+1]-1
t.reverse()
a=0
for j in range(s-1):
  if t[j]>t[j+1]:
    a=-1
if a==-1:
  print('No')
else:
  print('Yes')

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

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

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

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

Solution (Python):
N=int(input())
s=list(map(int,input().split()))
ok=True
isitok=0
if N>=2:

    for num in range(N-1):
        if s[num+1]-s[num]<=-2:    
            ok=False
            break
        if s[num+1]-s[num]==-1:
            isitok+=1
        if s[num+1]==s[num]:
        
            continue
        if s[num+1]>s[num]:
            isitok=0
            
        if isitok==2:
            ok=False
            break
        else:
            continue
    if ok:
        print("Yes")
    else:
        print("No")
        
elif N==1:
    print("Yes")

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

    H.reverse()

    bf = 10 ** 9

    for h in H:
        if bf >= h:
            bf = h
        elif bf + 1 == h:
            pass
        else:
            print("No")
            exit()

    print("Yes")
    
p_c()

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

f = True
while n>1:
  n -= 1
  if h[n-1]>h[n]:
    if h[n]==h[n-1]-1:
      h[n-1] -= 1
    else:
      f = False
      break

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

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] >= 1:
        h[i] -= 1
    
    if h[i] - h[i+1] >= 1:
        ans = "No"
        break
        
print(ans)

Solution (Python):
n = int(input())
hs = list(map(int, input().split()))
v = -float("inf")
for h in hs:
    if v > h:
        if v != h+1:
            print("No")
            exit()
        else:
            v = h+1
    else:
        v = h
print("Yes")

Solution (Python):

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

flag = 1

if N == 2:
    if H[0]>H[1]:
        H[0] -= 1
else:
    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]:
        flag = 0

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

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    h = list(map(int, input().rstrip('\n').split()))
    for i in range(1, n):
        if h[i] < h[i-1]:
            h[i] += 1
        if h[i] < h[i-1]:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    slove()

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]:
        H[i-1] = H[i-1] - 1

tmp = 0
for i in range( N-1 ):
    if H[i] > H[i+1]:
        tmp = 1
        break

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

Solution (Python):
import sys

N = int(input())
li = list(map(int,input().split()))
li.reverse()

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

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

for i in range(n - 1):
    if hs[i] < hs[i + 1]:
        hs[i + 1] -= 1
    elif hs[i] == hs[i + 1]:
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
import sys
n = int(sys.stdin.readline())
H = list(map(int, sys.stdin.readline().split()))

for i in range(n-1, 0,-1):
    if H[i] - H[i-1] ==-1:
        H[i-1]-=1
        
        
if sorted(H) == H:
    print('Yes')
else:
    print('No')

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

flag = True
res_max = 0
for i in range(n-1):
    if h[i+1]-h[i] >= 1:
        h[i+1] -= 1
    elif h[i+1]-h[i] >= 0:
        continue
    else:
        flag = False
        break

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

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

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

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

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

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

print('Yes')

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

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

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

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

Solution (Python):


import sys


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

level = 0
for i in range(len(array)-1):
    
    
    if array[i] + 1 <= array[i+1]:
        level = array[i]
        continue
    elif array[i] == array[i+1]:
        if level <= array[i] - 1:
            array[i] -= 1
            level = array[i]
        else:
            continue
    elif array[i] - 1 == array[i+1]:
        if level <= array[i] - 1:
            array[i] -= 1
            level = array[i]
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
print("Yes")

Solution (Python):

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

c = h[0]

for i in h:
    if c <= i:
        c = i

    elif i + 1 == c:
        c = i + 1

    else:
        print("No")
        exit()
print("Yes")

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

c = hs[0]

for h in hs:
    if c <= h:
        c = h
    elif h + 1 == c:
        c = h + 1
    else:
        print('No')
        exit()

print('Yes')

Solution (Python):

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

flag = True

for i in range(N-1):
    if H[i] <= H[i+1]:
        continue
    elif H[i] == H[i+1]+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()))
p = h[-1]
flag = 0
for i in h[::-1]:
  if i <= p:
    p = i
    continue
  elif (i - p) == 1:
    p = i - 1
  else:
    print('No')
    exit()
print('Yes')

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

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

Solution (Python):


n=int(input())





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






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

Solution (Python):
import sys

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
    elif H[i] + 1 < H[i-1]:
        print("No")
        sys.exit()
        
print("Yes")

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

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


for i in reversed(range(1, n)):
    l, r = list_h[i-1], list_h[i]

    
    if l <= r:
        continue

    
    elif l - 1 == r:
        list_h[i-1] = list_h[i-1] -1
        continue

    
    else:
        print("No")
        exit()

print("Yes")

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

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

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

Solution (Python):

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

x = lst[0]

for i in range(len(lst)):
    if x < lst[i]:
        x = lst[i]

    if ( x - lst[i] ) > 1 :
        print('No')
        exit(0)

print('Yes')

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

Solution (Python):

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

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

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

bool = True
pre=-1

for x in h:
    if x == pre:
        continue
    if x <= pre:
        bool = False
        break
    pre = x-1
ans = 'Yes' if bool else 'No'
print(ans)

Solution (Python):
import sys
n = int(input())
h = list(map(int,input().split()))
for k in range(n-1):
    if h[k+1]==h[k]-1:
        h[k+1]=h[k]
    elif h[k+1]>=h[k]:
        continue
    else:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
import sys
n = int(input())
h = list(map(int,input().split()))
for k in range(n-1):
    if h[k+1]==h[k]-1:
        h[k+1]=h[k+1]+1
    elif h[k+1]>=h[k]:
        continue
    else:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]
H[0] = H[0] - 1
for i in range(1,N):
    if H[i] - H[i-1] > 0:
        H[i] = H[i] -1

if H == sorted(H):
    print("Yes")
else: 
    print("No")

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] == H[i-1] - 1:
        H[i-1] -= 1
    elif H[i] < H[i-1] - 1:
        flag = False
        break
        
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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 H[i] < H[i+1]:
        print('No')
        exit()

print('Yes')

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

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

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

if N == 2:
    if H[0]-H[1] <= -1:
        print("Yes")
    else:
        print("No")

if N >= 3:
    for i in range(1, N):
        if H[0]-H[1] <= -1:
            H[1] -= 1
        elif H[0]-H[1] == 0:
            H[0] -= 1
            H[1] -= 1
        elif H[0]-H[1] == 1:
            H[0] -= 1

        if i == N-1:
            print("Yes")
            break
        elif H[i]-H[i+1] <= -1:
            H[i+1] -= 1
            continue
        elif H[i]-H[i+1] == 0:
            continue
        else:
            print("No")
            break

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
def solve(a):
  actMax = a[0]
  for i in range(1,n):
    if(a[i]<actMax-1):
      print("No")
      return
    actMax = max(actMax,a[i])
  print("Yes")
    
solve(a)

Solution (Python):
N = int(input())
S = list(map(int, input().split()))
flg = 1
for i in range(N - 1, 0, -1):
    if S[i] - S[i -1] <= -2:
        flg = 0
        break
    elif S[i] - S[i -1] == -1:
        S[i - 1] -= 1
    else:
        continue


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

Solution (Python):
n=int(input())
list1=list(reversed(input().split()))
list2=list(map(int,list1))

if len(list2)==1:
    print("Yes")
else:
    for i in range(len(list2)):
        
        d=list2[i]-list2[i+1]
        if d==-1:
            list2[i+1]-=1
        if d<-1:
            print("No")
            break
        if i==len(list2)-2:
            print("Yes")
            break

Solution (Python):

n= int(input())


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

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

k = sorted(h)

if k==h:
	print("Yes")

else:
	print("No")

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
h0min = h[0]
h0max = h[0]
for i in range(1, n):
    hi = h[i]
    if hi < h0min:
        print('No')
        break
    h0min = max(h0min, hi - 1)
    h0max = hi
else:
    print('Yes')

Solution (Python):
import sys
def I(): return(int(sys.stdin.readline())) 
def LI(): return(list(map(int,sys.stdin.readline().split())))

def main():
    N = I()
    H = LI()
    for i in range(N-2,-1,-1):
        if H[i]>H[i+1]+1:
            return("No")
        if H[i]==H[i+1]+1:
            H[i] -= 1
    return("Yes")
    
    
if __name__ == "__main__":
    print(main())

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

max = 0
for n in range(N):
    if max > H[n]:
        print('No')
        exit()
    sub = H[n]-1
    if sub > max:
        max = sub
print('Yes')

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

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

print(res)

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

minH_right = [0] * N
min_tmp = 10 ** 18
for i in range(N):
    if min_tmp > H[N - 1 - i]:
        min_tmp = H[N - 1 - i]
    minH_right[N - 1 - i] = min_tmp

ans = 'No'

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

print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans = True
a[0] -= 1
for i in range(1,n):
  if a[i]>a[i-1]:
    a[i] -= 1
  elif a[i]==a[i-1]:
    pass
  else:
    ans = False
    break
if ans==True:
  print("Yes")
else:
  print("No")

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

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

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


print("Yes")

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

flag = 0
key = 0

for i in range(len(H)-1):
    if flag == 1:
        if H[i+1] < key:
            print('No')
            sys.exit()

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

        elif H[i] == H[i+1] + 1:
            flag = 1
            key = H[i+1]
	
print('Yes')

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

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


def solve():
    max_h = 0

    for h in H:
        if max_h > h:
            return False

        max_h = max(max_h, h - 1)

    return True


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

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
flag=[False for _ in range(N)]

def solver(x,y):
  global flag
  if x<0 or y>N:
    return

  if H[x]>H[y] and flag[x]==False:

    H[x]-=1
    flag[x]=True
    solver(x-1,y)

for i in range(N-1):
  solver(i,i+1)


shadow=H[:]
H.sort()
if shadow==H:
  print("Yes")
else:
  print("No")

Solution (Python):
N=int(input())
H=list(map(int, input().split()))
h=H[::-1]
a=True

for i in range(N-1):
    if h[i] < h[i + 1]:
        if h[i+1]-h[i] <= 1:
            h[i+1] -=1
        else:
            a = False
            break

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

Solution (Python):
n = int(input())
h = list(map(int, input().split(' ')))
h.reverse()
flg = True

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

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

Solution (Python):
import sys

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
    elif H[i] + 1 < H[i-1]:
        print("No")
        sys.exit()
    
print("Yes")

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

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

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
h[0] -= 1
if len(h) == 1:
    print('Yes')
else:
    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):
import sys
input=sys.stdin.readline

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

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

down = 0
for x in range(1, N):
    if H[x - 1] > H[x]:
        if H[x - 1] - H[x] >= 2:
            print("No")
            sys.exit()
        down += 1
    elif H[x - 1] < H[x]:
        down = 0
    if down >= 2:
        print("No")
        sys.exit()

print("Yes")

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

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

Solution (Python):

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

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

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

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

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

if cnt == len(H)-1:
    print("Yes")
else:
    print("No")

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

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

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

Solution (Python):
import sys
N = int(input())
A = [int(_) - 1 for _ in input().split()]

for n in range(1, N):
    if A[n] + 1 == A[n - 1]:
        A[n] += 1
    elif A[n] + 1 < A[n - 1]:
        print('No')
        sys.exit()
print('Yes')

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

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

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
h[0] -= 1
flag = [True]
if len(h) == 1:
    print('Yes')
else:
    for i in range(1, n):
        if h[i] > h[i - 1]:
            h[i] -= 1
        elif h[i] < h[i - 1]:
            print('No')
            exit()
    print('Yes')

Solution (Python):
import sys
n, hl = sys.stdin.readlines()
n = int(n)
hl = list(map(int, hl.split()))

for i in range(n-1, 0, -1):
    if hl[i] - hl[i-1] ==-1:
        hl[i-1]-=1

if hl == sorted(hl):
    print('Yes')
else:
    print('No')

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]:
    h[i-1] -= 1
for i in range(1, n):
  if h[i]<h[i-1]:
    flag = False
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
def test():
    n = int(input())
    h = list(map(int,input().split()))
    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")
                return
    print("Yes")    


if __name__ == "__main__":
    test()

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

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

print(ans)

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

q, c = 0, 0
if len(H) >= 2:
  i = 0
  while i < len(H) - 1 and q == 0:
    if c <= H[i]:
      c = H[i]
    if c > H[i+1] + 1:
      q += 1
    i += 1
    
if q == 0:
  print('Yes')
else:
  print('No')

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

ans = 1
H[0] -= 1

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

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

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

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

Solution (Python):
N = raw_input()
X = map(int, raw_input().split())

counter = 0
possible = True
nextchanged = False
while counter < int(N) - 1:
  if X[counter] > X[counter + 1]:
    if nextchanged:
      possible = False
      break
    else:
      X[counter] -= 1
      if X[counter] == X[counter + 1]:
        nextchanged = True
      if X[counter] > X[counter + 1]:
        possible = False
        break
  else:
    if X[counter] < X[counter + 1]:
      nextchanged = False
  counter += 1
if possible:
  print "Yes"
else:
  print "No"

Solution (Python):
input()
hl=list(map(int, input().split()))
hl.reverse()
prev=10**9
for h in hl:
  if h <= prev:
    prev = h
    continue
  if h == prev + 1:
    prev = (h - 1)
    continue
  print("No")
  quit()
print("Yes")

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

count = 0

for i in range(N-1):
	if i != 0 and H[i-1] == H[i]:
		if H[i] > H[i+1] and H[i] != 1:
			H[i] -= 1
	else:
		if H[i] != 1:
			H[i] -= 1


for i in range(N-1):
	if H[i] > H[i+1]:
		print('No')
		break
	count += 1

if count == N-1:
	print('Yes')

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
h=list(map(int,input().split()))
m=0
ans=0
for i in range(n):
  if h[i]>=m-1:
    ans=1
    m=max(m,h[i])
  else:
    ans=0
    break

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

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

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

Solution (Python):
N = int(input())
a = input().split()
for l in range(N):
    a[l] = int(a[l])
for i in range(N):
  if i < N-1:
    if a[N-i-1] >= a[N-i-2]:
      continue
    elif a[N-i-1] + 1 == a[N-i-2]:
      a[N-i-2] -= 1
    else:
      print('No')
      break
  else:
    print('Yes')

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

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

    i = len(h) -1
    while 1 <= i:
        if h[i -1] <= h[i]:
            i -= 1
            continue
        elif h[i -1] - 1 <= h[i]:
            h[i - 1] -= 1
            i -= 1
            continue
        else:
            print('No')
            break
    else:
        print('Yes')


if __name__ == "__main__":
    main()

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

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

flag = False
length = len(h)

if length == 1:
	flag = True

for i in reversed(range(1,length)):
	if h[i] < h[i-1]:
		h[i-1] = h[i-1] - 1
		if h[i] != h[i-1]:
			break

	if i == 1:
		flag = True

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

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

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