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

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


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
if n == 1:
    print('Yes')
    exit(0)

for i in range(n-1, 0, -1):
    if l[i-1] - l[i] == 1:
        l[i-1] = l[i]
    elif l[i-1] - l[i] > 1:
        print('No')
        exit(0)

print('Yes')

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

print(ans)

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

hmax = 0

for i in range(n):
	if ls_h[i] <= hmax - 2:
		print('No')
		break
	elif ls_h[i] > hmax:
		hmax = ls_h[i]
		if i == n - 1:
			print('Yes')
	elif i == n - 1:
		print('Yes')

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

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

h = 0
for nh in H:
    if h > nh:
        print('No')
        exit()
    else:
        h = max(h, nh - 1)
else:
    print('Yes')

Solution (Python):

from sys import exit

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


def main():
    n = ii()
    a = li()

    a = reversed(a)

    m = 100000000000
    for i in a:
        m = min(m,i)
        if i > m+1:
            print("No")
            exit()

    print("Yes")



    
main()

Solution (Python):
n = int(input())
h = input()
str_list = []
ans = "Yes"
str_list = h.split(" ")

for j in range (len(str_list)-1):

  if(int(str_list[j]) < int(str_list[j+1])):
    str_list[j+1] = str(int(str_list[j+1])-1)
  elif(int(str_list[j]) > int(str_list[j+1])):
    ans = "No"
    break

print(ans)

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

flag = True
for i in range(n-1, 0, -1):
    if A[i-1] >= A[i] + 2:
        flag = False
        break
    elif A[i-1] == A[i] + 1:
        A[i-1] -= 1

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

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




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


        
if s==sorted(s):
    print("Yes")
else:
    print("No")

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

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

head = 0

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

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

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

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

ans = 'Yes'
for i in range(-1, -n, -1):
  if h[i]+1 == h[i-1]:
    h[i-1] -= 1
  elif h[i-1] - h[i] > 1:
    ans = 'No'
    break

print(ans)

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

Solution (Python):



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








pre = H[0] - 1  
for h in H[1:]:
    if h > pre:
        pre = h - 1
    elif h == pre:
        pre = h
    elif h < pre:
        print('No')
        exit()

print('Yes')

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

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

        elif h_list[i] > h_list[i+1]:
            print("No")
            exit()

    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
li = list(map(int, input().split()))
ans = "Yes"
count = N - 1
while count >= 1:
    if li[count] - li[count-1] >= 0:
        pass
    elif li[count] - li[count-1] == -1:
        li[count-1] -= 1
    else:
        ans = "No"
        break
    count -= 1
print(ans)

Solution (Python):
import sys

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

max_hight = 0
for i in range(N):
    if i != 0 and H[i] < H[i-1]:
        print('No')
        sys.exit()

    if i != 0 and H[i] < max_hight:
        print('No')
        sys.exit()

    if i != 0 and H[i] != H[i-1]:
        H[i] -= 1
    max_hight = max(max_hight, H[i])

print('Yes')

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



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

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

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

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

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

pre_h = float('inf')
for h in H:
    if pre_h >= h:
        pre_h = h
    elif pre_h == h-1:
        pre_h = h-1
    else:
        print('No')
        exit(0)
print('Yes')

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
h.reverse()
t=1
i=0
while i<n-1:
    if h[i]<h[i+1]:
        h[i+1]-=1
        if h[i]<h[i+1]:
            t=0
            print('No')
            break
        else:
            i+=1
    else:
        i+=1
if t:
    print('Yes')

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

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

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

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

Solution (Python):
"""
思い入れ:
これは、たしか僕がはじめて解こうとしたC問題であり、
はじめて解けなかったC問題でもある。
↓
解けなかった
"""
n = int(input())
Hs = list(map(int, input().split()))
ans = 'Yes'

for i in range(n-1):
    if Hs[i] > Hs[i+1] + 1:
        ans = 'No'
        break
    elif Hs[i] == Hs[i+1]+1:
        Hs[i+1] += 1

print(ans)

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

l[0] -= 0

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

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

