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


def main():
    N = int(input())
    *H, = map(int, input().split())

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


main()

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



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

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

for i in range(0, n-1):
    if(listH[i+1] - listH[i] == -1):
        listH[i+1] += 1
    if(listH[i+1] - listH[i] < -1):
        print("No")
        quit()


print("Yes")

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

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

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

Solution (Python):
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(li() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))

def main(n,h):
    for i in range(2, len(h)+1):
        if judge(h) : return print("Yes")
        if h[-i] - h[-i+1] >= 2 : return print("No")
        if h[-i] - h[-i+1] == 1 : h[-i] -= 1
    print("Yes" if judge(h) else "No")
    return
            

def judge(h):
    for i in range(len(h)-1):
        if h[i] > h[i+1] : return False
    return True

n = ii()
h = mi()
main(n,h)

Solution (Python):
import sys
import math
from collections import Counter
import itertools
import fractions



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

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

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")


 
N=II()
H=LI()
H.reverse()
for i in range(N-1):

    if H[i+1] - H[i] == 1:
        H[i+1] -=1
    elif H[i+1] - H[i] >1:
        print('No')
        exit()
print('Yes')

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

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

    if H[i] < before:
        print("No")
        exit()

    before = H[i]

print("Yes")

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

flg = True
prev = 0
for h in arr_H:
    if prev - 1 > h:
        flg = False
        break
    prev = max(prev,h)
print('Yes' if flg else 'No')

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

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

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

Solution (Python):
n = int(input())
h = [int(e) for e in input().split()]
flg = "Yes"
equal = 0
for i in range(n-1):
    if equal:
        if h[i] > h[i+1]:
            flg = "No"
            break
        elif h[i] != h[i+1]:
            equal = 0


    else:
        h[i] -= 1
   
        if h[i+1] < h[i]:
            flg = "No"
            break
        elif h[i+1] == h[i]:
            equal = 1

        else:
            equal = 0
print(flg)

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

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

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

mi = 0
for i in range(n):
    if mi < A[i]:
        mi = A[i]-1
    elif mi == A[i]:
        mi = A[i]
    elif A[i]-mi < 0 :
        print('No')
        sys.exit()
print('Yes')

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

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

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

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

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

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

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

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

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

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] += 1

print("Yes")

Solution (Python):
n=int(input())
lst = list(map(int,input().split()))
cnt = 0
height = 0
for j in range(n):
  if j == n-1:
    if lst[j] >= height:
      continue;
    else:
      cnt += 1
  else:
    if lst[j] - lst[j+1]<=1 and lst[j] >= height:
      if lst[j] > height:
        height = lst[j] - 1
    else:
      cnt += 1
if cnt == 0:
  print("Yes")
else:
  print("No")

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

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

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

Solution (Python):

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

m = 0
flag = True

for i in h:
  if m > i + 1:
    flag = False
    break

  if i > m:
    m = i

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 







n = int(input())
a = list(map(int, input().split()))
now = a[n-1]
for i in range(n-2, -1, -1):
    if now > a[i]:
        now = a[i]
    elif now == a[i]:
        now = a[i]
    elif a[i] - now == 1:
        now = a[i] - 1
    else:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
n = int(input())
H = list(map(int, input().split()))
ok = True
m = 0
for h in H:
    if h-1 >= m:
        m = h-1
    elif h >= m:
        m = h
    else:
        ok = False
        break
if ok:
    print('Yes')
else:
    print('No')

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

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

Solution (Python):
def main():
	n = int(input())
	arr = list(map(int,input().split()))
	for i in range(1,len(arr)):
		if arr[i]>arr[i-1]:
			arr[i]-=1
		elif arr[i]<arr[i-1]:
			print("No")
			return
	print("Yes")
	return


main()

Solution (Python):


n = int(input())
h = list(int(x) for x in input().split())

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

print(ans)

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

    increase = True
    for i in reversed(range(1, N)):
        if H[i] >= H[i-1]:
            pass
        elif H[i-1] - H[i] == 1:
            H[i-1] -= 1
        else:
            increase = False
            break

    if increase:
        print("Yes")
    else:
        print("No")
        
