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 read_int():
    return int(input())
 
 
def read_int_n():
    return list(map(int, input().split()))
 
 
def read_str():
    return input()
 
 
def read_str_n():
    return list(map(int, input().split()))


def main():
    n = read_int()
    h = read_int_n()
    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')
            return
    print('Yes')

main()

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


if __name__ == '__main__':
    main()

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

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


def check():
    for i in range(1, N):
        if nums[i] == nums[i - 1]:
            continue
        elif nums[i] - 1 >= nums[i - 1]:
            nums[i] -= 1
            continue
        else:
            return "No"
    return "Yes"


print(check())

Solution (Python):
n = int(input())
h = [int(i) for i in input().split()]
max = 0
for i in h:
    if(i > max):
        max = i
    if(max-2 >= i):
        print("No")
        exit()
print("Yes")

Solution (Python):
N=int(input())
H = list(map(int,input().split( )))
i = 1
s = 0
max = 0

while i < N + 1:
    if max - 1 > H[i-1]:
        s = 1
        break
    if max < H[i-1]:
        max = H[i-1]
    i = i+1

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

Solution (Python):


import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
minhoge=hoge[n-1]
for i in range(1,n):
	t=n-1-i
	if(hoge[t]>minhoge+1):
		print("No")
		sys.exit()
	elif(hoge[t]<minhoge):
		minhoge=hoge[t]
	if(t==0):
		print("Yes")
		sys.exit()
print("Yes")

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

H.append(H[-1])
H.append(H[-1])



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

print("Yes")

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

Solution (Python):
n=int(input())
li = list(map(int,input().split()))
c=li[0]

for i in range(n):
    if c < li[i]:
        li[i]-=1
        c=li[i]
    elif c == li[i]:
        pass
    else:
        print("No")
        exit()

print("Yes")

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

li = reversed(li)
kotae = 0
nex = 10000000000

for i in li:
	if i <= nex:
		nex = i
		pass
	elif i-1 <= nex:
		nex =i-1
		pass
	else:
		print('No')
		break
	kotae += 1
if kotae == n:
	print('Yes')

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

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

h = list(map(int, input().split()))
highest = h[-1]
for hi in h[-2::-1]:
    if hi - highest >= 2:
        print("No")
        exit()
    elif hi - highest == 1:
        pass
    else:
        highest = hi
print("Yes")

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

Solution (Python):
N = int(input())
S = input().split(" ")
S = [int(c) for c in S]

lock = [0] * N




ans = True

for i in range(0, N - 1):
    if S[i + 1] == S[i]:
        lock[i+1] = lock[i]

    if S[i + 1] - S[i] >= 0:
        
        pass
    elif S[i + 1] - S[i] >= -1 and lock[i] == 0:
        
        S[i] -= 1
        lock[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()))
k=1
if N==1:
  answer='Yes'
else:
  while k<=N-1:
    if H[N-k-1]-H[N-k]>=2:
      answer='No'
      break
    elif H[N-k-1]-H[N-k]==1:
      H[N-k-1]=H[N-k-1]-1
      k+=1
    else:
      k+=1
  if k==N:
    answer='Yes'
  else:
    pass
print(answer)

Solution (Python):
N = int(input())
listH = [int(i) for i in input().split()]
right = listH[0]
result = "Yes"
for i in range(N-1):
    if right - listH[i+1] > 1:
        result = "No"
    elif listH[i] < listH[i+1]:
        right = listH[i+1]
print(result)

Solution (Python):
import numpy as np
import sys

def main():
    n = int(input())
    _list = list(input().split())
    _max = 0
    for i in range(1, n):
        tr = int(_list[i])
        if _max < tr:
            _max = tr
        
        if _max -1 > tr:
            print('No')
            sys.exit()

        

    print('Yes')




if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def main():
    
    N = int(input())
    Hs = list(map(int, input().split()))

    is_possible = True
    max_sofar = 0
    for H in Hs:
        if max_sofar > H:
            is_possible = False
            break
        max_sofar = max([H-1, max_sofar])

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


if __name__ == '__main__':
    main()

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

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

befor = 0

f = True

for i in range(num):
  if h[i] > befor:
    befor = h[i] - 1
  elif h[i] <  befor:
    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):
  if H[i] <= H[i+1]:
    continue
  H[i+1] += 1
  if H[i] <= H[i+1]:
    continue
  print("No")
  exit()
print("Yes")

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

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

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

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

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

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

Solution (Python):
A = int(input())
B = input().split()
H = [int(b) for b in B]

for i in range(A):
    if i == 0:
        continue

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

    elif H[A - i] < H[A - i - 1] - 1:
        print("No")
        exit()

print("Yes")

Solution (Python):
def calc(N, H):
    if (N == 1):
        return '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]):
                return 'No'
    return 'Yes'

N = int(input())
H = [int(s) for s in input().split(' ')]
print(calc(N, H))

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

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

result = "Yes"


for i in range(1, N)[::-1]:
    if H[i - 1] <= H[i]:
        continue
    elif H[i - 1] - H[i] == 1:
        H[i - 1] -= 1
    else:
        result = "No"

print(result)

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

flag = 'Yes'

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

print(flag)

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

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

prev = -100

bl = True
for x in H:
    if x < prev:
        bl = False
        break
    if x == prev:
        continue
    prev = x - 1

answer = 'Yes' if bl else 'No'
print(answer)

Solution (Python):


import sys

n= int(sys.stdin.readline())
h= [ int(x) for x in sys.stdin.readline().split() ]

flag= True
ans= "Yes"
for i in range(n-1):
    
    dh= h[i+1]-h[i]
    if dh<=-2:
        ans="No"
        break
    if dh==-1 and flag:
        flag= False
    elif dh==0:
        pass
    elif dh>=1:
        flag= True
    else:
        ans="No"
        break

print( ans )

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
che = h[len(h)-1]+1
for i in h[len(h)-2::-1]:
    if che < i :
        print("No")
        break
    if che != i+1:
        if che == i:
            che = i
        else: 
            che = i+1
else:
    print("Yes")

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

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

print(ans)

Solution (Python):
import sys
n = int(sys.stdin.readline())
h = [int(i) for i in sys.stdin.readline().split()]

def cond(h):
    if len(h) == 1:
        return True
    for index in range(n - 1):
        diff = h[index + 1] - h[index]
        if diff == 0:
            continue
        if diff > 0:
            h[index + 1] -= 1
            continue
        if diff < 0:
            return False
    return True

if cond(h):
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
Hlist = list(map(int, input().split()))
maxH = 0
a = True
for n in range(N):
    if maxH == Hlist[n]:
        maxH = Hlist[n]
    elif maxH < Hlist[n]:
        if maxH <= Hlist[n] - 1:
            maxH = Hlist[n] - 1
    else:
        a = False
        break
if a == True:
    print('Yes')
else:
    print('No')

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

s=0
for i in h:
    if s < i:
        s = i - 1
    elif s == i:
        pass
    else:
        print "No"
        break
else:
    print "Yes"

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
count = 0
max_i = 0
H.append(10**9 + 2)
for i in range(N):
  if H[i] > H[i + 1] + 1:
    count += 1
  if max_i - H[i] > 1:
    count += 1
  max_i = max(max_i,H[i])

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

Solution (Python):
N = int(input())
H = list(map(int,input().split()))
gap = [1]
for _ in range(N - 1):
    gap.append(H[_ + 1] - H[_])
for _ in range(1,N):
    if gap[-_] < 0:
        gap[-_] += 1
        gap[-_ - 1] -= 1
if min(gap) >= 0:
    print("Yes")
else:
    print("No")

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

Solution (Python):

import sys







"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def make_divisors(n):
    
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            
            return i
            
            


def n_to_10(X, n):
    if int(X / n):
        return n_to_10(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    h = ip.IL()
    m = max(h)
    flag = True
    for x in h[::-1]:
        
        if m < x-1:
            
            flag = False
        m = min(m, x)

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


main()

Solution (Python):
import sys

n = int(input())
h = list(map(int, input().split(' ')))
max = 0
for i in range(len(h)):
    if max < h[i]:
        max = h[i]
    if h[i]+2 <= max:
        print('No')
        sys.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+1] > H[i]:
        H[i+1] -= 1
    if H[i+1] < H[i]:
        print("No")
        exit()

print("Yes")

Solution (Python):
import sys, re, os
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 S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
h = LIST()


table = [0] * n
h[0] = h[0] - 1

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


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

    if count == n-1:
        print("Yes")
        exit()

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

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

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

heights[0] -= 1

for i in range(1, num_cell):
    if heights[i-1] < heights[i]:
        heights[i] -= 1
    elif heights[i-1] > heights[i]:
        break
else:
    print("Yes")
    exit(0)

print("No")
exit(0)

Solution (Python):
n=int(input())
hi=[int(i) for i in input().split(" ")]
pre=hi[0]
flag=0
if n==0:
    print("Yes")
for i in range(n-1):
    if hi[i+1] < pre-1:
        flag = 1
        break
    if hi[i+1] == pre-1:
        pre = hi[i+1]+1
    else:
        pre = hi[i+1]