def main():
    n = int(input())
    h_ls = tuple(map(int, input().split()))
    h_ = h_ls[-1]

    for h in h_ls[-2::-1]:
        if h > h_:
            if h - 1 == h_:
                continue
            print('No')
            quit()
        h_ = h
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


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

    cur_max = 0
    for i in range(N):
        if cur_max - H[i] >= 2:
            print(NO)
            return 
        cur_max = max(cur_max,H[i])
    print(YES)
    return


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

if __name__ == '__main__':
    main()

Solution (Python):

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

Solution (Python):

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

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    H = LI()
    H = [0] + H + [10**9+1]
    for i in range(1, N+1):
        l = H[i-1]
        m = H[i]
        r = H[i+1]
        if m > r:
            if l == m:
                print("No")
                return
            elif l < m:
                if not H[i] - 1 == r:
                    print("No")
                    return
            else:
                print("No")
                return
        else:
            pass
        if l != m:
            H[i] -= 1
    print("Yes")

main()

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

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

m=h[0]
judge=True
for i in range(n-1):
    if h[i+1]>=h[i] and m<=h[i+1]:
        continue
        m=h[i+1]
    else:
        h[i]-=1
        if h[i+1]>=h[i] and m<=h[i+1]:
            m=h[i+1]
            continue
        else:
            judge=False

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

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

flag=True
max_num=h_[0]
for i in range(1,n):
    if max_num > h_[i]:
        if max_num - h_[i] >=2:
            flag=False
            break
        else:
            max_num=max_num
    else:
        max_num=h_[i]

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

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]:
        h[i]-=1
    elif h[i-1]==h[i]:
        pass
    else:
        ans = "No"
        break

print(ans)

Solution (Python):

def main():
    n = int(input())
    h  = list(map(int, input().split()))
    h = h[::-1]
    
    if n == 1:
        print('Yes')
    else:
        for i in range(n-1):
            if h[i+1] - h[i] == 1:
                h[i+1] -= 1

            elif h[i+1] <= h[i]:
                pass

            elif h[i+1] > h[i]:
                print('No')
                break 

            if i == n-2:
                print('Yes')
                break

    
    
if __name__ == '__main__':
    main()

Solution (Python):

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

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

print(ans)

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

Solution (Python):
N = int(input())
numbers = [int(i) for i in input().split()]
 
def build_stairs(N, numbers):
    for i in range(1, N): 
        stair1 = numbers[-i]
        stair2 = numbers[-(i + 1)]
        diff_stair = stair1 - stair2
        if diff_stair >= 0:
            pass
        elif diff_stair <= -2:
            return False
        elif diff_stair == -1:
            numbers[-(i + 1)] -= 1
    return True

if build_stairs(N, numbers):
    print('Yes')
else :
    print('No')

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
flg = 0
arr2 = [arr[0]]
for i in range(1,n):
	if arr[i] > arr2[i-1]:
		arr2.append(arr[i]-1)
	else:
		arr2.append(arr[i])

for j in range(n-1):
	if arr2[j] > arr2[j+1]:
		flg = 1

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

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

def build_stairs(N, numbers):
    for i in range(1, N): 
        stair1 = numbers[-i]
        stair2 = numbers[-(i + 1)]
        diff_stair = stair1 - stair2
        if diff_stair >= 0:
            pass
        elif diff_stair <= -2:
            return False
        elif diff_stair == -1:
            numbers[-(i + 1)] -= 1
    return True

if build_stairs(N, numbers):
    print('Yes')
else :
    print('No')

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

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

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

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
t = True
for h0, h1 in zip(H, H[1:]):
    if t:
        if h0 == h1 + 1:
            t = False
        elif h0 > h1 + 1:
            print("No")
            break
    else:
        if h0 > h1:
            print("No")
            break
        elif h0 < h1:
            t = True
else:
    print("Yes")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
i = n-1
while (i > 1):
    if (a[i-1] > a[i]):
        a[i-1] -= 1
    i -= 1

j = 0
c = 0

while (j < n-1):
    if (a[j] > a[j+1]):
        c += 1
    j += 1
