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

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

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

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
    elif H[i-1] <= H[i]:
        continue
    else:
        print("No")
        exit()
print("Yes")

Solution (Python):
from sys import *

n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
last = arr[n - 1]
for i in range(n - 1, -1, -1):
	if arr[i] > last:
		d = arr[i] - last
		if d > 1:
			print("No")
			exit(0)
	last = min(last, arr[i])
print("Yes")

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

h=[int(x) for x in input().split()]
m=h[0]
for i in range(n):
  
  
  if h[i]<m-1:
    print("No")
    exit()
  m=max(m,h[i])
print("Yes")

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

Solution (Python):
n = int(input())
nums = list(map(int,input().split()))
tall = 0
for i in nums:
    if tall - i >=2:
        print('No')
        exit()
    tall = max(tall,i)
print('Yes')

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] < -1:
        print("No")
        quit()

print("Yes")

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

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

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

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

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
base=0
for h in H:
    if base>h:
        print("No")
        break
    base=max(base,h-1)
else:
    print("Yes")

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

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

    elif h[i] - h[i + 1] == 1:
        if x == 1:
            print('No')
            break
        else:
            x = 1


    elif h[i] - h[i + 1] < 0:
        x = 0

else:
    print('Yes')

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

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:
        print('No')
        break

    elif  h[i-1] - h[i] == 1:
        h[i-1] -= 1

else:
    print('Yes')

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

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

Solution (Python):
n = int(input())
hoge_list = list(map(int,input().split()))
h_list = hoge_list[::-1]
mae = h_list[0]
s = 0
for h in h_list:
  if h <= mae:
    mae = h
  elif h-1 == mae:
    mae = h-1
  else:
    print('No')
    s += 1
    break
if s == 0:
  print('Yes')

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

s=[]
for i in range(n-1,-1,-1):
    s.append(h[i])

for j in range(n-1):
    if s[j]+1<s[j+1]:
        print("No")
        exit()
    elif s[j]+1==s[j+1]:
        s[j+1]-=1

print("Yes")

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

Solution (Python):
def main():
    input()
    t = list(map(int, input().split()))
    m = 0
    flg = True
    for i in range(len(t)):
        if 0 == i or i == len(t) - 1:
            continue
        if t[i-1] < t[i]:
            t[i] -= 1
        if t[i - 1] <= t[i] <= t[i + 1]:
            pass
        else:
            print('No')
            exit()
    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    n=I()
    h=L()
    for i in reversed(range(1,n)):
        if h[i]<h[i-1]:
            h[i-1]-=1
            if h[i]<h[i-1]:
                print('No')
                exit()
    for i in range(n-1):
        if h[i]>h[i+1]:
            print('No')
            exit()
    print('Yes')

if __name__=='__main__':
    main()

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

hgh = la[0]
for i in range(N):
    if la[i] > hgh:
        hgh = la[i]
    elif la[i] < hgh - 1:
        print("No")
        exit()

print("Yes")

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

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

Solution (Python):
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque



def input1():
	return int(input())


def input2():
	return map(int,input().split())


def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets


def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	
	return fact(x+y)/fact(x)/fact(y)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True

n=input1()

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from collections import Counter
def resolve():
    N,=pin()
    H=lispin()
    for i in range(1,N):
        if H[i]-H[i-1]>0:
            H[i]-=1
    cond=1
    for j in range(1,N):
        if H[j]-H[j-1]<0:cond=0;break
    print(["No","Yes"][cond])
    

resolve()

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

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *h = map(int, read().split())
h = h[::-1]
for i, (bf, af) in enumerate(zip(h, h[1:])):
    if bf + 1 < af:
        print('No')
        exit()
    if bf < af:
        h[i + 1] -= 1
print('Yes')

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

Solution (Python):


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

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



List=[]
for i in range(N-1):
    List.append(H[i+1]-H[i])

count=0
for i in range(len(List)):
    count+=List[i]
        
    if count>=1:
        count=0
    if count<=-2:
        count=-2
        break

print("Yes" if count>=-1 else "No")

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

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

