qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(0, N-1):
  b = L[i] - L[i+1]
  c = int(b)
  if c >> 0:
    ans = ans + c
    L[i + 1] = L[i]
print(ans)  


Fixed code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(0, N-1):
  a = L[i]
  b = L[i + 1]
  if a - b > 0:
    ans +=(a - b)
    L[i + 1] = L[i]
print(ans)
Buggy code:
a=input()
b=input()
c=b.split()
d=map(int,c)
main=list(d)
sum=0
print(main)
for i in range(len(main)-2):
    stool=main[i]-main[i+1]
    if stool>0:
        main[i+1]+=stool
        sum+=stool

stool=main[len(main)-2]-main[len(main)-1]
if stool>0:
    sum+=stool
    main[len(main)-1]+=stool

print("sum = ",sum, "main = ",main)    

Fixed code:
a=input()
b=input()
c=b.split()
d=map(int,c)
main=list(d)
sum=0
for i in range(len(main)-2):
    stool=main[i]-main[i+1]
    if stool>0:
        main[i+1]+=stool
        sum+=stool

stool=main[len(main)-2]-main[len(main)-1]
if stool>0:
    sum+=stool
    main[len(main)-1]+=stool

print(sum)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

if A[0]-A[1]>0:
  total = A[0]-A[1]
else:
  total=0 
dif = total
for i in range(1,N):
  if (A[i-1]+dif)-A[i]>0:
    total += (A[i-1]+dif)-A[i]
    dif = (A[i-1]+dif)-A[i]
  else:
    dif = 0
print(total)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
 
total = 0
dif = 0
for i in range(1,N):
  if (A[i-1]+dif)-A[i]>0:
    total += (A[i-1]+dif)-A[i]
    dif = (A[i-1]+dif)-A[i]
  else:
    dif = 0
print(total)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
max = 0
sum = 0
for i in range(n):
  if a[i] > max:
    max = a[i]
  else:
    sum += a[i] - max
print(sum)
    

Fixed code:
n = int(input())
a = list(map(int,input().split()))
max = 0
sum = 0
for i in range(n):
  if a[i] > max:
    max = a[i]
  else:
    sum += (max - a[i]) 
print(sum)
Buggy code:
N = int(input())
A = map(int, input().split())
dif = 0
sum = 0

for i in range(N - 1):
  if A[i] > A[i +1]:
    dif = A[i] - A[i + 1]
    sum += dif
    A[i +1] = A[i + 1] + dif
    
  else:
    
print(sum)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
dif = 0
sum = 0

for i in range(N - 1):
  if A[i] > A[i + 1]:
    dif = A[i] - A[i + 1]
    sum += dif
    A[i +1] = A[i + 1] + dif
    
print(sum)
Buggy code:
n=int(input())
a = list(map(int,input().split()))
step=[0]*n
for i in range(n-1):
  step[i+1]+=a[i]+step[i]-a[i+1]
  if step[i+1]<0:
    step[i+1]=0
    
total=sum(step)
print(step)
print(total)

Fixed code:
n=int(input())
a = list(map(int,input().split()))
step=[0]*n
for i in range(n-1):
  step[i+1]+=a[i]+step[i]-a[i+1]
  if step[i+1]<0:
    step[i+1]=0
    
total=sum(step)
print(total)
Buggy code:
n,*a=map(int,open(0).read().split())
ma=a[0]
ans=0
for q in a:
  if q>ma:
    ans+=(q-ma)
  ma=max(ma,q)
print(ans)


Fixed code:
n,*a=map(int,open(0).read().split())
ma=a[0]
ans=0
for q in a:
  if ma>q:
    ans+=(ma-q)
  ma=max(ma,q)
print(ans)
Buggy code:
N = input()
As = list(map(int, input().split()))

s = 0
now = As[0]
for a in As:
    if a<now:
        s += now - a
    else:
        now = a
        
    print(s)

Fixed code:
N = input()
As = list(map(int, input().split()))