if (c == 0):
    print('Yes')
else:
    print('No')

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

for i in range(1,n):
  if H[i]>t+1:
    print("No")
    break
  
  else:
    t=min(H[i],t)

else:
  print("Yes")

Solution (Python):
N = int(input())
h = list(map(int,input().split()))
ans = True
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]:
        ans = True
    else:
        ans = False
        break
if ans:
    print('Yes')
else:
    print('No')

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

flag = True
count = 0
for i in range(len(h)-1):
    if h[i] < h[i + 1]:
        count = 0
    else:
        count += h[i] - h[i+1]
        if count >= 2:
            flag = False
            print('No')
            exit()

print('Yes')

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

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

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

Solution (Python):
N = int(input())
k = list(map(int, input().split()))
base = k[0]
ans = "Yes"
max = 0

for i in range(1, N):
  
  
  if base-1 >= max:
    max = base -1;
  
  if (base-1 <= k[i]) and (max <= k[i]):
    pass
  else:
    ans = "No"
    break
  base = k[i]
    
print(ans)

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

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

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

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

if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
h = list(map(int,input().split()))
h.reverse()
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()))

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


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

print("Yes")

Solution (Python):
N = int(input())
H = list(map(int, input().split()))
Hmax = H[0]
flag = True
for height in H:
    if height <= Hmax - 2:
        flag = False
        break
    Hmax = max(Hmax, height)

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

Solution (Python):
import sys

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

for i in range(len(heights) - 1):
    if (heights[i] < heights[i+1]) and heights[i+1] != 1:
        heights[i+1] += -1
    if heights[i] > heights[i+1]:
        print('No')
        sys.exit(0)

print('Yes')

Solution (Python):
import copy
N = int(input())
H = list(map(int,input().split()))
ans = 'Yes'
H2 = H.copy()
for n in range(N):
    H2[n] -= 1
H3 = [H2[0]]
for n in range(1,N):
    if H3[-1] <= H2[n]:
        H3.append(H2[n])
    elif H3[-1] <= H[n]:
        H3.append(H[n])
    else:
        ans = 'No'
        break
print(ans)

Solution (Python):
from itertools import *
from math import *

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

flag = True
for j in range(N - 2, -1, -1):
    if H[j] <= H[j + 1]:
        pass  
    elif H[j] == H[j + 1] + 1:
        H[j] -= 1
    else:
        flag = False
        break

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

Solution (Python):
N=int(input())
H=list(map(int,input().split()))
set=0
flag=True
for n in range(N):
    if set<H[n]:
        set=H[n]-1
    elif set>H[n]:
        print("No")
        flag=False
        break
if flag==True:
    print("Yes")

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

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

for ii in reversed( range(1, N) ):
    if H[ii-1] <= H[ii]:
        continue
    elif H[ii-1] - 1 == H[ii]:
        H[ii-1] -= 1
    else:
        print('No')
        exit()

print('Yes')

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

Solution (Python):
import sys

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

for i in range(n-1) :
  j = (n-1)-i
  if h[j-1]-h[j] >= 2 :
    print('No')
    sys.exit()
  elif h[j-1]-h[j] == 1 :
    h[j-1] -= 1

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

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

Solution (Python):
def calculate(arr):

    if len(arr) <= 1:
        return True

    index = len(arr) - 1
    while index >= 1:
        if arr[index - 1] - arr[index] > 1:
            return False
        if arr[index - 1] - arr[index] == 1:
            arr[index - 1] = arr[index -1 ] - 1
        index = index - 1
    return True




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

if len(arr) != N:
    print("No")
else:
    result = calculate(arr)
    if result:
        print("Yes")
    else:
        print("No")

Solution (Python):


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

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

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

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

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

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
H = MAP()

max = 0
for h in H:
	if h >= max:
		max = h
		continue
	if h < max-1:
		
		print('No')
		sys.exit()
print('Yes')

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

flag = True

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

print('Yes') if flag 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]):
        H[i+1] -= 1
    

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

print('Yes')

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

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


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


