Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
submax = 0

for i in range(n-1):
  for j in range(i+1,n):
    if h[i] - h[j] >= 2:
      submax = 1
      break
  if submax == 1:
    break

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

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
submax = 0

for i in range(n-1):
  for j in range(i+1,n):
    if h[i] - h[j] >= 2:
      submax = 1

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

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))
 
for i in range(n-1):
  if h[i] == h[i+1]+1:
    j = i
    p = 1
    break
  elif h[i] >= h[i+1] + 2:
    p = 2
    break
  else:
    j = 0
    p = 3
 
if j == 0:
  print("Yes")
else:  
  if min(h[j:]) + 2 <= h[j] or p == 2:
    print("No")
  else:
    print("Yes")

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

for i in range(n-1):
  if h[i] == h[i+1]+1:
    j = i
    p = 1
    break
  elif h[i] >= h[i+1] + 2:
    p = 2
    break
  else:
    j = 0
    p = 3

if j == 0:
  print("Yes")
else:  
  if min(h[j:]) + 2 <= h[j] or p == 2:
  print("No")
  else:
  print("Yes")

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))


for i in range(n-1):
  if h[i] == h[i+1]+1:
    j = i
    p = 1
    break
  elif h[i] >= h[i+1] + 2:
    p = 2
    break
  elif h[i] <= h[i+1]:
    j = 0
    p = 3
    
if min(h[j:]) + 2 <= h[j] or p == 2:
  print("No")
else:
  print("Yes")

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

for i in range(n-1):
  if h[i] == h[i+1]+1:
    j = i
    p = 1
    break
  elif h[i] >= h[i+1] + 2:
    p = 2
    break
  else:
    j = 0
    p = 3
    
if min(h[(j+1):]) + 2 <= h[j] or p == 2:
  print("No")
else:
  print("Yes")

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

for i in range(n-1):
  if h[i] == h[i+1]+1:
    j = i
    p = 1
    break
  elif h[i] >= h[i+1] + 2:
    p = 2
    break
  else:
    j = 0
    p = 3
    
if min(h[j:]) + 2 <= h[j] or p == 2:
  print("No")
else:
  print("Yes")

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
d = [1]+[0]*(n-1)

for i in range(n-1):
  if h[i] >= 2+ h[i+1]:
    print('No')
    exit()
  if d[i] == 1 and h[i] <= h[i+1]:
    d[i+1] = 1
  elif d[i] == 0:
    if h[i] +1 <=h[i+1]:
      d[i+1] = 1
    elif h[i] -1 == h[i+1]:
      print('No')
      exit()
      
print('Yes')