Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if h[i] >= 0:
            h[i] -= 1
        
        if i > 0 and h[i] < 0 and h[i-1] >= 0:
            count += 1

        if i == n-1 and h[i] >= 0:
            count += 1
    if max(h) == 0:
        done = True
print(count)


Fixed submission:
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if h[i] >= 0:
            h[i] -= 1
        
        if i > 0 and h[i] < 0 and h[i-1] >= 0:
            count += 1

        if i == n-1 and h[i] >= 0:
            count += 1
    if max(h) <= 0:
        done = True
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if i > 0 and h[i] <= 0 and h[i-1] >= 0:
            count += 1

        elif i == n-1 and h[i] > 0:
            count += 1

        h[i] -= 1
    if max(h) == 0:
        done = True
print(count)


Fixed submission:
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if h[i] >= 0:
            h[i] -= 1
        
        if i > 0 and h[i] < 0 and h[i-1] >= 0:
            count += 1

        if i == n-1 and h[i] >= 0:
            count += 1
    if max(h) <= 0:
        done = True
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
h_max = -1
while done == False:
    start = 0
    for i in range(n):
        if i > 0 and h[i-1] >= 0 and h[i] <= 0:
            count += 1
        elif i == n-1 and h[i] > 0:
            count += 1
        h[i] -= 1

        if h_max < h[i]:
            h_max = h[i]
    if h_max == 0:
        done = True
print(count)


Fixed submission:
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if h[i] >= 0:
            h[i] -= 1
        
        if i > 0 and h[i] < 0 and h[i-1] >= 0:
            count += 1

        if i == n-1 and h[i] >= 0:
            count += 1
    if max(h) <= 0:
        done = True
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    start = 0
    for i in range(n):
        if i > 0 and h[i-1] >= 0 and h[i] <= 0:
            count += 1
        elif i == n-1 and h[i] > 0:
            count += 1
        h[i] -= 1
    if max(h) == 0:
        done = True
print(count)


Fixed submission:
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if h[i] >= 0:
            h[i] -= 1
        
        if i > 0 and h[i] < 0 and h[i-1] >= 0:
            count += 1

        if i == n-1 and h[i] >= 0:
            count += 1
    if max(h) <= 0:
        done = True
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    start = 0
    for i in range(n):
        if i > 0 and h[i-1] >= 0 and h[i] <= 0:
            count += 1
        elif i == n-1 and h[i] > 0:
            count += 1
        h[i] -= 1
    if max(h) == 0:
        done = True
print(count)


Fixed submission:
n = int(input())
h = list(map(int,input().split()))
count = 0
done = False
while done == False:
    for i in range(n):
        if h[i] >= 0:
            h[i] -= 1
        
        if i > 0 and h[i] < 0 and h[i-1] >= 0:
            count += 1

        if i == n-1 and h[i] >= 0:
            count += 1
    if max(h) <= 0:
        done = True
print(count)