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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num__grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
h = wi()
h[0] -= 1

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

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

Solution (Python):


import sys

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

N=INT()
H=LIST()

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

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

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

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

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

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

K_left=H[1]-H[0]
if K_left<-1:
    print("No")
    sys.exit()
elif K_left == -1 :
    L_left='-'
elif K_left == 0 :
    L_left='0'
else:
    L_left='+'
maxH=max(H[1],H[0])
for i in range(1,N-1):
    K_right = H[i+1]-H[i]    
    if K_right < -1:
        print("No")
        sys.exit()
    elif K_right == -1 :
        L_right='-'
    elif K_right == 0 :
        L_right='0'
    else:
        L_right='+'

    if L_left =='-' and L_right=='-':
        print("No")
        sys.exit()
    if L_left =='0' and L_right=='-':
        if maxH <= H[i]:
            L_left=L_right
            K_left=K_right
        else:
            print("No")
            sys.exit()
    else:
        L_left=L_right
        K_left=K_right
        maxH=max(H[i+1],maxH)
print("Yes")

Solution (Python):

import numpy as np
from copy import deepcopy

def main():
    
    
    
    
    
    
    
    
    N = int(input())
    H_list = list(map(int, input().split()))
    flag = False
    for i in range(N-1,0,-1):
        
        if H_list[i-1] - H_list[i] > 1:
            print("No")
            flag = True
            break
        elif H_list[i-1] - H_list[i] == 1:
            H_list[i-1] = deepcopy(H_list[i-1]) -1
        else:
            pass
    if flag == False:
        print("Yes")
    
    
    
    
    
    
    
    
    
    
    
    


if __name__=='__main__':
    main()

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

idx = max(enumerate(H), key=lambda x: x[1])[0]

cmp = H[idx]-1
flg = 0

if N>1:
    if idx!=N-1:
        for i in range(idx, N):
            if H[i]<cmp:
                flg = 1
        if flg==0:
            print('Yes')
        else:
            print('No')

    else:
        idx = max(enumerate(H[0:N-1]), key=lambda x: x[1])[0]
        cmp = H[idx]-1
        flg = 0
        for i in range(idx, N-1):
            if H[i]<cmp:
                flg = 1
        if flg==0:
            print('Yes')
        else:
            print('No')
else:
    print('Yes')

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



c = 0


d = [0] * len(h)

f = True
if len(h) == 1:
    f = True
elif len(h) == 2:
    if h[1] >= h[0]:
        f = True
    else:
        if h[0] == h[1] + 1:
            f = True
        else:
            f = False
else:
    for i in range(len(h)-1):
        if h[i] + 1 <= h[i+1]:
            
            if d[i+1] == 0:
                h[i+1] -= 1
                d[i+1] = 1
        elif h[i] == h[i+1] + 1:
            
            if i >= 1:
                if h[i-1] + 1 <= h[i]:
                    
                    if d[i] == 0:
                        h[i] -= 1
                        d[i] = 1
                    else:
                        f = False
                        break
                    
                else:
                    
                    f = False
                    break
        else:
            
            if not h[i] == h[i+1]:
                
                f = False
                break
        

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

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

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

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

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

if len(set(lst)) == 1:
    print('Yes')
    exit()

lst_c = sorted(lst)
for i in range(n):
    if lst[i] - lst_c[i] >= 2:
        print('No')
        exit()
print('Yes')

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


print('Yes')

Solution (Python):
import sys

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

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

Solution (Python):

N = int(input())

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

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

    check_list = sorted(H)

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

Solution (Python):


_ = int(input())
h_list = [int(x) for x in input().split(' ')]



big_f = False

no_f = False

for i, h in enumerate(h_list[:-1]):
    left = h_list[i]
    right = h_list[i+1]
    if left < right:
        big_f = False
        continue
    elif left == right:
        continue
    elif left - right == 1:
        if big_f:
            no_f = True
            break
        else:
            big_f = True
    elif left - right >= 2:
        no_f = True
        break

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

Solution (Python):
def hoge(x, y):
    return y if x >= y else y - 1

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

flag = 0
for i in range(N - 1):
    H[i + 1] = hoge(H[i], H[i + 1])
    if H[i] < H[i + 1]:
        flag = 1
        print("No")
        break

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

Solution (Python):
before = 0
cur = 0

N = int(input())

