Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import sys

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

#w=input()
from operator import itemgetter
from sys import stdin

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

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"



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

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








#print(type(brray[0][0]))
#print(brray)

"列数に関して自由度の高い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)
'''




#s=input()

#print(a[0])
#print([a])















#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"





#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)



##############################################################################################
##############################################################################################
#under this line explains example calculation





#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''









#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)

#A.insert(index, 5)
#print(index)
#print(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






########################################################################
########################################################################

#print(b2)



#print(b3)

def main():

    w=1
    j=0
    k=0
    n=int(input())
    h=list(map(int, input().split(" ")))
    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):
        #print(h[i], h[i+1], h[i+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")

    #r=int(input())
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        
    #    dp[i] += [a]
    #    dp[i] += [b]
        
        
    #print(dp)


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


    #s=input()
    #int取るとstrでも行ける
    #print(a)
    
    pin_l=["x" for i in range(10)]
    #print(pin_l)

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


    #print(ls[2:5])
    

    #print(ls[:-3])
    

    #print(ls[:4:2])
    
    
    
    #print(ls[::2])
    

if __name__ == "__main__":
    main()


# -*- coding: utf-8 -*-
import sys

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

#w=input()
from operator import itemgetter
from sys import stdin

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

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"



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

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








#print(type(brray[0][0]))
#print(brray)

"列数に関して自由度の高い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)
'''




#s=input()

#print(a[0])
#print([a])















#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"





#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)



##############################################################################################
##############################################################################################
#under this line explains example calculation





#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''









#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)

#A.insert(index, 5)
#print(index)
#print(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






########################################################################
########################################################################

#print(b2)



#print(b3)

def main():
    
    w=1
    j=0
    k=0
    dl=[]
    n=int(input())
    h=list(map(int, input().split(" ")))
    for i in range(1,n):
        print(h[-(i)])
        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")
    
    
    
    


    #r=int(input())
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        
    #    dp[i] += [a]
    #    dp[i] += [b]
        
        
    #print(dp)


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


    #s=input()
    #int取るとstrでも行ける
    #print(a)
    
    pin_l=["x" for i in range(10)]
    #print(pin_l)

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


    #print(ls[2:5])
    

    #print(ls[:-3])
    

    #print(ls[:4:2])
    
    
    
    #print(ls[::2])
    

if __name__ == "__main__":
    main()


# -*- coding: utf-8 -*-
import sys

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

#w=input()
from operator import itemgetter
from sys import stdin

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

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"



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

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








#print(type(brray[0][0]))
#print(brray)

"列数に関して自由度の高い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)
'''




#s=input()

#print(a[0])
#print([a])















#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"





#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)



##############################################################################################
##############################################################################################
#under this line explains example calculation





#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''









#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)

#A.insert(index, 5)
#print(index)
#print(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






########################################################################
########################################################################

#print(b2)



#print(b3)

def main():

    w=1
    j=0
    k=0
    dl=[]
    n=int(input())
    h=list(map(int, input().split(" ")))
    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()
    #print("Yes")
    #print(dl)
    


    #r=int(input())
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        
    #    dp[i] += [a]
    #    dp[i] += [b]
        
        
    #print(dp)


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


    #s=input()
    #int取るとstrでも行ける
    #print(a)
    
    pin_l=["x" for i in range(10)]
    #print(pin_l)

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


    #print(ls[2:5])
    

    #print(ls[:-3])
    

    #print(ls[:4:2])
    
    
    
    #print(ls[::2])
    

if __name__ == "__main__":
    main()


# -*- coding: utf-8 -*-
import sys

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

#w=input()
from operator import itemgetter
from sys import stdin

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

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"



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

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








#print(type(brray[0][0]))
#print(brray)

"列数に関して自由度の高い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)
'''




#s=input()

#print(a[0])
#print([a])















#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"





#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)



##############################################################################################
##############################################################################################
#under this line explains example calculation





#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''









#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)

#A.insert(index, 5)
#print(index)
#print(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






########################################################################
########################################################################

#print(b2)



#print(b3)

def main():
    
    w=1
    j=0
    k=0
    dl=[]
    n=int(input())
    h=list(map(int, input().split(" ")))
    for i in range(1,n):
        #print(h[-(i)])
        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")
    
    
    
    


    #r=int(input())
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        
    #    dp[i] += [a]
    #    dp[i] += [b]
        
        
    #print(dp)


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


    #s=input()
    #int取るとstrでも行ける
    #print(a)
    
    pin_l=["x" for i in range(10)]
    #print(pin_l)

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


    #print(ls[2:5])
    

    #print(ls[:-3])
    

    #print(ls[:4:2])
    
    
    
    #print(ls[::2])
    

if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted