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


from itertools import combinations
from collections import defaultdict
from pprint import pprint
import math
import datetime
import sys
import fcntl
import time

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

left_high = 0
ans = True
for i in range(N):
    if H[i] < left_high:
        ans = False
        break
    left_high = max(H[i] - 1, left_high)

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

Solution (Python):
N = int(input())
nums = list(map(int, input().split()))
before = 0
for num in nums:
  if num > before:
    before = num - 1
  elif num < before:
    print('No')
    exit()
print('Yes')

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def even_digits(i):
    if (1 <= i <= 9) or (100 <= i <= 999) or (10000 <= i <= 99999) or (1000000 <= i <= 9999999):
        return True
    else: return False

def main(): 
    N = II()
    H = LI()

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

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

main()

Solution (Python):
import sys

def main():
    N = int(input())
    H = list(map(int, sys.stdin.readline().split()))

    last = 10**10
    for h in reversed(H):
        if h > last + 1:
            print('No')
            sys.exit()
        elif h > last:
            continue
        else:
            last = h

    print('Yes')

if __name__=='__main__':
    main()

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

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
f = True
m = 0
for i in range(n):
    m = max(m, h[i])
    if m - 1 > h[i]:
        f = False
print('Yes' if f else 'No')

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

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

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

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

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

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

print('Yes')

Solution (Python):

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

for i in range(1,N):
    if (H[i-1]>H[i]):
        if (H[i-1]-1 == H[i]):
            if(dec==0):
                H[i-1]-=1
                dec=1
            else:
                ng=1
        else:
            ng=1
    if (H[i-1]<H[i]):
        dec=0
    if ng==1:
        break;

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

Solution (Python):
N, *H = map(int, open(0).read().split())
cnt = 0
for i in range(N - 1):
    if H[i + 1] - H[i] < -1:
        print('No')
        break
    elif H[i + 1] - H[i] == -1:
        cnt += 1
    elif H[i + 1] - H[i] == 0:
        pass
    else:
        cnt = 0
        
    if cnt > 1:
        print('No')
        break
else:
    print('Yes')

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

Solution (Python):
N=int(input())
H=[int(x) for x in input().split()]
ans=True
if N!=1:
  for i in range(len(H)-1,0,-1):
    if H[i]<H[i-1]:
      if H[i-1]-H[i]==1:
        H[i-1]-=1
      else:
        ans=False
        break
if ans:
  print('Yes')
else:
  print('No')

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

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()
nums = getList()
tmp = nums[-1]
for i in range(n-1):
    tgt = nums[n - i - 2]
    
    if tgt <= tmp:
        tmp = tgt
    elif tgt == tmp + 1:
        tmp = tgt - 1
    else:
        print("No")
        sys.exit()

print("Yes")

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Hs = [int(x) for x in stdin.readline().rstrip().split()]
    for i in range(1, N - 1):
        a = Hs[i - 1]
        b = Hs[i]
        c = Hs[i + 1]
        if a + 1 <= b:
            Hs[i] -= 1
            b = Hs[i]
        if a <= b <= c:
            pass
        else:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()

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

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

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

for i in reversed(range(1,n)):
  if li[i-1] <= li[i]:
    continue
  elif li[i-1] -1 == li[i]:
    li[i-1] -= 1
  else:
    print("No")
    exit()
print("Yes")

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline






















def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	H = inputList()

	flg = True
	for i, val in enumerate(H):
		if i == 0:
			continue
		if H[i-1] < H[i]:
			H[i] -= 1

	
	for i, val in enumerate(H):
		if i == 0:
			continue
		if H[i] < H[i-1]:
			flg = False

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


if __name__ == "__main__":
	main()

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

result = True
for i in range(n-1):
    if h[i] < h[i+1]:
        if h[i+1] - 1 <= h[i]:
            h[i+1] = h[i+1] -1
        else:
            result = False
            break

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

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

yes = True
for i in range(len(H) - 1, 0, -1):
    if H[i] < H[i -1] - 1:
        yes = False
        break
    elif H[i] < H[i - 1]:
        H[i - 1] -= 1
    
if yes:
    print("Yes")
else:
    print("No")

Solution (Python):


N = int(input())

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

flg = True
tmp = 0

for h in H:
    if h >= tmp:
        tmp = max(tmp, h-1)
    else:
        flg = False

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

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

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

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

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

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

masu = H[:]

ans = 'Yes'
masu[0] -= 1
for i, h in enumerate(masu[:]):
    if i == 0:
        continue
    
    pre_h = masu[i-1]
    if pre_h < h:
        masu[i] -= 1
    elif pre_h == h:
        continue
    else:
        ans = 'No'
        break
print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
MAX = 0
ans = "Yes"
for i in a:
  diff = MAX - i
  if diff < 0:
    MAX = i
  elif diff >= 2:
    ans = "No"
    break
print(ans)

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

