Buggy python submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split(" ")]

for i in range(1, n):
  if h(-i)-h(-i-1) >= 0:
    continue  
  if h(-i)-h(-i-1) == -1:
    h(-i-1) = h(i-1) - 1
    continue
  if h(i)-h(-i-1) < -1:
    ans = "No"
    break
else:
  ans = "Yes"

print(ans)

Fixed submission:
n = int(input())
h = [int(x) for x in input().split(" ")]
 
for i in range(1, n):
  if h[-i]-h[-i-1] >= 0:
    continue  
  elif h[-i]-h[-i-1] == -1:
    h[-i-1] = h[-i-1] - 1
    continue
  elif h[-i]-h[-i-1] < -1:
    ans = "No"
    break
else:
  ans = "Yes"
  
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split(' ')))

is_trimmed = [False] * N
max_v = 0
max_ids = []
succeed = True
for i in range(N):
    if max_v > H[i]:
        if max_v - H[i] > 1:
            print('No')
            succeed = False
            break
        if max_v - H[i] == 1:
            for j in max_ids:
                if is_trimmed[j]:
                    print('No')
                    succeed = False
                    break
                is_trimmed[j] = True
    elif max_v == H[i]:
        max_ids.append(i)
    elif max_v < H[i]:
        max_v = max(max_v, H[i])
        max_ids = [i]
    print(max_v, max_ids, is_trimmed)

if succeed:
    print('Yes')


Fixed submission:
N = int(input())
H = list(map(int, input().split(' ')))

is_trimmed = [False] * N
max_v = 0
max_ids = []
succeed = True
for i in range(N):
    diff = max_v - H[i]
    if diff > 1:
        print('No')
        succeed = False
        exit(0)
    elif diff == 1:
        for j in max_ids:
            if is_trimmed[j]:
                print('No')
                succeed = False
                exit(0)
            is_trimmed[j] = True
        max_ids.append(i)
        max_v -= 1
    elif diff == 0:
        max_ids.append(i)
    elif diff < 0:
        max_v = max(max_v, H[i])
        max_ids = [i]
    # print(max_v, max_ids, is_trimmed)

if succeed:
    print('Yes')

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split(' ')))

is_trimmed = [False] * N
max_v = 0
max_ids = []
for i in range(N):
    if max_v > H[i]:
        if max_v - H[i] > 1:
            print('No')
            exit(0)
        if max_v - H[i] == 1:
            for j in max_ids:
                if is_trimmed[j]:
                    print('No')
                    exit(0)
                is_trimmed[j] = True
    elif max_v == H[i]:
        max_ids.append(i)
    elif max_v < H[i]:
        max_v = max(max_v, H[i])
        max_ids = [i]
    print(max_v, max_ids, is_trimmed)
print('Yes')


Fixed submission:
N = int(input())
H = list(map(int, input().split(' ')))

is_trimmed = [False] * N
max_v = 0
max_ids = []
succeed = True
for i in range(N):
    diff = max_v - H[i]
    if diff > 1:
        print('No')
        succeed = False
        exit(0)
    elif diff == 1:
        for j in max_ids:
            if is_trimmed[j]:
                print('No')
                succeed = False
                exit(0)
            is_trimmed[j] = True
        max_ids.append(i)
        max_v -= 1
    elif diff == 0:
        max_ids.append(i)
    elif diff < 0:
        max_v = max(max_v, H[i])
        max_ids = [i]
    # print(max_v, max_ids, is_trimmed)

if succeed:
    print('Yes')