s = 0
now = As[0]
for a in As:
    if a<now:
        s += now - a
    else:
        now = a
        
print(s)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
pre = A[0]
ans = 0
for a in A[1:]:
    if pre > a:
        ans += pre - a
    pre = a
print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
pre = A[0]
ans = 0
if N == 1:
    print(0)
else:
    for a in A[1:]:
        if pre > a:
            ans += pre - a
        else:
            pre = a
    print(ans)
Buggy code:
n=int(input())
l=list(map(int,input().split()))
mx=l[0]
an=0
for i in range(1,n):
  if l[i]<mx:
    an+=mx-l[i]
  else:
    l[i]=mx
print(an)

Fixed code:
n=int(input())
l=list(map(int,input().split()))
mx=l[0]
an=0
for i in range(1,n):
  if l[i]<mx:
    an+=mx-l[i]
  else:
    mx=l[i]
print(an)
Buggy code:
N = int(input())
A = [map(int, input().split())]
d = 0
for n in range(0, N-1):
    if A[n+1] < A[n]:
        d += A[n]-A[n+1]
        A[n+1] = A[n]
print(d)

   

Fixed code:
N = int(input())
A = list(map(int, input().split()))
d = 0
for n in range(0, N-1):
    if A[n+1] < A[n]:
        d += A[n]-A[n+1]
        A[n+1] = A[n]
print(d)
Buggy code:
N = int(input())
A = map(int, input().split())

#current height
now = 0
total = 0

for a in A:
    print("a", a)

    if a >= now:
        now = a
        pass
    else:
        total += now - a
    #print("now", now)
    #print("total", total)

print(total)


Fixed code:
N = int(input())
A = map(int, input().split())

#current height
now = 0
total = 0

for a in A:
    #print("a", a)

    if a >= now:
        now = a
        pass
    else:
        total += now - a
    #print("now", now)
    #print("total", total)

print(total)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
h = A[0]
for a in A:
  if h > a:
    ans += h - a
  h = a
print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
h = A[0]
for a in A:
  if h > a:
    ans += h - a
  else:
    h = a
print(ans)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
b = []
c = 0
for i in range(1,n):
    s = a[i-1]-a[i]
    if s >= 0:
        s = s+c 
        b.append(s)
        c = max(c,s)
    else:
        c = 0
        b.append(c)
print(b)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
b = []
c = 0
for i in range(1,n):
    c = max(c,a[i-1])
    s = c-a[i]
    if s >= 0:
        b.append(s) 
print(sum(b))
Buggy code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(1,n-1) :
    if a[i] - a[i-1] >= 0 :
        continue
    else :
        ans += abs(a[i] - a[i-1])
        a[i] += abs(a[i] - a[i-1])
        print(a)
print(ans)

Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
ans=0
for i in range(1,n):
  d = a[i-1] - a[i]
  if d>0:
    ans+= d
    a[i]=a[i]+d
  else:
    continue
    
print(abs(ans))
Buggy code:
N=int(input())
A = list(map(int, input().split()))
#print(A)
count=0
count2=0
for i in range(len(A)-1):
    if A[i]>A[i+1]:
        count=A[i]-A[i+1]
        #print(count)
        A[i+1]=A[i]
    count2+=count
print(count2)

Fixed code:
N=int(input())
A = list(map(int, input().split()))
#print(A)
count=0
count2=0

for i in range(len(A)-1):
    #print(A[i])
    if A[i]>A[i+1]:
        count=A[i]-A[i+1]
        #print(count)
        A[i+1]=A[i]
        count2+=count

print(count2)
Buggy code:
N = int(input())
A = list(map(int,input().split()))

keep = 0
cnt =0
x=0


for a in A:
    if keep > a:
        cnt += keep -a
        x=0
        x += keep -a
    keep = a + x
    
    
print(cnt)

Fixed code:
N = int(input())
A = list(map(int,input().split()))

keep = 0
cnt =0
x=0