def resolve():
    def main():
        n=int(input())
        l=list(map(int,input().split()))
        ll=l[::-1]
        prev=ll[0]+1
        for i in range(n):
            if prev>=ll[i]:
                prev=ll[i]
            elif prev+1==ll[i]:
                prev=ll[i]-1
            else:
                return 'No'
        return 'Yes'
    print(main())
resolve()

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

def resolve():
    def main():
        n=int(input())
        l=list(map(int,input().split()))
        prev=0
        for i in range(n):
            if l[i]>prev:
                l[i]-=1
                prev=l[i]
            elif l[i]<prev:
                return 'No'
        return 'Yes'
    print(main())
resolve()

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

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

    if arr[i] > arr[i+1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
prev = 10**9+1
stair = "Yes"
hlen = len(h)
for i in range(n):
  hgt = h[hlen-1-i]
  if hgt>prev+1:
    stair = "No"
    break
  elif hgt==prev+1:
    prev = hgt-1
  else:
    prev = hgt
print(stair)

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

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

ans = 1
m = h[0]
for i in range (n):
    if (h[i] > m):
        m = h[i]
    elif (m-h[i] >= 2):
        ans = 0
        break

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

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

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

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

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

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

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

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

for i in range(len(hsrev)-1):
    if hsrev[i] < hsrev[i+1]:
        hsrev[i+1] -= 1
        if hsrev[i] < hsrev[i+1]:
            print("No")
            exit()

print("Yes")

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

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

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
H = LI()

a = INF
for i in reversed(range(n)):
    if H[i] > a + 1:
        print("No")
        exit()
    elif H[i] == a+1:
        H[i] -= 1
    a = min(a, H[i])

print("Yes")

Solution (Python):


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

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

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

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

print(ans)

Solution (Python):
import numpy as np

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

ans_1 = min(H[np.where(H==H.max())[0].min():]) > max(H)-2
ans_2 = all((H[1:] - H[:-1]) > -2)

print("Yes") if ans_1 & ans_2 else print("No")

Solution (Python):
import numpy as np

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

ans_1 = min(H[np.where(H==H.max())[0].min():]) > max(H)-2
tmp = H[1:] - H[:-1]
ans_2 = all(tmp > -2)

print("Yes") if ans_1 & ans_2 else print("No")

Solution (Python):
import numpy as np
N = int(input())
H = np.array(list(map(int, input().split())))

ans_1 = min(H[np.where(H==H.max())[0].min():]) > max(H)-2

tmp = H[1:] - H[:-1]

ans_2 = all(tmp > -2)

print("Yes") if ans_1 & ans_2 else print("No")

Solution (Python):
import numpy as np
N = int(input())
H = np.array(list(map(int, input().split())))

tmp_1 = H[np.where(H==H.max())[0].min():]
ans_1 = min(tmp_1) > max(H)-2

tmp2 = H[1:] - H[:-1]

ans_2 = all(tmp2 > -2)

print("Yes") if ans_1 & ans_2 else print("No")

Solution (Python):
def solve():
    n = int(input())
    h = list(map(int, input().split()))
    right = h[len(h)-1]
    flag = True
    for i in reversed(h):
        if i <= right:
            right = i
            continue
        elif i-1 == right:
            continue
        else:
            flag = False
            break
    if flag:
        print('Yes')
    else:
        print('No')


solve()

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

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

max_h=H[0]

flg =0
for i in range(N):
    max_h =max(max_h,H[i])

    if max_h-1>H[i]:
        flg+=1

if flg!=0:
    print('No')
else:
    print('Yes')

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

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

Solution (Python):


N = int(input())
H = [int(h) for h in input().split()]
ans = 'Yes'
for i in range(1, N):
    if H[i - 1] <= H[i] - 1:
        H[i] -=1
    if H[i] < H[i - 1]:
        print('No')
        break
else:
    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]>h[i+1] or h[i]>h[i-1]:
        h[i]-=1
for i in range(n-1):
    if h[i]>h[i+1]:
        print("No")
        quit()
print("Yes")

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

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

Solution (Python):
import sys, heapq