for h in map(int, input().split()):
    if (cur - 1 > h):
        print("No")
        exit()
    elif (cur - 1 == h):
        if (before > h):
            print("No")
            exit()
        else:
            cur = h
            before = h
    else:
        cur = h

print("Yes")

Solution (Python):


N = int(input())
H = list(map(int, input().split()))
C = list(map(lambda x:False, H))

Ans = "Yes"


base = H[0]
for i in range(1,N):
    if H[i] < base:
        Ans = "No"
    if H[i] > base:
        base = H[i] - 1

print(Ans)

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

    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:
            print("No")
            return

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

    print("Yes")

    return


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
 
H=[int(i) for i in input().split()]
old=H[0]
danger=False
first=True

M=H[0]

for w in H:
    if w < M-1:
        print("No")
        break
    else:
        M=max(M,w)
else:
    print("Yes")

Solution (Python):
b=int(input())
a = [int(i) for i in input().split()]
a.insert(0,0)
for i in range(1,b+1):
  if a[i-1] == a[i]:
    continue
  else:
    a[i] -= 1

for i in range(b):
  if a[i] > a[i+1]:
    print('No')
    exit()
print('Yes')

Solution (Python):

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



for i in reversed(range(len(H_list))):
    if i == 0:
        print("Yes")
    elif H_list[i] - H_list[i - 1] == -1:
        H_list[i - 1] -= 1
    elif H_list[i] - H_list[i - 1] < -1:
        print("No")
        break
    else:
        continue

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

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

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

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

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

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

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

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

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

print('Yes')

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 + 1:
            cur = i - 1
        if i < cur:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

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

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

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
change = [True] * N
if N == 1:
    print('Yes')
    exit()

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

print('Yes')

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

minus_point = 0
for n in range(N-1):
  h1 = H[n]
  h2 = H[n+1]
  if h1 < h2:
    minus_point = 0
    continue
  elif h1 == h2:
    continue
  elif h1 - h2 == 1:
    if minus_point == 0:
      minus_point += 1
    else:
      print("No")
      break
  else: 
    print("No")
    break
else:
  print("Yes")

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
fin=True
if n>1 and l[0] == l[1]:l[0] += -1
for i in range(1,n):
  if n==1:break
  prev=l[i-1]
  now=l[i]
  if i == n-1:
    if prev>now:
      fin=False
    break
  else:
    next_=l[i+1]
  if prev < now and now >= next_:
    l[i] += -1
  elif prev>now:
    fin=False
    break
if fin==True:print("Yes")
else:print("No")

Solution (Python):
import sys

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

if len(H)==1:
    print("Yes")
    sys.exit()
else:

    Flag = [0 for i in range(len(H))]
    x = 0

while x < len(H)-1:

    diff = H[x+1] - H[x]
    if diff < 0:
        if Flag[x]==1:
            print("No")
            sys.exit()
        else:
            Flag[x]=1
            H[x] -= 1
            x-=1
            continue
    x += 1
print("Yes")

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

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

Solution (Python):
N = int(input())
H_ = list(map(int,input().split()))
for i in reversed(range(N-1)):
    if H_[i+1] < H_[i]:
        H_[i] = H_[i] -1

ans = 1
for i in range(N-1):
    if H_[i+1] < H_[i]:
        ans = 0
if ans == 0:
    print("No")
else:
    print("Yes")

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

if n == 2:
  if h[1] < h[0]:
    h[1]-=1
    if h[1] < h[0]:
      result='No'

print(result)

Solution (Python):
import numpy as np

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

err = 0
f = 0
for i in range(n-1):
  t = h[i+1] - h[i]
  if t>=-1 and f>=-1 and not(t==-1 and f==-1):
    pass
  else:
    err = 1
    break
    
  if t!=0:
    f = t
  
if err==1:
  print('No')
else:
  print('Yes')

Solution (Python):
a = int(input())
b_str = list(input().split())
b = [int(s) for s in b_str]

check_cnt = 0
check_flg = True

max_item = 0

for idx, item in enumerate(b):
	
	if idx == 0:
		max_item = item
		continue
	
	if max_item <= item:
		max_item = item
		continue
	elif max_item - 1 == item:
		continue
	else:
		check_flg = False
		break
		
if	check_flg:
	print('Yes')
else:
	print('No')

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

prev_h = -1
downflg = False
for h in Hs:
    
    if not downflg:
        if  h - prev_h >= 0:
            prev_h = h
        elif h - prev_h == -1:
            downflg = True
            prev_h = h
        else:
            print("No")
            sys.exit()
    
    else:
        if h - prev_h > 0:
            downflg = False
            prev_h = h
        if h - prev_h == 0:
            prev_h = h
        else:
            print("No")
            sys.exit()
    
    prev_h = h
print("Yes")

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

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

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

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

Solution (Python):
import numpy as np
 
n = int(input())
h = list(map(int, input().split()))
 
h = np.array(h)
 
for i in range(len(h)-1):
   if h[i] < h[i+1]:
       h[i+1] -= 1
np.diff(h-1, n=1)
 
minus = [i for i in np.diff(h-1, n=1) if i < 0]
 
if len(minus) > 0:
    print('No')
else:
    print('Yes')

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


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

for j in range(n-2):
    if h[j] - h[j+1]  == 1:
        for k in range(j,n-2):
            if h[k+1] - h[k+2] == 0:
                continue
            if h[k+1] - h[k+2] == 1:
                w = 0
                break
            break


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

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

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

n=int(input())
h=list(map(int,input().split()))
l=h
s=[]
t=max(h)

for i in range(n-1):
        if l[i]-1==l[i+1]:
                l[i]=l[i]-1
                s.append(l[i])
        elif l[i]==l[i+1] and l[i]==t:
                l[i]=l[i]-1
                s.append(l[i])
        elif l[i]-1>l[i+1]:
                break
        elif l[i]-1<l[i+1]:
                s.append(l[i])
                continue

s.append(h[n-1])
s.sort()
if len(s)==n:
        if l==s:
                print('Yes')
        else:
                print('No')

else:
        print('No')

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

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

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

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

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

Solution (Python):
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
h_list = [int(elem) for elem in fin().split()]
original_h_list = [x for x in h_list]

flag = True
result = 'Yes'
h_list = [-1] + h_list + [10**10]
min_h_list = min(h_list[1:-1])
for i in range(1, len(h_list)-1):
    if h_list[i] - 1 >= h_list[i-1]:
        h_list[i] -= 1

for i in range(1, len(h_list)-1):
    if not (h_list[i-1] <= h_list[i] <= h_list[i+1]):
        result = 'No'

print(result)

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

for i in range(n-1):
    if h[i]>h[i+1]:
        judge=False
        break
    elif h[i]!=h[i+1]:
        h[i+1]=h[i+1]-1

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

Solution (Python):
N = int(input())
li = list(map(int,input().split()))
li2 = []
key =[0] 
cnt = 0
flg = True
if N == 1:
    ans ="Yes"
    flg = False
while flg :
    cur1 = li[cnt]
    cur2 = li[cnt+1]
    sa = cur2 - cur1
    if key[cnt] == 0:
        if sa < -1:
            ans = "No"
            flg = False
        elif sa == -1:
            key.append(1)
            cnt += 1
        else:
            key.append(0)
            cnt += 1
    else:
        if sa < 0:
            ans = "No"
            flg = False
        elif sa == 0:
            key.append(1)
            cnt += 1
        else:
            key.append(0)
            cnt += 1
    if cnt == len(li)-1:
        ans = "Yes"
        flg = False
print(ans)

Solution (Python):
n = int(input())
H_l = list(map(int, input().split()))
tmp_max = 0
flg_nd = True
for i in range(n):
    if tmp_max - H_l[i] >=2:
        flg_nd = False
        break;
    if H_l[i] > tmp_max:
        tmp_max = H_l[i]

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

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

print("Yes")

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

lst_s = s.split()
lst = [int(str) for str in lst_s]
i = 0
flg = 0

if lst[0] > 1:
  lst[0] -= 1

while i <= n-2 and n > 1:
  if lst[i] < lst[i+1]:
    lst[i+1] -= 1
  elif lst[i] > lst[i+1]:
    flg = 1  
  i += 1

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

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

prev = h[0]
flag = True
for i in range(len(h) - 1):
    if prev > h[i+1]:
        if flag and prev - h[i+1] == 1:
            flag = False
            prev = h[i+1]
        else:
            print('No')
            break
    elif prev == h[i+1]:
        prev = h[i+1]
    else:
        flag = True
        prev = h[i+1]
else:
    print('Yes')

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

result = "Yes"

for i in range(0, N-1):
  if H[i] >= H[i+1]:
    if i == 0:
      H[i] -= 1
    elif i >= 1 and H[i-1] < H[i]:
      H[i] -= 1
  
  if H[i] > H[i+1]:
    result = "No"
    break