for a in A:
    if keep > a:
        cnt += keep -a
        x = keep -a
        keep = a + x
    else:
      keep = a
    
    
print(cnt)
Buggy code:
n = input()
A = list(map(int,input().split()))
ans = 0 
temp = 0
for i in range(n-1):
    if A[i]<temp:
        ans += temp-A[i]
    else:
        temp = max(temp,A[i])

print(ans) 

Fixed code:

n = int(input())
A = list(map(int,input().split()))
ans = 0 
temp = 0
for i in range(n):
    if A[i]<temp:
        ans += temp-A[i]
    else:
        temp = max(temp,A[i])

print(ans)
Buggy code:
n = int(input())
A = list(map(int,input().split()))
ans = 0

for i in range(n):
  if A[i]>A[i+1]:
    A[i+1]=A[i]
    ans += A[i]-A[i+1]

print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(1,N):
    if A[i-1] > A[i]:
        ans += A[i-1] - A[i]
        A[i] += A[i-1] - A[i]
print(ans)
Buggy code:
# t=int(input())
# for _ in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
maxa=arr[0]
count=0
for i in range(n):
    if arr[i] > maxa:
        maxa=arr[i]
    else:
        count+=1
print(count)


Fixed code:
# t=int(input())
# for _ in range(t):
n=int(input())
arr=[int(x) for x in input().split()]
maxa=arr[0]
count=0
for i in range(n):
    if arr[i] >= maxa:
        maxa=arr[i]
    else:
        count+=(maxa-arr[i])
print(count)
Buggy code:
n=int(input())
a=list(map(int, input().split()))
ans=0
for i in range(1, n):
    s=a[i] - a[i-1]
    if s<0:
        ans-=s
        a[i]-=s

Fixed code:
n=int(input())
a=list(map(int, input().split()))
ans=0
for i in range(1, n):
    s=a[i] - a[i-1]
    if s<0:
        ans-=s
        a[i]-=s
print(ans)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(1,n):
    if x[i]<x[i-1]:
        t=x[i-1]-x[i]
        sum+=t

print(sum)

Fixed code:
N=int(input())
x=list(map(int,input().split()))
sum=0
for i in range(1,N):
    if x[i]<x[i-1]:
        t=x[i-1]-x[i]
        sum+=t
        x[i]=x[i-1]
print(sum)
Buggy code:
N = int(input())
members = list(map(int, input().strip().split()))
stands = []

for i, member in enumerate(members):
  if i>0:
    if members[i] > members[i-1]:
      stands.append(0)
    else:
      stands.append(members[i-1] - members[i])
      
print(sum(stands))

Fixed code:
N = int(input())
members = list(map(int, input().strip().split()))
stands = []
stands.append(0)

for i, member in enumerate(members):
  if i>0:
    if members[i] > members[i-1] + stands[i-1]:
      stands.append(0)
    else:
      stands.append(members[i-1] + stands[i-1] - members[i])
      
print(sum(stands))
Buggy code:
n = int(input())
a = list(map(int,input().split()))
ans = 0

for i in range(1,n):
  if(a[i-1] > a[i]):
    while(a[i-1] == a[i]):
      a[i] += 1
      ans += 1
    
print(ans)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
diff = 0

for i in range(1,n):
  if(a[i-1] > a[i]):
    diff = a[i-1] - a[i]
    a[i] += diff
    ans += diff
    
print(ans)
Buggy code:
from sys import stdin
input = stdin.readline

n = input().rstrip()
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)-1):
    if a[i] > a[i+1]:
        diff = a[i] - a[i+1]
        ans += diff

print(ans)

Fixed code:
from sys import stdin
input = stdin.readline

n = input().rstrip()
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)-1):
    if a[i] > a[i+1]:
        diff = a[i] - a[i+1]
        a[i+1] += diff
        ans += diff

print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
sum=0
for i in range(N-1):
  if A[i] < A[i+1]:
    continue
  else:
    sa = A[i]-A[i+1]+1
    A[i+1]=A[i]+1
    sum += sa