for i in range(n):
    if i+1<n and a[i]>a[i+1]:
        print("No")
        exit()
print("Yes")

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

h.insert(len(h), float("inf"))

ans = "Yes"
border = 1
for i in range(n):
    if h[i] > h[i+1]:
        _h = h[i] - 1
        if border > _h or _h > h[i+1]:
            ans = "No"
            break

        border = _h

print(ans)

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

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

isYes = True
for i in reversed(range(N)):
    if i == 0:
        break
    if H[i-1] > H[i]:
        H[i-1] -= 1
        if H[i-1] > H[i]:
            print("No")
            isYes = False
            break
if isYes:
    print("Yes")

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

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

    h_list[0] -= 1
    ans = 'Yes'
    for i in range(0, len(h_list)-1):
        if h_list[i] == h_list[i+1]:
            pass
        elif h_list[i] > h_list[i+1]:
            ans = 'No'
        else:
            h_list[i+1] -= 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

print('Yes')

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

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


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

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

Solution (Python):
def solve(N, H):

    if(N == 1):
        return 1
    
    else:

        highest = H[0]

        for i in range(1,N):

            if(highest - H[i] > 1):
                return 0

            else:
                if(highest < H[i]):
                    highest = H[i]
    
    return 1


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

if(solve(N,H) == 1):
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()] 
ans = 'Yes'
down = True
if H[0] == 0:
    down = False
 
for i in range(N-1):
    if down:
        if H[i+1] - H[i] >= 0:
            down = True
        elif H[i+1] - H[i] == -1:
            down = False
        else:
            ans = 'No'
            break
    else:
        if H[i+1] - H[i] >= 1:
            down = True
        elif H[i+1] - H[i] == 0:
            down = False
        else:
            ans = 'No'
            break
print(ans)

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

Solution (Python):

import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())


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

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

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

is_true = False
for i in range(0, len(H)):
  if len(H) <= 1:
    print('Yes')
    is_true = True
  elif i == 0:
    if H[0] <= H[1]:
      H[1] -= 1
    elif H[0] > H[1]+1:
      break
  elif i != N-1:
    if H[i] < H[i+1]:
      H[i+1] -= 1
    elif H[i] > H[i+1]:
      break
  elif i == N-1:
    print('Yes')
    is_true = True

if is_true == False:
  print('No')

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] == 1:
        h[i] -= 1
        
    elif h[i] <= h[i+1]:    
        pass
    else:
        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]:
        H[i-1] -= 1
print('Yes' if all([H[i] <= H[i+1] for i in range(N-1)]) else 'No')

Solution (Python):
N = int(input())
H = [int(i) for i in input().split()]
H[0]-=1
s = True
for i in range(N-1):
    if H[i] < H[i+1]:
        H[i+1]-=1
    if H[i] > H[i+1]:
        s = False
        break
if s:
    print("Yes")
else:
    print("No")

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

for i in range(n):
    if i == 0 and h[i] != 1:
        h[i] -= 1
    elif i != 0:
        if h[i] < h[i-1]:
            print('No')
            flag = 1
            break
        elif h[i] > h[i-1]:
            h[i] -= 1

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    *nh, = map(int, read().split())
    n, h = nh[0], nh[1:]
    o = "Yes"
    for i in range(1, n):
        if h[i-1]<h[i]:
            h[i] -= 1
        if h[i-1]>h[i]:
            o = "No"
            break
    print(o)

if __name__ == "__main__":
    main()

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

h1=[x-1 for x in h]

prev=h1[0]
for i in range(1,n):
  if prev <= h1[i]:
    prev = h1[i]
  elif prev <= h[i]:
    prev = h[i]
  else:
    print('No')
    exit(0)
  

print('Yes')

Solution (Python):

N = int(raw_input())
H = map(int, raw_input().split())

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

is_non_descend = True
for i in xrange(N-1):
    if H[i+1] > H[i]:
        H[i+1] -= 1
    if H[i+1] < H[i]:
        is_non_descend = False
        break

if is_non_descend:
    print "Yes"
else:
    print "No"

Solution (Python):

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


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