Hs, HSs = Hs, sorted(Hs)
for h,s in zip(Hs, HSs):
    if h - s <= 1:
        ...
    else:
        print('No')
        exit()
print('Yes')

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right

import re







def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e50)
MOD = int(1e9)+7 


def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]



def main():
    N = i_inpl()
    H = l_inpl()

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

if __name__ == "__main__":
    main()

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

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

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, H: "List[int]"):
    flag = True
    for i in range(0, N-1):
        if H[N-1-i-1] <= H[N-1-i]:
            continue
        elif H[N-1-i-1] == H[N-1-i] + 1:
            H[N-1-i-1] -= 1
            continue
        else:
            flag = False
            break
    if flag==True:
        print('Yes')
    else:
        print('No')
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    H = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, H)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, H: "List[int]"):

    for i in range(len(H)-1):
        if H[i] > H[i+1]:
            H[i] -= 1
        elif i > 0 and H[i-1] < H[i]:
            H[i] -= 1

    for i in range(len(H)-1):
        if H[i] > H[i+1]:
            print(NO)
            return


    print(YES)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    H = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, H)

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    cur = A[0]
    for i in A[1:]:
        if i == cur or i - 1 == cur:
            continue
        elif i > cur:
            cur = i - 1
        else:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
import sys

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

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

print("Yes")

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

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 permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
H = LIST()

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

Solution (Python):
n = int(input())
array = [int(i) for i in input().split()]
last = array[n-1]
ans = "Yes"

for i in range(n-1):
  if array[i]>array[i+1] or array[i]>last:
    array[i] -= 1
    
for i in range(n-1):
  if array[i] > array[i+1]:
    ans ="No"
    
print(ans)

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

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

print("Yes")

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]
ans = False
for i in range(N-1):
    h1, h2 = H[i], H[i+1]
    if h1 <= h2:
        continue
    if h1 - h2 > 1:
        print('No')
        exit()
    else:
        H[i+1] += 1
print('Yes')

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, H: "List[int]"):
    for i in range(N-2, -1, -1):
        if H[i] == H[i+1] + 1:
            if i > 0:
                if H[i] >= H[i-1]:
                    H[i] -= 1
            else:
                H[i] -= 1
        if H[i] > H[i+1]:
            print(NO)
            return
    print(YES)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    H = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, H)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]

for i in range(N-1):
    if A[i] - A[i+1] >= 2:
        print("No")
        break
    if A[i] - A[i+1] == 1 and i >= 2 and A[i-1] >= A[i]:
        print("No")
        break
    if i == 0 or A[i] > A[i-1]:
        A[i] -= 1
else:
    print("Yes")

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

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

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

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

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


if __name__ == "__main__":
    main()

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

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
t = readl()
mx = t[-1]
for i in reversed(range(n)):
    if mx >= t[i]:
        mx = t[i]
    else:
        k = t[i] - 1
        if mx >= k:
            mx = k
        else:
            print("No")
            exit()
print("Yes")

Solution (Python):



def solve(n, hs):
    xs = hs[::-1]
    for i in range(n - 1):
        if xs[i] >= xs[i + 1]:
            pass
        elif xs[i] + 1 == xs[i + 1]:
            xs[i + 1] -= 1
        else:
            return False
    else:
        return all(xs[i] >= xs[i + 1] for i in range(n - 1))


def main():
    n = int(input())
    hs = [int(h) for h in input().split()]
    res = solve(n, hs)
    print("Yes" if res else "No")


if __name__ == "__main__":
    main()

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

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

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

  ma = H[-1]
  ans = "Yes"
  for i, h in enumerate(H[::-1]):
    if i == 0:
      continue
    if ma > h:
      ma = h
      continue
    if ma < h:
      if ma + 1 == h:
        continue
      ans = "No"
    if ma == h:
      continue
  print(ans)

if __name__ == "__main__":
  main()

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True


def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    h_list = LI()

    mn = 10**10
    for h in reversed(h_list):
        if h >= mn + 2:
            print('No')
            return
        if h < mn:
            mn = h

    print('Yes')
solve()

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

flg = True
prv = 0
for h in H:
    if h-prv >= 1:
        h -= 1
    if prv > h:
        flg = False
    prv = h

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

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

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

right_min = [0] * N
tmp = H[-1]

if len(H) == 1:
    print("Yes")
else:
    for i in reversed(range(N)):
        if tmp > H[i]:
            tmp = H[i]
        right_min[i] = tmp
    for i in range(N-1):
        if H[i] - right_min[i+1] > 1:
            print("No")
            exit()
    print("Yes")

Solution (Python):
import sys


fin = sys.stdin.readline
N = int(fin())
H_list = [int(elem) for elem in fin().split()]
cur_max = H_list[0]
for h in H_list[1:]:
    if cur_max - h > 1:
        print("No")
        exit(0)
    cur_max = max(cur_max, h)
