Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    b = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            array[i] = array[i] + 1
            ans += 1
            a = True
            if b == False:
                b= True
                next = i

print(ans)


Fixed submission:
N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    b = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            ans += array[i-1] - array[i]
            array[i] = array[i - 1]
            a = True
            if b == False:
                b= True
                next = i

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            array[i] = array[i] + 1
            ans += 1
            a = True

print(ans)


Fixed submission:
N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    b = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            ans += array[i-1] - array[i]
            array[i] = array[i - 1]
            a = True
            if b == False:
                b= True
                next = i

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = list(map(int, input().split()))
ans = 0
m = 0

max_index = len(array) - 1

while(True):
    if len(array) == 0:
        break
    m = max(array)
    max_index = array.index(m)

    t = 0
    for x in range(max_index + 1,len(array)):
        t += m - array[x]
    ans += t
    del array[max_index :]

print(ans)


Fixed submission:
N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    b = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            ans += array[i-1] - array[i]
            array[i] = array[i - 1]
            a = True
            if b == False:
                b= True
                next = i

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = list(map(int, input().split()))
ans = 0
m = 0

max_index = len(array) - 1

while(True):
    if len(array) == 0:
        break
    m = max(array)
    max_index = array.index(m)

    t = 0
    for x in range(max_index + 1,len(array)):
        t += m - array[x]
    ans += t
    del array[max_index :]

print(ans)


Fixed submission:
N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    b = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            ans += array[i-1] - array[i]
            array[i] = array[i - 1]
            a = True
            if b == False:
                b= True
                next = i

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = list(map(int, input().split()))
ans = 0

for x in reversed(range(1,len(array))):
    m = max(array)

    if m > array[x]:
        ans += m - array[x]
    array.pop(-1)

print(ans)


Fixed submission:
N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    b = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            ans += array[i-1] - array[i]
            array[i] = array[i - 1]
            a = True
            if b == False:
                b= True
                next = i

print(ans)