N = int(input())
H = list(map(int, sys.stdin.readline().rsplit()))

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

print("Yes")

Solution (Python):

import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        
        if n % k == 0:
            return False
            
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''












def main():
    
    w=1
    j=0
    k=0
    dl=[]
    n=int(input())
    h=list(map(int, input().split(" ")))
    for i in range(1,n):
        
        if h[-(i+1)] >h[-(i)]:
         if h[-(i+1)]-1 >h[-(i)]:
            print("No")
            sys.exit()
         h[-(i+1)]=h[-(i+1)]-1
    print("Yes")
    
    
    
    '''
    for i in range(n-1):
        dl.append(h[i]-h[i+1])
        if h[i]-h[i+1]>0:
            k=k+1
        if h[i]-h[i+1]>=2:
            print("No")
            sys.exit()
           
    if k >=2:
     print("No")
     sys.exit()
    
    

    if n == 1 :
        print("Yes")
        sys.exit()
    if n == 2 :
        if (h[0])>h[1] :
            print("No")
            sys.exit()
        print("Yes")
        sys.exit()


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


        elif (h[i]-1)>h[i+1] and h[i+1]==h[i+2]:
            print("No")
            sys.exit()


    if h[-2]-1 > h[-1]:
        print("No")
        sys.exit()
        


    print("Yes")
    '''


    
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    "1行1つの整数を入力を取得し、整数と取得する"
    
    
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    
    


    
    
    
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]
    

    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

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

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

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

Solution (Python):


from collections import deque
import sys

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


differ =0
ans="Yes"
max_h   =max(H)
max_index =H.index(max_h)

if max_index +1 <= N-1:
    if H[max_index]-1 > min(H[max_index+1:]):
        ans ="No"
        print(ans)
        sys.exit()

dq    =deque(H)
before  =dq.popleft()
for i in range(N-1):
    after   =dq.popleft()
    differ    =after - before
    
    if differ <-1:      
        ans ="No"
        break
  
    else:
        before = after

print(ans)

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

Solution (Python):
n = int(input())
H = list(map(int, input().split()))
flag = True
H[0] -= 1
for i in range(1, n):
    if H[i] - H[i - 1] > 0:
        H[i] -= 1
    elif H[i] - H[i - 1] < 0:
        flag = False

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

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

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

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

Solution (Python):
def main():
    N = int(input())
    H = [int(x) for x in input().split()]
    k = True
    for i in range(1, N):
        if H[i] >= H[i-1]:
            if H[i] - 1 >= H[i - 1]:
                H[i] = H[i] - 1
        else:
            k = False
            break
    if k:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
h = list(map(int, input().split()))
ans = 'Yes'
for i in range(n - 1, 0, -1):
    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()))

prev = -999
for i in range(n):
    if prev <= h[i]-1: prev = h[i]-1
    elif prev <= h[i]: prev = h[i]
    else:
        print("No")
        exit()

print("Yes")

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

print('Yes')

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

Solution (Python):
def main():
    N = int(input())
    H = list(map(int, input().split(' ')))
    left_h = 0
    for h in H:
        if left_h > h:
            print('No')
            exit(0)
        elif left_h == h:
            left_h = h
        else:
            left_h = h - 1
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
base=0
for h in H:
    if base>h:
        print("No")
        break
    base=max(base,h-1)
else:
    print("Yes")

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

max_ = 0
for i in range(n):
  if h[i]>=max_: max_=h[i]
  else:
    h[i]+=1
    if h[i]>=max_: max_=h[i]
    else: 
      print('No')
      exit(0)
print('Yes')

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

Solution (Python):

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

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

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

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

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

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

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


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

Solution (Python):
n = int(input())
li_h = list(map(int, input().split()))
sum_ = 0
if len(li_h) == 1:
  print('Yes')
else:
  b = True
  max_ = li_h[0]
  for i in range(len(li_h)):
    if li_h[i] > max_:
      max_ = li_h[i]
    if max_ - li_h[i] > 1:
      b = False
  if b:
    print('Yes')
  else:
    print('No')