Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    c = int(input())
    if c not in A:
        A.append(c)
    else:
        A.remove(c)

print(len(A))

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
cnt = 1
ans = 0
A.sort()
for i in range(N-1):
    if A[i] == A[i+1]:
        cnt += 1
    else:
        if cnt%2 == 1:
            ans += 1
        cnt = 1
if cnt%2 == 1:
    ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    c = int(input())
    if c not in A:
        A.append(c)
    else:
        A.remove(c)

print(len(A))

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
cnt = 1
ans = 0
A.sort()
for i in range(N-1):
    if A[i] == A[i+1]:
        cnt += 1
    else:
        if cnt%2 == 1:
            ans += 1
        cnt = 1
if cnt%2 == 1:
    ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0]*N
cnt = 0
for i in range(N):
    A[i] = int(input())

a = list(set(A))
for c in a:
    if A.count(c) % 2 == 1:
        cnt += 1
print(cnt)

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
cnt = 1
ans = 0
A.sort()
for i in range(N-1):
    if A[i] == A[i+1]:
        cnt += 1
    else:
        if cnt%2 == 1:
            ans += 1
        cnt = 1
if cnt%2 == 1:
    ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0]*N
cnt = 0
for i in range(N):
    A[i] = int(input())

A.sort()
a = list(set(A))
for c in a:
    if A.count(c) % 2 == 1:
        cnt += 1
print(cnt)

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
cnt = 1
ans = 0
A.sort()
for i in range(N-1):
    if A[i] == A[i+1]:
        cnt += 1
    else:
        if cnt%2 == 1:
            ans += 1
        cnt = 1
if cnt%2 == 1:
    ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0]*N
cnt = 0
for i in range(N):
    A[i] = int(input())

A.sort()
for c in A:
    if A.count(c) % 2 == 1:
        cnt += 1
    
print(cnt)

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
cnt = 1
ans = 0
A.sort()
for i in range(N-1):
    if A[i] == A[i+1]:
        cnt += 1
    else:
        if cnt%2 == 1:
            ans += 1
        cnt = 1
if cnt%2 == 1:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import fractions
N=int(input())
t=int(input())
l=[t]
for i in range(N-1):
    t1=int(input())
    l.append(t1)
    g=fractions.gcd(t,t1)
    t=g
ans=1
for i in range(N):
    ans*=l[i]

ans=ans//g

print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
import fractions
from functools import reduce
N=int(input())
L=[]
for i in range(N):
    L.append(int(input()))
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
    
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm_list(L))

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import fractions
N=int(input())
t=int(input())
for i in range(N-1):
    t1=int(input())
    g=fractions.gcd(t,t1)
    ans=g*t*t1
    t=g
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
import fractions
from functools import reduce
N=int(input())
L=[]
for i in range(N):
    L.append(int(input()))
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
    
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm_list(L))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N,M=map(int,input().split())
L=[]
B=[]
flg=0
cnt=0
for i in range(M):
    a,b=list(map(int,input().split()))
    L.append([a,b])
    if a==1:
        B.append(b)
        cnt+=1
#print(L)
ans=[]
for i in range(M):
    for j in range(cnt):
        if L[i][0]==B[j]:
            ans.append(L[i][1])
#print(ans)
if N in ans:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Fixed submission:
# coding: utf-8
N,M=map(int,input().split())
L=[]
B=[]
A=[]
flg=0
cnt=0
for i in range(M):
    a,b=list(map(int,input().split()))
    L.append([a,b])
    if a==1:
        B.append(b)
        cnt+=1
    elif b==N:
        A.append(a)
        
#print(L)
ans=[]
if len(set(A)&set(B))==0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
a,b,c=map(int,input().split())
if b%2==0:
    if a%2==0:
        if c%2==0:
            print('YES')
        else:
            print('NO')
    else:
        if c%2==0:
            print('NO')
        else:
            print('YES')
else:
    pirnt('YES')

Fixed submission:
# coding: utf-8
a,b,c=map(int,input().split())
Flg=False
for i in range(b+1):
    if a*i%b==c:
        Flg=True
        break
    
if Flg:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
a=int(input())
b=int(input())
la=len(str(a))
lb=len(str(b))

if la>lb:
    print('GREATER')
elif la<lb:
    print('LESS')