print(sa)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
sum=0
sa=0
for i in range(N-1):
  if A[i] <= A[i+1]:
    continue
  else:
    sa = A[i]-A[i+1]
    A[i+1]=A[i]
    sum += sa
print(sum)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
ans = 0
for i in range(n-2):
  s = a[i+1] -a[i] 
  if s < 0:
      ans = ans - s
      a[i+1]=a[i]
print(ans)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
ans = 0
for i in range(n-1):
  s = a[i+1] -a[i] 
  if s < 0:
      ans = ans - s
      a[i+1]=a[i]
print(ans)
Buggy code:
N = int(input())
A = input().split()
# print(A)
A_list = list(map(float, A))
sa = 0
for i in range(N-1):
    # print(i)
    if A_list[i] > A_list[i+1]:
        sa += A_list[i] - A_list[i+1]
        A_list[i+1] = A_list[i]
print(sa)


Fixed code:
N = int(input())
A = input().split()
# print(A)
A_list = list(map(float, A))
sa = 0
for i in range(N-1):
    # print(i)
    if A_list[i] > A_list[i+1]:
        sa += A_list[i] - A_list[i+1]
        A_list[i+1] = A_list[i]
print(int(sa))
Buggy code:
N = int(input())
A = list(map(int,input().split()))
x = A[0]
ans = 0
for i in range(1,N):
    if A[i] < x:
        ans += x - A[i]
    elif A[i] > x:
        x = A[i]
    print(x, ans)
print(ans)

Fixed code:
N = int(input())
A = list(map(int,input().split()))

top = A[0]
ans = 0

for i in range(1,N):
  if A[i] < top:
    ans += (top - A[i])
  elif A[i] > top:
    top = A[i]
    
print(ans)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
sum(A)
count=0
for num in range(N)
    if A[num]>A[num+1]:
        count=count+A[num]-A[num+1]
    else:
        count=count
print (count)    

Fixed code:
N=int(input())
A=list(map(int,input().split()))
count=0
for num in range(N-1):
    if A[num]>A[num+1]:
        count=count+A[num]-A[num+1]
        A[num+1]=A[num]
    else:
        continue        
print(count)
Buggy code:
n = int(input())
a_L = list(map(int,input().split()))


if len(a_L) == 1:
    print(0)
    exit()

ans = 0
for i in range(0,len(a_L)-1):
    if a_L[i] > a_L[i+1]:
        ans += abs(a_L[i+1] - a_L[i])
        a_L[i+1] = a_L[i]

print(ans)

if a_L[-2] > a_L[-1]:
    ans += abs(a_L[-1]-a_L[-2])
print(ans)

Fixed code:
n = int(input())
a_L = list(map(int,input().split()))


if len(a_L) == 1:
    print(0)
    exit()

ans = 0
for i in range(0,len(a_L)-1):
    if a_L[i] > a_L[i+1]:
        ans += abs(a_L[i+1] - a_L[i])
        a_L[i+1] = a_L[i]


if a_L[-2] > a_L[-1]:
    ans += abs(a_L[-1]-a_L[-2])
print(ans)
Buggy code:
#ABC177 C
N = int(input())
A = list(map(int,input().split()))
max = A[0]
F = [0]

for i in range(1,N):
  if max > A[i]:
    F.append(max - A[i])
  else:
    max = A[i]
    F.append(0)

print(F)
print(sum(F))


Fixed code:
#ABC177 C
N = int(input())
A = list(map(int,input().split()))
max = A[0]
F = [0]

for i in range(1,N):
  if max > A[i]:
    F.append(max - A[i])
  else:
    max = A[i]
    F.append(0)

print(sum(F))
Buggy code:
n=int(input())

l=list(map(int,input().split()))

t=0
x=0

for i in range(n):
  if t>l[i]:
    t+=t-l[i]
    x+=t-l[i]
    
print(x)

Fixed code:
n=int(input())
 
l=list(map(int,input().split()))
 
t=l[0]
x=0
 