if flag==0:
    print("Yes")
else:
    print("No")

Solution (Python):
def check(h):
    for i in range(len(h)-1, -1, -1):
        if i == len(h)-1:
            continue
        if h[i] <= h[i+1]:
            continue
        else:
            h[i] -= 1
        if h[i] <= h[i+1]:
            continue
        else:
            return False
    return True

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

if check(H):
    print('Yes')
else:
    print('No')

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

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
tmp=0
for i in range(N):
	if i==0:
		continue
	if L[i]<L[i-1]:
		if L[i]<L[i-1]-1 or L[i-1]-1<tmp:
			print("No")
			exit()
		else:
			L[i-1]=L[i-1]-1
			tmp=L[i-1]

else:
	print("Yes")

Solution (Python):
n = input()
nums = input()
nums = nums.split(" ")

before_num = int(nums[0])

flag = True
for num in nums:
    if before_num == -1:
        before_num = int(num)
        continue

    if before_num == int(num):
        continue
    elif before_num < int(num):
        before_num = int(num) - 1
    else:
        flag = False
        break
    
    
if flag:
    print("Yes")
else:
    print("No")

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

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

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

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
m=10**10
r="Yes"
for i in range(n):
  m=min(m,h[n-i-1])
  if h[n-i-1]-m>1:
    r="No"
    
print(r)

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

Solution (Python):


N=int(input())

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

H.reverse()


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

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

Solution (Python):

N = int(input())
H = list(map(int, input().split(" "))) + [10**9]

N_highest = 0

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

for i in range(0, N):
    current = H[i]
    next = H[i+1]

    N_highest = max(N_highest, current)

    if current > next:
        if N_highest - next > 1:
            print("No")
            exit()

print("Yes")

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

flag = True
prev = 1
for h in H:
    if prev > h:
        flag = False
        break
    prev = max(prev, h - 1)

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

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

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

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

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

def f():
    if N == 1:
        return True

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

        d = H[i + 1] - H[i]
        if d == 1:
            H[i + 1] -= 1
            continue

        return False

    return True


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

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

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

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

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

flag = 1
temp = h[0]
for i in range(len(h)-1):
    if(temp<h[i]):
        temp = h[i]
    if(temp-h[i+1]>=2):
        print("No")
        flag=0
        break
            
if(flag==1):
    print("Yes")

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

Solution (Python):

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

H[0] -= 1
for n in range(1,N):
	if H[n-1]==H[n]:
		continue
	H[n] -= 1

ans = True
for n in range(1,N):
	if H[n-1]>H[n]:
		ans = False

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

Solution (Python):
def main():
    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
            continue

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

main()

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


main()

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def existFalse(decr):
    for i in range(len(decr)):
        if i == False:
            return True
    return False

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

def solve(N: int, H: "List[int]"):
    decr = [False] * N
    isGood = False
    while existFalse(decr):
        changed = False
        for i in range(N-1):
            if H[i] > H[i+1]:
                if decr[i] == False:
                    H[i] -= 1
                    decr[i] = True
                    changed = True
        isGood = checkNonDecr(H)
        if isGood: 
            break
        if changed == False:
            break
    if isGood:
        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()))

flag = 'Yes'

h.reverse()
for i in range(n-1):
  if h[i] < h[i+1]:
    h[i+1] -= 1
  if h[i+1] > h[i]:
    flag = 'No'
    break
if h[-1] < 0:
  flag = 'No'
print(flag)

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

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

Solution (Python):
import numpy as np

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




tmp = [h[0]-1]

ok = True
for i in range(1, n):

    tmp[i-1]
    if h[i] - tmp[i-1] >= 1:
        tmp.append(h[i] - 1)
    elif h[i] - tmp[i-1] == 0:
        tmp.append(h[i])
    else:
        ok = False
        break
if ok:
    print("Yes")
else:
    print("No")

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

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

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

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

for i in H :
    if pre <= i:
        pre = i
        continue
    else:
        c = i+1
        if pre <= c:
            pre = pre
            continue
        else:
            pre = c
            count += 1

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

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

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

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

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

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

Solution (Python):

n = int(input())
boxes = list(map(int,input().split()))
answer = 'Yes'

for i in reversed(range(1,len(boxes))):
	
	if boxes[i-1] - boxes[i] > 1:
		answer = 'No'
		break
	elif boxes[i-1] - boxes[i] == 1:
		boxes[i-1] = boxes[i-1] -1

print(answer)

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

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

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

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

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

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

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    HL = list(map(int, sys.stdin.readline().split()))

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

    print("Yes")

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