else:
    for i in range(la):
        if int(str(a)[i])>int(str(b)[i]):
            print('GREATER')
            Flg=False
            break
        elif int(str(a)[i])<int(str(b)[i]):
            print('LESS')
            Flg=False
            break
    if Flg:
        print('EQUAL')

Fixed submission:
# coding: utf-8
a=int(input())
b=int(input())
if a>b:
    print('GREATER')
elif a<b:
    print('LESS')
else:
    print('EQUAL')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans=1
    for i in range(1,N+1):
        ans *= i
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans=1
    for i in range(1,N+1):
        ans = ans%(10**9+7) * i%(10**9+7)
        
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
ans=1
for i in range(1,N+1):
    ans *= i
print(ans%(10**9+7))

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans=1
    for i in range(1,N+1):
        ans = ans%(10**9+7) * i%(10**9+7)
        
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans=1
for i in range(1,N+1):
    ans *= i
print(ans%(10**9+7))

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans=1
    for i in range(1,N+1):
        ans = ans%(10**9+7) * i%(10**9+7)
        
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
s=input()
n=len(s)
cnt=0
while "ST" in s:
    s=s.replace("ST", "")
    cnt+=1
    #print(s)
print(len(s))

Fixed submission:
# coding: utf-8
from collections import deque
s=input()
n=len(s)
A=deque()
for i in range(n):
    if s[i]=="S":
        A.append(s[i])
    else:
        if len(A)==0:
            A.append(s[i])
        elif A[-1]=="S":
            A.pop()
        else:
            A.append(s[i])
print(len(A))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

d = I()
contest = LI()
mylist = [LI() for i in range(26)]
day = [0] * 26
result = 0
for i in range(d):
    temp = I()
    result += mylist[i][temp-1]
    day = [j+1 for j in day]
    day[temp-1] = 0
    for k in range(26):
        result -= day[k] * contest[k]
    print(result)

Fixed submission:
# coding: utf-8
# Your code here!

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

d = I()
contest = LI()
mylist = [LI() for i in range(d)]
day = [0] * 26
result = 0

for i in range(d):
    temp = I()
    result += mylist[i][temp-1]
    day = [j+1 for j in day]
    day[temp-1] = 0
    for k in range(26):
        result -= day[k] * contest[k]
    print(result)
Buggy python submission (verdict: Runtime Error):
n = input().rstrip()
print(int(n+n**2+n**3))

Fixed submission:
n = int(input().rstrip())
print(int(n+n**2+n**3))
Buggy python submission (verdict: Runtime Error):
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


s = input().rstrip()
t = intput().rstrip()
result = 0
for i in range(len(s)):
    if s[i] != t[i]:
        result += 1
        
print(result)

Fixed submission:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


s = input().rstrip()
t = input().rstrip()
result = 0
for i in range(len(s)):
    if s[i] != t[i]:
        result += 1
        
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def ruiseki(mydata):
    res = [0]*(len(mydata)+1)
    for i in range(len(mydata)):
        res[i+1] = res[i] + mydata[i]
    return res

n, k , m = MI()
a = ruiseki(LI())
b = ruiseki(LI())
a = a
b = b

result = 0
for i, ii in enumerate(a):
    if ii > m:
        break
    for j, jj in enumerate(b):
        if ii + jj > m:
            break
        if result <= i+j:
            result = i+j

print(result)

Fixed submission:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def ruiseki(mydata):
    res = [0]*(len(mydata)+1)
    for i in range(len(mydata)):
        res[i+1] = res[i] + mydata[i]
    return res

n, k , m = MI()
a = ruiseki(LI())
b = ruiseki(LI())
a = a
b = b

result = 0
index = k
for i, ii in enumerate(a):
    if ii > m:
        break
    while b[index] + ii > m:
        index -= 1
    result = max(result, i+index)
print(result)
Buggy python submission (verdict: Runtime Error):
#関数リスト
import sys
import numpy as np
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n, k = MI()
mylist = LI()
mylist.sort()
print(sum(mylist[:k+1]))