for i in range(n):
    if t>l[i]:
        x+=t-l[i]
    else:
        t=l[i]
    
print(x)
Buggy code:
# AtCoder Beginner Contest 176
# C - Step

N=int(input())
Als=list(map(int,input().split()))

ans=0

for i in range (1,N):
    if Als[i]>=Als[i-1]:
        pass
    else :
        ans+= max(Als[0:i])
print(ans)

Fixed code:
# AtCoder Beginner Contest 176
# C - Step

N=int(input())
Als=list(map(int,input().split()))

ans=0

for i in range (1,N):
    if Als[i]>=Als[i-1]:
        pass
    else :
        step=abs(Als[i]-Als[i-1])
        ans+=step
        Als[i]+=step
print(ans)
Buggy code:
As = list(map(int, input().split()))
 
sum_humidai = 0
 
for person_idx, person_height in enumerate(As):
  
  if person_idx == 0:
    continue
    
  max_front_person = max(As[:person_idx])
  
  if max_front_person > person_height:
    humidai = max_front_person - person_height
    sum_humidai += humidai
 
print(sum_humidai)

Fixed code:
N = int(input())
As = list(map(int, input().split()))
 
sum_humidai = 0
max_front_person = 0
  
for person_idx, person_height in enumerate(As):
  
  if person_idx == 0:
    continue
    
  max_front_person = max(max_front_person, As[person_idx - 1])
  if max_front_person > person_height:
    humidai = max_front_person - person_height
    sum_humidai += humidai
 
print(sum_humidai)
Buggy code:
vfrom sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
n=int(input())
A=INPUT()
B=[A[0]]

currmax=A[0]
ans=0
for i in range(1,n):
    if A[i]<=currmax:
        ans+=currmax-A[i]
    currmax=max(currmax,A[i])
print(ans)


Fixed code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
n=int(input())
A=INPUT()
B=[A[0]]

currmax=A[0]
ans=0
for i in range(1,n):
    if A[i]<=currmax:
        ans+=currmax-A[i]
    currmax=max(currmax,A[i])
print(ans)
Buggy code:
 = int(input())
list1 = list(map(int, input().split()))
h,c = 0,0
for i in list1:
    if i < h:
        c += h - i
    else:
        h = i
print(c)

Fixed code:
n = int(input())
list1 = list(map(int, input().split()))
h,c = 0,0
for i in list1:
    if i < h:
        c += h - i
    else:
        h = i
print(c)
Buggy code:
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(n):
  if l[i]>l[i+1]:
     m.append(l[i]-l[i+1])
    l[i+1] = l[i]

print(sum(m))
  


Fixed code:
n = int(input())
l = list(map(int,input().split()))
m = []
for i in range(n-1):
  if l[i]>l[i+1]:
     m.append(l[i]-l[i+1])
     l[i+1] = l[i]

print(sum(m))
Buggy code:
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(1,n):
    print(a[i-1], a[i])
    if a[i-1] <= a[i]:
        continue
    else:
        ans += a[i-1] - a[i]
        a[i] = a[i-1]

print(ans)

Fixed code:
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(1,n):
    if a[i-1] <= a[i]:
        continue
    else:
        ans += a[i-1] - a[i]
        a[i] = a[i-1]

print(ans)
Buggy code:
n = int(input())
a = [int(i) for i in input.split()]
ans = 0
for i in range(1, n):
  if a[i] < a[i - 1]:
    ans += a[i - 1] - a[i]
print(ans)

Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(1, n):
  if a[i] < a[i - 1]:
    ans += a[i - 1] - a[i]
    a[i] += (a[i - 1] - a[i])
print(ans)
Buggy code:
total = int(input())
tall = list(map(int, input().split()))
dif = 0
for i in range(total - 1):
    if tall[i] > tall[i+1]:
        var = tall[i] - tall[i+1]
        tall[i+1] += var
        dif += var
    else:
        pass
print(dif)
print(tall)