print("Yes")

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

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

Solution (Python):
import sys

YES = "Yes"
NO = "No"


def solve(N: int, H: "List[int]"):
    hmax = H[0]
    for h in H:
        if h <= hmax - 2:
            return NO
        hmax = max(hmax, h)
    return YES


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    H = [int(next(tokens)) for _ in range(N)]  
    ans = solve(N, H)
    if ans is not None:
        print(ans)


if __name__ == '__main__':
    main()

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

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

output = 'Yes'
h_max = 0
for h in h_list:
    if h_max - h >= 2:
        output = 'No'
        break
    if h > h_max:
        h_max = h
print(output)

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

ans = "Yes"

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

print(ans)

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

H.reverse()
last = H[0]
for h in H[1:]:
    if last >= h:
        last = h
    
    elif last+1 == h:
        continue

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
hh=list(reversed(list(map(int,input().split()))))
for i in range(len(hh)-1):
    if hh[i] >= hh[i+1]:
        continue
    if hh[i]+1 == hh[i+1]:
        hh[i+1] -= 1
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
def solve(n, H):
    if n == 1:
        return True

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

    R = [0] * n
    R[-1] = H[-1]
    for i in range(n - 2, -1, -1):
        R[i] = min(R[i + 1], H[i])

    for i in range(n):
        if L[i] - R[i] > 1:
            return False

    return True


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

if solve(n, H):
    print("Yes")
else:
    print("No")

Solution (Python):


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

def solve(N, H):
  for n in range(N-1):
    i = (N - 1) - n
    if H[i] < (H[i-1] - 1):
      return 'No'
    if H[i] == (H[i-1] - 1):
      H[i-1] -= 1
  return 'Yes'

def main():
  N = readInts()[0]
  H = readInts()
  print(solve(N, H))

if __name__ == "__main__":
  main()

Solution (Python):

N = int(input())

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

flag = True


for i in range(N-1):

    i = N-1-i

    if H[i-1] <= H[i]:
        pass
    elif H[i-1]-1 == H[i]:
        H[i-1] -= 1
    else:
        flag = False
        break

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

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

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

Solution (Python):

import itertools
import sys
import math
from functools import lru_cache





from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache

input = sys.stdin.readline





n = int(input())


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



m = 0

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

print('Yes')

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

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

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

Solution (Python):



from math import *

def main():
    import sys
    sys.dont_write_bytecode = True
    sys.setrecursionlimit(10000000)

    input = sys.stdin.readline

    
    

    

    import os
    import math, itertools, operator
    from math import factorial as fact
    from operator import itemgetter, attrgetter
    from itertools import permutations, combinations
    from functools import reduce, lru_cache
    
    
    from fractions import gcd
    from fractions import Fraction as Frac

    inf = float('inf')
    pow = __builtins__.pow

    def lcm(a, b):
        return a * b // gcd(a,b)

    def perm(a, b):
        import scipy.special
        return scipy.special.perm(a, b, exact = True)

    def comb(a, b):
        import scipy.special
        return scipy.special.comb(a, b, exact = True)

    def dfact(n):
        import scipy.special
        return scipy.special.factorial2(n, exact = True)

    def prod(l):
        return reduce(operator.mul, l)

    def input_ints(func = input, sep = None, conv = int):
        return list(map(conv, func().split(sep = sep)))

    if os.environ.get('GOROOT') is None:
        def dprint(*args, **kwargs):
            kwargs['file'] = sys.stderr
            import inspect
            frame = inspect.currentframe().f_back
            print('[' + os.path.basename(frame.f_code.co_filename)
                    + ':' + str(frame.f_lineno) + ']', *args, **kwargs)
    else:
        def dprint(*args, **kwargs):
            pass


    


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

    yes = True
    last = H[-1]
    for n in range(N - 2, -1, -1):
        diff = last - H[n]
        dprint(diff)
        if diff < -1:
            yes = False
            break
        last = H[n]
        if diff == -1:
            last -= 1
    print('Yes' if yes else 'No')


if __name__ == '__main__':
    main()

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

Solution (Python):

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

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

mak = h[0]
for i in h:
    if (mak > i):
        if (mak - i > 1):
            print("No")
            exit()
    else:
        mak = i
print("Yes")

Solution (Python):
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
h = IL()

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

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

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

    h = H[i]

    
print("Yes")

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

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

now = 0
for k in range(N):
    if H[k] == now:
        pass
    elif H[k] == now + 1:
        pass
    elif H[k] >= now + 2:
        now = H[k]-1
    elif H[k] < now:
        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]:
        H[i+1] -= 1
    elif H[i] == H[i+1]:
        continue
    else:
        print('No')
        break
else:
    print('Yes')

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

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

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

tmp = h[-1]
for hi in reversed(h):
    if hi > tmp + 1:
        print("No")
        break
    else:
        tmp = min(hi, tmp)
else:
    print("Yes")