Fixed submission:
#関数リスト
import sys
input = sys.stdin.readline

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n, k = MI()
mylist = LI()
mylist.sort()
print(sum(mylist[0:k]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    M = I()
    L = [LI() for i in range(M)]
    L = L[::-1]
    temp = 0
    ans = 0
    
    for a, b in L:
        for j in range(b):
            temp += a
            ans += 1
            if temp >= 10:
                temp = 1 + temp % 10
                ans += 1

    print(ans-1)
    
if __name__ == "__main__":
    main()

Fixed submission:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    M = I()
    L = [LI() for i in range(M)]
    L = L[::-1]
    temp = 0
    ans = 0
    for a, b in L:
        temp += a*b
        ans += b
        while temp >= 10:
            temp2 = temp // 10
            ans += temp2
            temp = (temp % 10) + temp2

    print(ans-1)
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N, Q = MI()
    #木
    tree = [[]]*N
    visit = [True]*N
    for i in range(N-1):
        a,b = MI()
        if len(tree[a-1]) == 0:
            tree[a-1] = [b-1]
            tree[b-1] = [a-1]
        else:
            tree[a-1].append(b-1)
            tree[b-1].append(a-1)
    #カウンター保存用、初期化
    counter = [0]* N
    score = [0]* N
    dq = deque([0])
    visit[0] = False
    for i in range(Q):
        p, x = MI()
        counter[p-1] += x
    score[0] = counter[0]
    while dq:
        temp = dq.pop()
        for num in tree[temp]:
            if visit[num]:
                score[num] = score[temp]+counter[num]
                dq.append(num)
                visit[num] = False
    score = [str(i) for i in score]
    print(" ".join(score))
    return None

if __name__ == "__main__":
    main()

Fixed submission:
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
 
def main():
    n,q = map(int,ipt().split())
    way = [[] for i in range(n+1)]
    for i in range(n-1):
        a,b = map(int,ipt().split())
        way[a].append(b)
        way[b].append(a)
    pl = [0]*(n+1)
    for i in range(q):
        p,x = map(int,ipt().split())
        pl[p] += x
    ans = [-1]*(n+1)
    ans[0] = 0
    ans[1] = pl[1]
    q = [(1,0)]
 
    while q:
        qi,qp = q.pop()
        qa = ans[qi]
        for j in way[qi]:
            if j == qp:
                continue
            ans[j] = qa+pl[j]
            q.append((j,qi))
 
    print(" ".join(map(str,ans[1::])))
 
    return None
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def end_of_loop():raise StopIteration
    
    
def main():
    N, M = MI()
    Switch = [LI()[1:] for i in range(N)]
    P = LI()
    result = 0
    for i in range(2**N):
        temp = [0]*M
        for j in range(N):
            if i>>j & 1 != 0:
                for k in Switch[j]:
                    temp[k-1] += 1
        result += 1
        for num1, num2 in zip(temp, P):
            if num1 % 2 != num2:
                result -= 1
                break
    print(result)
            
        
if __name__ == "__main__":
    main()

Fixed submission:
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def end_of_loop():raise StopIteration
    
    
def main():
    N, M = MI()
    Switch = [LI() for i in range(M)]
    P = LI()
    result = 0
    for i in range(2**N):
        result += 1
        for index, swich in enumerate(Switch):
            if swich[0] == 0:
                continue
            temp = 0
            for j in range(swich[0]):
                if i >> (swich[j+1]-1) & 1 == 1:
                    temp += 1
            if temp % 2 != P[index]:
                result-=1
                break
            
    print(result)
                    
                    
            
            
        
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = [list(MI()) for i in range(n-1)]

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s
        if (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)
    
    
for i in range(n-1):
    main(i)
print(0)

Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = [list(MI()) for i in range(n-1)]

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s
        if (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)
    
    
for i in range(n-1):
    main(i)
print(0)
Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np
mylist = [0, 1]
n = int(input().rstrip())

mise = [list(map(int, input().rstrip().split())) for i in range(n)]
mine = [list(map(int, input().rstrip().split())) for i in range(n)]

maxnum = - float('inf')
for i in itertools.product(mylist, repeat = 10):
    if sum(i) == 0:
        continue
    sell = 0
    for j, k in zip(mise, mine):
        temp = 0
        for l in range(10):
            if j[l] == i[l] and j[l] == 1:
                temp += 1
        sell += k[temp]
    maxnum = max(maxnum, sell)
print(maxnum)

Fixed submission:
import itertools
mylist = [0, 1]
n = int(input().rstrip())

mise = [list(map(int, input().rstrip().split())) for i in range(n)]
mine = [list(map(int, input().rstrip().split())) for i in range(n)]

maxnum = - float('inf')
for i in itertools.product(mylist, repeat = 10):
    if sum(i) == 0:
        continue
    sell = 0
    for j, k in zip(mise, mine):
        temp = 0
        for l in range(10):
            if j[l] == i[l] and j[l] == 1:
                temp += 1
        sell += k[temp]
    maxnum = max(maxnum, sell)
print(maxnum)
Buggy python submission (verdict: Runtime Error):
N = int(input())
mod = 10**9+7
if N == 1:
  print(0)
elif N == 2:
  print(2)
else:
  ans = 10*8*6*(10**(3(N-3)))
  print((ans*2)%mod)


Fixed submission:
n = int(input())
mod = 10**9+7
a = 10**n-9**n-9**n+8**n
print(a%mod)

Buggy python submission (verdict: Runtime Error):
N = int(input())
mod = 10**9+7
if N == 1:
  print(0)
elif N == 2:
  print(2)
else:
  ans = 10*8*6*10**(3(N-3))*2
  print(ans%mod)

Fixed submission:
n = int(input())
mod = 10**9+7
a = 10**n-9**n-9**n+8**n
print(a%mod)

Buggy python submission (verdict: Runtime Error):
N = int(input())
mod = 10** + 7
if N == 1:
  print(0)
else:
  ans = N*10**(n-2)
  print(ans%mod)

Fixed submission:
n = int(input())
mod = 10**9+7
a = 10**n-9**n-9**n+8**n
print(a%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input().split()
mod = 10**9+7
ans=0
for i in range(2**N):
  cl = [False]*N
  for j in range(N):
    if ((i>>j)&1):
        cl[N-1-j] = True
  total=''
  if cl.count(True) == 2:
        for k in range(len(cl)):
            if cl[k]:
                total += A[k] + '*'
        total+='1'
  if total =='':
    pass
  else:
        ans += eval(total)

print(ans%mod)


Fixed submission:
mod=10**9 + 7
n=int(input())
a=list(map(int,input().split()))
ans=0
total=sum(a)
for i in a:
  total -= i
  ans += total*i
print(ans%mod)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [list(map(str,input().split()) for i in range(N))]
mod = 10**9+7
ans=0
for i in range(2**N):
  cl = [False]*N
  for j in range(N):
    if ((i>>j)&1):
      cl[N-1-j] = True
  total=''
  if cl.count(True) == 2:
    for k in range(len(cl)):
      if cl[k]:
        total+= A[k] + '*'
      total+= '1'
  ans += eval(total)

print(ans%mod)


Fixed submission:
mod=10**9 + 7
n=int(input())
a=list(map(int,input().split()))
ans=0
total=sum(a)
for i in a:
  total -= i
  ans += total*i
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
count=0
num=0
for i in range(N):
  while count != N:
    count = i
    try:
      C = i+1
      num += A[i]*A[C]
      C+=1
      count+=1
    except:
      pass
print(num)

Fixed submission:
mod=10**9 + 7
n=int(input())
a=list(map(int,input().split()))
ans=0
total=sum(a)
for i in a:
  total -= i
  ans += total*i
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
N,X,T = map(int,input().split())
count=0
if N <=X:
  print(T)
  break
elif N > X:
  while N > X:
    N = N - X
    count+=1
  print(T*count)

Fixed submission:
N,X,T = map(int,input().split())
count = 1
while N > X:
  N = N - X
  count += 1
print(T*count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(input().split()))
count=0
for i in range(N):
  try:
    a=A[i]
    b=A[i+1]
    while a>b:
      b+=1
      count+=1
  except:
    pass
print(count)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
count=0
for i in range(N):
  try:
    a = A[i]
    b = A[i+1]
    if a <= b:
      pass
    else:
      c = abs(a-b)
      A[i+1] = b+c
      count+=c
  except:
    pass
print(count)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
count=0
for i in len(s):
  if s[i] != t[i]:
    count+=1
print(count)


Fixed submission:
s = input()
t = input()
count=0
for (i,j) in zip(s,t):
  if i != j:
    count+=1
print(count)

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
count=0
for i in len(s):
  if s[i] == t[i]:
    count+=1
print(count)

Fixed submission:
s = input()
t = input()
count=0
for (i,j) in zip(s,t):
  if i != j:
    count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = sorted([int(input()) for i in range(n)])
count=0
for i in range(k):
  count = count+p[i]
print(count)


Fixed submission:
n,k = map(int,input().split())
p = sorted(list(map(int,input().split())))
total = 0
for i in range(k):
  total += p[i]
print(total)