Fixed code:
total = int(input())
tall = list(map(int, input().split()))
dif = 0
for i in range(total - 1):
    if tall[i] > tall[i+1]:
        var = tall[i] - tall[i+1]
        tall[i+1] += var
        dif += var
    else:
        pass
print(dif)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
X=0
for i in range(N-1):
  if A[i+1]>A[i]:
    X+=A[i+1]-A[i]
    A[i+1]=A[i]
print(X)

Fixed code:
N=int(input())
A=list(map(int,input().split()))
X=0
for i in range(N-1):
  if A[i+1]<A[i]:
    X+=A[i]-A[i+1]
    A[i+1]=A[i]
print(X)
Buggy code:
n = int(input())
list = list(map(int,input().split()))

ans = 0
maxV = max(list)
maxI = list.index(maxV)

sumV = sum(list[maxI+1, len(list)])
maxM = maxV * (len(list)-1-maxI)
ans += maxM - sumV

if maxI != 0:
    for i in range(0,maxI):
        if i != maxI:
            x = list[i] - list[i+1]
            if x > 0:
                ans += x


print(ans)


Fixed code:
n = int(input())
list = list(map(int,input().split()))

ans = 0
maxV = max(list)
maxI = list.index(maxV)

sumV = sum(list[maxI:len(list)])
maxM = maxV * (len(list)-maxI)
ans += maxM - sumV

if maxI != 0:
    for i in range(0,maxI):
        if i != maxI-1:
            x = list[i] - list[i+1]
            if x > 0:
                ans += x
                list[i+1] = list[i+1]+x
print(ans)
Buggy code:
N = int(input(''))
A = input('')
A_N = A.split()
num = 0 
for i in range(1,N):
    if int(A_N[i]) >= int(A_N[i-1]):
        num += 0
    elif (A_N[i]) < (A_N[i-1]):
        num += int(A_N[i-1]) - int(A_N[i])
print(num)

Fixed code:
N = int(input(''))
A = input('')
a_n = A.split()
A_N = list(map(int, a_n))
num = 0 
for i in range(1,N):
    if A_N[i] >= A_N[i-1]:
        num += 0
    elif A_N[i] < A_N[i-1]:
        num += A_N[i-1] - A_N[i]
        A_N[i] = A_N[i-1]
print(num)
Buggy code:
n = int(input())
lis = list(map(int,input().split()))
sum = 0
for i in range(n-1):
  if int(lis[i])>int(lis[i+1]):
    sum += lis[i]-lis[i+1]
  else:
    continue
print(sum)

Fixed code:
n = int(input())
lis = list(map(int,input().split()))
sum = 0
for i in range(n-1):
  if int(lis[i])>int(lis[i+1]):
    sum += lis[i]-lis[i+1]
    lis[i+1] = lis[i]
  else:
    continue
print(sum)
Buggy code:
A = int(input())
B = list(map(int, input().split()))  

dai=[0, 0, 0, 0, 0]
for i, l in enumerate(B):
  if i==0:
    continue
  if B[i-1]-B[i]>0:
    dai[i]=B[i-1]-B[i]
    #B[i]+=B[i-1]-B[i]
    
print(sum(dai))

Fixed code:
A = int(input())
B = list(map(int, input().split()))  

dai=[0 for _ in range(A)]

for i, l in enumerate(B):
  if i==0:
    continue
  if B[i-1]-B[i]>0:
    dai[i]=B[i-1]-B[i]
    B[i]+=B[i-1]-B[i]

print(sum(dai))
Buggy code:
n = int(input())
a = list(map(int, input().split()))
s = 0

for i in range(0, n - 1):
    h = a[i] - a[i+1]
    if h > 0:
        s += h
        a[i] += h

print(str(s))


Fixed code:
n = int(input())
a = list(map(int, input().split()))
s = 0

for i in range(0, n - 1):
    h = a[i] - a[i+1]
    if h > 0:
        s += h
        a[i+1] = a[i]

print(str(s))
Buggy code:

n = int(input())
a_list = list(map(int, input().split()))