if __name__ == "__main__":
    main()

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

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

Solution (Python):
from collections import deque

N = int(input())
H = deque(map(float, input().split()))

ato = H.pop()

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

for i in range(N-1, 0, -1):
    mae = H.pop()
    if ato - mae < -1:
        print('No')
        exit()
    elif ato - mae == -1:
        ato = mae - 1
    else:
        ato = mae

print('Yes')

Solution (Python):
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()
H = list(mapint_inp())

H = H[::-1]

mn = 10**9+7
ans = True
for i in range(N-1):
    mn = min(mn, H[i])
    if i == 0:
        continue
    if H[i]-1 > mn:
        ans = False
        break

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

Solution (Python):
import sys

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

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

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]:
    print("No")
    sys.exit()

if h[n-2] <= h[n-1]:
  print("Yes")
else:
  print("No")

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

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

b.reverse()

for i in range(1,n):

    if (b[i] > b[i-1]): b[i] += -1

    if b[i] > b[i-1] : print('No');exit() 


print('Yes')

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

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

No = 0

tmp = H[0]-1
for i in range(1,N):
  if tmp < H[i]:
    tmp = H[i]-1
  elif tmp == H[i]:
    tmp = H[i]
  else:
    No = 1
    break

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
pre = -999
frag = 0

for i in range(N):
    if A[i]-1 >= pre:
        pre = A[i] - 1
    elif A[i] >= pre:
        pre = A[i]
    else:
        frag += 1
        break
        
if frag == 1:
    print("No")
else:
    print("Yes")

Solution (Python):
n = int(input())
H1 = list(map(int,input().split()))
H2 = list(map(lambda x: x - 1, H1))

ans = "Yes"
prev = H2[0]
for i in range(1,n):
    if H2[i] > prev:
        prev = H2[i]
    if prev > H1[i]:
        ans = "No"
        break

print(ans)

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

for i in range(1,len(h)):
  if h[i-1] < h[i] :
    if h[i-1] - h[i] == -1:
      h[i] = h[i] - 1
    elif h[i-1] - h[i] < -1:
      print("No")
      exit()

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

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

print("Yes")

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

ans = "Yes"
h_pre = h_list[0]
for h in h_list:
    if h > h_pre:
        h -= 1
    elif h < h_pre:
        ans = "No"
        break
    h_pre = h
print(ans)

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

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

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

Solution (Python):
n,*h=map(int,open(0).read().split())
for i in range(n-1)[::-1]:
  if h[i+1]<h[i]:
    h[i]-=1
    if h[i+1]<h[i]:
      print('No')
      exit()
print('Yes')

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

f = True
maxh = None
for i in range(n - 1, 0, -1):
    if i == n - 1:
        continue
    if h[i] - h[i + 1] == 1:
        h[i] -= 1
    elif h[i] - h[i + 1] > 1:
        print("No")
        exit(0)
print("Yes")

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

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

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


def main():
    n = int(input())
    h = list(map(int, input().split()))
    hi = 0
    lo = 10**9
    for i in range(0, n):
        hi = max(h[i], hi)
        if h[i] == hi:
            lo = hi
        lo = min(h[i], lo)
        if hi-lo >= 2:
            print("No")
            exit()

    print("Yes")


if __name__ == '__main__':
    main()

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

print("Yes")

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

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

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

N = i()
H = li()

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

print(ans)

Solution (Python):
import sys
import numpy as np

n=int(sys.stdin.readline())
h=np.array(sys.stdin.readline().split(),dtype='int64')
h=h[::-1]
miss=0
for i in range(n):
    if i==0:
        pre=h[i]
    elif pre+1==h[i]:
        pass
    elif pre==h[i]:
        pass
    elif pre+1<h[i]:
        miss=1
        break
    else:
        pre=h[i]

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

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

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

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

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

Solution (Python):
def I(): return int(input())
def LI(): return list(map(int,input().split()))

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()
H = LIST()

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

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

print("Yes")

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,operator,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())

N = I()
H = LI()
if N==1:
    print('Yes')
    exit()
if N==2:
    print('Yes' if H[0]-1<=H[1] else 'No')
    exit()
