Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
h_list = list(map(int, input().split()))
# print(N, h_list)

flag = True
# for i in range(0, N-1):
#     for j in range(i+1, N):
#         if (h_list[i]- h_list[j]) > 1:
#             flag = False
#             break
#     if not flag:
#         break

max_v = max(h_list)
left_max_index = h_list.index(max(h_list))
# print(left_max_index)

min_v = min(h_list)
right_min_index = [i for i, v in enumerate(h_list) if v == min(h_list)][-1]
# print(right_min_index)

if left_max_index < right_min_index:
    if (max_v - min_v) > 1:
        print("No")
        sys.exit(0)

for i in range(0, N-1):
    i_v = h_list[i]
    min_v = min(h_list[i+1:N])
#    print(i_v, min_v, h_list[i+1:N])
    if i_v - min_v > 1:
        flag = False
        break


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



Fixed submission:
N = int(input())                                                                                                                                                                                                                                                                
h_list = list(map(int, input().split()))                                                                                                                                                                                                                                        
# print(N, h_list)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                
flag = True                                                                                                                                                                                                                                                                     
for i in reversed(range(1, N)):                                                                                                                                                                                                                                                 
    diff = h_list[i-1]- h_list[i]                                                                                                                                                                                                                                               
#    print(i, diff)                                                                                                                                                                                                                                                             
    if diff >= 2:                                                                                                                                                                                                                                                               
        flag = False                                                                                                                                                                                                                                                            
        break                                                                                                                                                                                                                                                                   
    elif diff == 1:                                                                                                                                                                                                                                                             
        h_list[i-1] -= 1                                                                                                                                                                                                                                                        
    else:                                                                                                                                                                                                                                                                       
        pass                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                
if flag:                                                                                                                                                                                                                                                                        
    print("Yes")                                                                                                                                                                                                                                                                
else:                                                                                                                                                                                                                                                                           
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h_list = list(map(int, input().split()))
# print(N, h_list)

flag = True
# for i in range(0, N-1):
#     for j in range(i+1, N):
#         if (h_list[i]- h_list[j]) > 1:
#             flag = False
#             break
#     if not flag:
#         break

for i in range(0, N-1):
    i_v = h_list[i]
    min_v = min(h_list[i+1:N])
#    print(i_v, min_v, h_list[i+1:N])
    if i_v - min_v > 1:
        flag = False
        break


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


Fixed submission:
N = int(input())                                                                                                                                                                                                                                                                
h_list = list(map(int, input().split()))                                                                                                                                                                                                                                        
# print(N, h_list)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                
flag = True                                                                                                                                                                                                                                                                     
for i in reversed(range(1, N)):                                                                                                                                                                                                                                                 
    diff = h_list[i-1]- h_list[i]                                                                                                                                                                                                                                               
#    print(i, diff)                                                                                                                                                                                                                                                             
    if diff >= 2:                                                                                                                                                                                                                                                               
        flag = False                                                                                                                                                                                                                                                            
        break                                                                                                                                                                                                                                                                   
    elif diff == 1:                                                                                                                                                                                                                                                             
        h_list[i-1] -= 1                                                                                                                                                                                                                                                        
    else:                                                                                                                                                                                                                                                                       
        pass                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                
if flag:                                                                                                                                                                                                                                                                        
    print("Yes")                                                                                                                                                                                                                                                                
else:                                                                                                                                                                                                                                                                           
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h_list = list(map(int, input().split()))
# print(N, h_list)

flag = True
for i in range(0, N-1):
    for j in range(i+1, N):
        if (h_list[i]- h_list[j]) > 1:
            flag = False
            break
    if not flag:
        break

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



Fixed submission:
N = int(input())                                                                                                                                                                                                                                                                
h_list = list(map(int, input().split()))                                                                                                                                                                                                                                        
# print(N, h_list)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                
flag = True                                                                                                                                                                                                                                                                     
for i in reversed(range(1, N)):                                                                                                                                                                                                                                                 
    diff = h_list[i-1]- h_list[i]                                                                                                                                                                                                                                               
#    print(i, diff)                                                                                                                                                                                                                                                             
    if diff >= 2:                                                                                                                                                                                                                                                               
        flag = False                                                                                                                                                                                                                                                            
        break                                                                                                                                                                                                                                                                   
    elif diff == 1:                                                                                                                                                                                                                                                             
        h_list[i-1] -= 1                                                                                                                                                                                                                                                        
    else:                                                                                                                                                                                                                                                                       
        pass                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                
if flag:                                                                                                                                                                                                                                                                        
    print("Yes")                                                                                                                                                                                                                                                                
else:                                                                                                                                                                                                                                                                           
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h_list = list(map(int, input().split()))
# print(N, h_list)

flag = True
for i in range(0, N-1):
    for j in range(i+1, N):
        if (h_list[i]- h_list[j]) > 1:
            flag = False
            break
    if not flag:
        break

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



Fixed submission:
N = int(input())                                                                                                                                                                                                                                                                
h_list = list(map(int, input().split()))                                                                                                                                                                                                                                        
# print(N, h_list)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                
flag = True                                                                                                                                                                                                                                                                     
for i in reversed(range(1, N)):                                                                                                                                                                                                                                                 
    diff = h_list[i-1]- h_list[i]                                                                                                                                                                                                                                               
#    print(i, diff)                                                                                                                                                                                                                                                             
    if diff >= 2:                                                                                                                                                                                                                                                               
        flag = False                                                                                                                                                                                                                                                            
        break                                                                                                                                                                                                                                                                   
    elif diff == 1:                                                                                                                                                                                                                                                             
        h_list[i-1] -= 1                                                                                                                                                                                                                                                        
    else:                                                                                                                                                                                                                                                                       
        pass                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                
if flag:                                                                                                                                                                                                                                                                        
    print("Yes")                                                                                                                                                                                                                                                                
else:                                                                                                                                                                                                                                                                           
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
h_list = list(map(int, input().split()))
# print(N, h_list)

flag = True
for i in range(0, N-1):
    for j in range(i+1, N):
        if (h_list[i]- h_list[j]) > 1:
            flag = False

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


Fixed submission:
N = int(input())                                                                                                                                                                                                                                                                
h_list = list(map(int, input().split()))                                                                                                                                                                                                                                        
# print(N, h_list)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                
flag = True                                                                                                                                                                                                                                                                     
for i in reversed(range(1, N)):                                                                                                                                                                                                                                                 
    diff = h_list[i-1]- h_list[i]                                                                                                                                                                                                                                               
#    print(i, diff)                                                                                                                                                                                                                                                             
    if diff >= 2:                                                                                                                                                                                                                                                               
        flag = False                                                                                                                                                                                                                                                            
        break                                                                                                                                                                                                                                                                   
    elif diff == 1:                                                                                                                                                                                                                                                             
        h_list[i-1] -= 1                                                                                                                                                                                                                                                        
    else:                                                                                                                                                                                                                                                                       
        pass                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                
if flag:                                                                                                                                                                                                                                                                        
    print("Yes")                                                                                                                                                                                                                                                                
else:                                                                                                                                                                                                                                                                           
    print("No")