print(result)

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
if n>3:
  m=h.pop(0)
  for i in h:
    if m<i:
      m=i
    elif m-1>i:
      ans="No"
      break
elif n==3 and (h[0]-1>h[2] or h[1]-1>h[2]):
    ans="No"
elif n==2 and h[0]-1>h[1]:
    ans="No"
print(ans)

Solution (Python):
import sys

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

ans = True
if n == 1:
    print('Yes')
    sys.exit()

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

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

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

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

    if H[i-1] == H[i]:
        if H[i] > H[i+1]:
            fl = False
            break

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

if fl == True:
    print('Yes')
elif fl == False:
    print('No')

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

i = N - 1
while i > 0:
  if H[i-1] > H[i] + 1:
    print('No')
    break
  if H[i-1] == H[i] + 1:
    H[i-1] -= 1
  i -= 1
if i==0:
  print('Yes')

Solution (Python):

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

flug = 0
for index in range(1,N):
  if int(H[index]- H[index - 1]) < -1 :
    print("No")
    flug = 1
    break
  else:
    if int(H[index] < H[index - 1]):
      H[index] = H[index-1]
   
    continue
if flug == 0:
  print("Yes")

Solution (Python):
n = int(input())
h = list(map(lambda x: int(x), input().split()))
flag = 0
mx = 0
for hi in h:
    if hi > mx:
        mx = hi
    if hi <= (mx - 2):
        flag = 1
        break
print('YNeos'[flag::2])

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

Solution (Python):
n = int(input())
H = list(map(int,input().split()))
 
flag = 0
tmp = H[0]
d = len(H) - 1
if d == 0:
    print("Yes")
    exit()
 
if d == 1:
    if H[0] - 1 <= H[1]:
        print("Yes")
        exit()
    print("No")    
    exit()
 
H[0] -= 1
for i in range(1, len(H)):
    if  not(H[i - 1] > H[i] - 1):
        H[i] -= 1
    if H[i] > H[i + 1]:
        print("No")
        exit()

    if i + 1 == d:
        break    
print("Yes")

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

pos = True

for i in range(n-2, -1, -1):
    if(arr[i] > arr[i+1]):
        if(arr[i] - arr[i+1] > 1):
            pos = False
            break
        else:
            arr[i] = arr[i+1]

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

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

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

print('Yes')

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
D = [0] * N
i = 0
judge = True
while i < N - 1:
    h1 = H[i]
    h2 = H[i + 1]
    if h2 - h1 < 0:
        if D[i] == 0:
            H[i] -= 1
            D[i] = 1
            i -= 1
            if i < 0:
                i == 0
        else:
            judge = False
            break

    else:
        i += 1

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

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

piyo = True
dame = False
if N == 1:
  print("Yes")
else:
  for i in range(0,N-1):
    huga = H[i+1] - H[i]
    
    if huga < -1:
      dame = True
      break
    elif huga == -1:
      if piyo == True:
        H[i] = H[i] - 1
      piyo = True
    elif huga > 0:
      H[i+1] = H[i+1] - 1
      piyo = False
  
  for i in range(0,N-1):
    huga = H[i+1] - H[i]
    
    if huga < 0:
      dame = True
      break
  if dame == True:
    print("No")
  else:
    print("Yes")

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

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

print("Yes")

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

flag = True
level = h[0]

for i in range(n-1):
  if h[i] < h[i+1]:
    pass
  elif h[i] == h[i+1]:
    if level > h[i] - 1:
      pass
    else:
      h[i] -= 1
  else:
    if level > h[i] - 1:
      flag = False
      break
    else:
      h[i] -= 1
      if h[i] == h[i+1]:
        level = h[i]
      else:
        flag = False
        break

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

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

max_h = 0
for h in H:
    if h >= max_h:
        max_h = h
    else:
        if max_h - 1 == h:
            continue
        else:
            print("No")
            break
else:
    print("Yes")

Solution (Python):



import sys
input = sys.stdin.readline


def main():
    n = int(input())
    h = [i for i in map(int, input().split())]

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):

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

count = 0
diff = 0

if N == 1:
    print("Yes")
else:
    minn = 1
    tmp = 0
    for i in range (0, N):
        if minn <= H[i] - 1:
            H[i] -= 1
            minn = H[i]
        elif minn <= H[i]:
            minn = H[i]
        else:
            tmp = 1

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