for i in range(N-1):
    if i==0:
        H[i] -= 1
        continue
    if H[i-1]<=H[i]-1<=H[i+1]:
        H[i] -= 1
        continue
    if H[i-1]<=H[i]<=H[i+1]:
        continue
    print('No')
    break
else:
    print('Yes')

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

ans = 'Yes'
_max = 0
for i in H:
    if _max < i - 1:
        _max = i - 1
    if _max > i:
        ans = 'No'
print(ans)

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

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

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

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
x = True
c = 0
for i in range(n):
    if i > 0 and h[i - 1] - h[i] >= 2:
        x = False
        break
    elif i > 0 and h[i - 1] - h[i] == 1:
        c += 1
    elif i > 0 and h[i] > h[i - 1] and c == 1:
        c = 0
    if c == 2:
        x = False
        break
if x:
    print("Yes")
else:
    print("No")

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

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

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
flag = True
last = 0
for i,l in enumerate(li):
    
    if i == 0:
        last = l-1
    if last > l:
        flag = False
        break
    elif last == l:
        last = l
    else:
        last = l-1
if flag:
    print('Yes')
else:
    print('No')

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

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

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

Solution (Python):

def myAnswer(N:int,H:list) -> str:
   pre = H.pop(0) - 1
   for h in H:
      if(pre < h):
         pre = h - 1
      elif(pre > h):
         return "No"
      else:
         pre = h
   return "Yes"


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   H = list(map(int,input().split()))
   print(myAnswer(N,H[:]))
if __name__ == '__main__':
   main()

Solution (Python):

import io
import math

data = int(input())
array = list(map(int, input().split()))
result = "Yes"
counter = 0
for i in range(data):
    if array[i]<counter-1:
        result = "No"
        break
    counter = max(counter, array[i])
print(result)

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()))
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()))
base = 0
for h in H:
    if base > h:
        print('No')
        break
    base = max(base,h-1)
else:
    print('Yes')

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
N = int(input())
H = list(map(int, input().split()))

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

    if H[i-1] > H[i] and H[i-1] - H[i] == 1:
        H[i-1] -= 1

    
    
    

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

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

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    H = LI()

    pre = -999
    flag = True
    for h in H:
        if pre <= h - 1:
            pre = h - 1
        elif pre <= h:
            pre = h
        else:
            flag = False
            break

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

if __name__ == '__main__':
    solve()

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import deque

def solve():
    n = II()
    H = LI()
    d = deque([])

    flag = True
    for i in range(0, n):
        hi = H[i]
        if i == 0:
            d.append(hi - 1)
            continue

        hp = d.popleft()
        if hp < hi:
            d.append(hi - 1)
        elif hp == hi:
            d.append(hi)
        else:   
            flag = False
            break

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







if __name__ == '__main__':
    solve()

Solution (Python):
import sys

n, *h = map(int, sys.stdin.read().split())

def main():
    ans = 'Yes'
    for i in range(n - 1, 0, -1):
        if h[i-1] > h[i]: h[i-1] -= 1
        if h[i-1] > h[i]: ans = 'No'; break
    print(ans)

if __name__ ==  '__main__':
    main()

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

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

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


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

Solution (Python):
N=int(input())
*H,=map(int,input().split())
RH=H[::-1]

ans='Yes'
i=0
while i+1<=N-1:
    if RH[i+1]-RH[i]==1:
        RH[i+1]-=1
    elif RH[i+1]-RH[i]>=2:
        ans='No'
    i+=1

print(ans)

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    H = readInts()
    ma_ = H[0]
    for i in range(1,n):
        if ma_ < H[i]:
            H[i] -=1
        if ma_ <= H[i]:
            
            
            ma_ = H[i]
        else:
            print('No')
            exit()
    print('Yes')



if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
h = list(map(int,input().split()))[::-1]
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:
    print('No')
    break
else:
  print('Yes')

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

print("Yes")

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

B = [-1]
ans = 0
for i in A:
    if B[-1] == i:
        B.append(i)
    elif B[-1] < i:
        B.append(i - 1)
    else:
        ans = 1
if ans == 1:
    print("No")
else:
    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):
        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):
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):
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")