_sum = 0

for e in range(len(a_list)):
    # print('aaa')
    if e != 0 :
        # print('bbb')
        if a_list[e] < a_list[e - 1] :
            # print('ccc')
            _sum = _sum + (a_list[e - 1] - a_list[e])

print(_sum)

Fixed code:

n = int(input())
a_list = list(map(int, input().split()))

_sum = 0

for e in range(len(a_list)):
    # print('aaa')
    if e != 0 :
        # print('bbb')
        if a_list[e] < a_list[e - 1] :
            # print('ccc')
            _sum = _sum + (a_list[e - 1] - a_list[e])
            a_list[e] = a_list[e] + (a_list[e - 1] - a_list[e])

print(_sum)
Buggy code:
n = int(input())

s = list(map(int, input().split()))

print(s)

top = s[0]
count = 0

for x in s :
    if x <= top :
        count = count + top - x
    else :
         top = x

print(count)


Fixed code:
n = int(input())

s = list(map(int, input().split()))


top = s[0]
count = 0

for x in s :
    if x <= top :
        count = count + top - x
    else :
         top = x

print(count)
Buggy code:
inputs = input().split()
A = list(map(int, inputs[1:]))

sum = 0

for i in range(1, len(A)):
  if A[i] < A[i-1]:
    sum += A[i-1] - A[i]
    A[i] = A[i-1]
    
print(sum)


Fixed code:
input()
A = list(map(int, input().split()))

sum = 0

for i in range(1, len(A)):
  if A[i] < A[i-1]:
    sum += A[i-1] - A[i]
    A[i] = A[i-1]
    
print(sum)
Buggy code:
n=int(input())
l=map(int,input().split())
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-1
    maxt=max(i,maxt)
print(ans)


Fixed code:
n=int(input())
l=map(int,input().split())
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-i
  maxt=max(i,maxt)
print(ans)
Buggy code:
l=list(map(int,input().split()))
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-1
    maxt=max(i,maxt)
print(ans)


Fixed code:
n=int(input())
l=list(map(int,input().split()))
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-i
  maxt=max(i,maxt)
print(ans)
Buggy code:
n=int(input())
a=map(int,input(),split())

ans=0
cur_max=0

for x in a:
  if cur_max>x:
    ans+=cur_max-x
  cur_max=max(cur_max,x)

print(ans)

Fixed code:
n=int(input())
a=map(int,input().split())

ans=0
cur_max=0

for x in a:
  if cur_max>x:
    ans+=cur_max-x
  cur_max=max(cur_max,x)

print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
import copy
b = copy.copy(a)
tall = a[0]
for i in range(n):
    if a[i]<tall:
        a[i] = tall
        cnt +=tall-a[i]
    elif a[i]>tall:
        tall = a[i]
print(sum(a)-sum(b)) 

Fixed code:
n = int(input())
a = list(map(int, input().split()))
import copy
b = copy.copy(a)
tall = a[0]
for i in range(n):
    if a[i]<tall:
        a[i] = tall
    elif a[i]>tall:
        tall = a[i]
print(sum(a)-sum(b))
Buggy code:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(1, n):
  if a[i-1] > a[i]:
    total += a[i-1] - a[i]
    a[i] = a[i-1]

Fixed code:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(1, n):
  if a[i-1] > a[i]:
    total += a[i-1] - a[i]
    a[i] = a[i-1]
print(total)
Buggy code:
N=input()
list=[int(x) for x in input().split()]
i=0
kei=0
k=0
while(i!=len(list)-1):
    if(list[i]>list[i+1]):
        kei+=list[i]-list[i+1]
        list[i+1]=list[i]
        print(kei)
    i+=1
print(kei)

Fixed code:
N=input()
list=[int(x) for x in input().split()]
i=0
kei=0
k=0
while(i!=len(list)-1):
    if(list[i]>list[i+1]):
        kei+=list[i]-list[i+1]
        list[i+1]=list[i]
    i+=1
print(kei)