Problem p02953 (python)

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

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

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
 
ans = 1
if (N==1):
    continue

elif (N == 2):
    if (H[0] - H[1] >= 2):
        print('No')
        ans = -1
else:
    for i in range(1, N-1, 1):
        #print((H[i] - H[i+1]))
        if ((H[i-1] - H[i]) >= 1) & ((H[i] - H[i+1]) >= 1):
            print('No')
            ans = -1
            break
        elif ((H[i-1] - H[i]) == 0) & ((H[i] - H[i+1]) == 1):
            print('No')
            ans = -1
            break
        elif ((H[i-1] - H[i]) >= 2) or ((H[i] - H[i+1]) >= 2):
            print('No')
            ans = -1
            break
        else:
            continue

 
if (ans == 1): print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
 
ans = 1
if (N == 2) & (H[0] - H[1] >= 2):
    print('No')
    ans = -1
else:
    for i in range(1, N-1, 1):
        #print((H[i] - H[i+1]))
        if ((H[i-1] - H[i]) >= 1) & ((H[i] - H[i+1]) >= 1):
            print('No')
            ans = -1
            break
        elif ((H[i-1] - H[i]) == 0) & ((H[i] - H[i+1]) == 1):
            print('No')
            ans = -1
            break
        elif ((H[i-1] - H[i]) >= 2) or ((H[i] - H[i+1]) >= 2):
            print('No')
            ans = -1
            break
        else:
            continue

 
if (ans == 1): print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
 
ans = 1
for i in range(1, N-1, 1):
    #print((H[i] - H[i+1]))
    if ((H[i-1] - H[i]) >= 1) & ((H[i] - H[i+1]) >= 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) == 0) & ((H[i] - H[i+1]) == 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) >= 2) or ((H[i] - H[i+1]) >= 2):
        print('No')
        ans = -1
        break
    else:
        continue

if (N == 2) & (H[0] - H[1] >= 2):
    print('No')
    ans = -1
 
if (ans == 1): print('Yes')

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

ans = 1
for i in range(1, N-1, 1):
    #print((H[i] - H[i+1]))
    #print(i)
    if ((H[i-1] - H[i]) >= 1) & ((H[i] - H[i+1]) >= 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) == 0) & ((H[i] - H[i+1]) == 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) >= 2):
        print('No')
        ans = -1
        break
    elif ((H[i] - H[i+1]) >= 2):
        print('No')
        ans = -1
        break
    else:
        continue

if (N == 2) & (H[0] - H[1] >= 2):
    print('No')
    ans = -1

if (ans == 1): print('Yes')

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

# ans = 1
# for i in range(1, N-1, 1):
#     #print((H[i] - H[i+1]))
#     if ((H[i-1] - H[i]) == 1) & ((H[i] - H[i+1]) == 0):
#         continue
#     elif ((H[i-1] - H[i]) <= 0) & ((H[i] - H[i+1]) <= 0):
#         continue
#     elif ((H[i-1] - H[i]) == -1) & ((H[i] - H[i+1]) == 1):
#         continue
#     else:
#         print('No')
#         ans = -1
#         break

#if (ans == 1): print('Yes')

ans = 1
for i in range(1, N-1, 1):
    #print((H[i] - H[i+1]))
    #print(i)
    if ((H[i-1] - H[i]) >= 1) & ((H[i] - H[i+1]) >= 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) == 0) & ((H[i] - H[i+1]) == 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) >= 2):
        print('No')
        ans = -1
        break
    elif ((H[i] - H[i+1]) >= 2):
        print('No')
        ans = -1
        break
    else:
        continue

if (H[0] - H[1] >= 2):
    print('No')
    ans = -1

if (ans == 1): print('Yes')

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

ans = 1
for i in range(1, N-1, 1):
    #print((H[i] - H[i+1]))
    print(i)
    if ((H[i-1] - H[i]) >= 1) & ((H[i] - H[i+1]) >= 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) == 0) & ((H[i] - H[i+1]) == 1):
        print('No')
        ans = -1
        break
    elif ((H[i-1] - H[i]) >= 2):
        print('No')
        ans = -1
        break
    elif ((H[i] - H[i+1]) >= 2):
        print('No')
        ans = -1
        break
    else:
        continue

if (H[0] - H[1] >= 2):
    print('No')
    ans = -1

if (ans == 1): print('Yes')