ZhenlongDai/ACPR huggingface dataset:
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
l = list(map(int,input().split()))
s=0
for i in range(n):
    if int(l[i-1])>int(l[i]):
        p=int(l[i-1])-int(l[i])
        s+=p
print(s)

Failing test case input:
5
0 -1 1 19 2

Expected output:
18


Actual output:
20


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
s=0
p=0
h_need=l[0]
for i in range(n):
    if h_need>l[i]:
        p=h_need-l[i]
        s+=p
    else:
        h_need=l[i]
print(s)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(len(A)-1):
    a_before = A[i]
    a_after = A[i+1]

    diff = a_before-a_after

    if diff < 0:
        ans += abs(diff)

print(ans)


Failing test case input:
5
22 10 1 -3 0

Expected output:
80


Actual output:
3


Fixed submission (verdict: Accepted):

N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(len(A)-1):
    a_before = A[i]
    a_after = A[i+1]

    
    diff = a_before-a_after
    
    if diff > 0:
        A[i+1] = a_before
        ans += diff

print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
max_len = A[0]
for i in range(1, len(A)):
    if A[i-1] < A[i]:
        max_len = A[i]
    else:
        ans += max_len - A[i]

print(ans)





Failing test case input:
5
21 -2 1 18 6

Expected output:
61


Actual output:
35


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
max_len = A[0]
for i in range(1, len(A)):
    if max_len < A[i]:
        max_len = A[i]
    else:
        ans += max_len - A[i]

print(ans)

Problem: p02578
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
Max = a[0]
ans = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        Max = a[i+1]
    else:
        ans += Max-a[i+1]
print(ans)

Failing test case input:
5
16 2 5 8 2

Expected output:
47


Actual output:
20


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
Max = a[0]
ans = 0
for i in range(1, n):
    if Max < a[i]:
        Max = a[i]
    else:
        ans += Max-a[i]
print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
5
49 10 2 -4 -1

Expected output:
189


Actual output:
39
86
139
189
189


Fixed submission (verdict: Accepted):
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)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = input()
l = [int(i) for i in input().split()]
max = 0
sum = 0
print(l)
for i in range(1,len(l)):

  if l[i-1] > max:
    max = l[i-1]
  if l[i] < max:
    sum += max - l[i]
print(sum)

Failing test case input:
5
4 4 3 7 6

Expected output:
2


Actual output:
[4, 4, 3, 7, 6]
2


Fixed submission (verdict: Accepted):
n = input()
l = [int(i) for i in input().split()]
max = 0
sum = 0
for i in range(1,len(l)):

  if l[i-1] > max:
    max = l[i-1]
  if l[i] < max:
    sum += max - l[i]
print(sum)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
list = list(map(int,input().split()))

ans = 0
maxV = max(list)
for i,ele in enumerate(list):
    if i == len(list)-1:
        continue

    if ele == maxV:
        for j in range(i+1,len(list)):
            hoge = maxV-list[j]
            
            ans += hoge
        break

    if ele > list[i+1]:
        hoge = ele - list[i+1]
        
        ans += hoge

print(ans)


Failing test case input:
5
2 1 1 16 6

Expected output:
12


Actual output:
11


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

n = int(input())

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

p = 0

q = 0

for i in range(n-1):
  
  e = a[i+1]-a[i]-q
  if e>0:
    if e>q:
      q = 0
    else:
      q -= e
  else:
    if p < q-e:
      p = q-e
      q = p
    else:
      q = q-e
    
  
print(p)

Failing test case input:
5
4 -1 76 3 0

Expected output:
154


Actual output:
149


Fixed submission (verdict: Accepted):

n = int(input())

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

p = 0

q = 0

for i in range(n-1):
  
  e = a[i+1]-a[i]
  if e > 0:
    if e > q:
      q = 0
    else:
      q = q-e
  else:
    q = q-e
  p += q
  
print(p)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
ans = 0
m = a[0]
for i in range(1,n-1):
  if a[i] > m:
    ans += a[i]-m
    m = a[i]
print(ans)


Failing test case input:
5
0 0 1 19 4

Expected output:
15


Actual output:
19


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
ans = 0
m = a[0]
for i in range(1,n):
  if a[i] <= m:
    ans += -a[i]+m
  else:
    m = a[i]
print(ans)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

sum_ = 0
for i in range(N - 1):
    if A[i] > A[i - 1]:
        diff = A[i] - A[i - 1]
        sum_ += diff
print(sum_)

Failing test case input:
5
2 1 5 8 3

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

sum_ = 0
for i in range(N - 1):
    if A[i] > A[i + 1]:
        diff = A[i] - A[i + 1]
        sum_ += diff
        A[i + 1] += diff
print(sum_)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
H = list(map(int, input().split()))
mh = 0
cnt = 0
for i in range(n - 1):
    mh = max(mh, H[i])
    if H[i] <= H[i + 1]:
        continue
    else:
        if H[i + 1] < H[i]:
            cnt += mh - H[i + 1]
print(cnt)


Failing test case input:
5
16 2 5 8 2

Expected output:
47


Actual output:
28


Fixed submission (verdict: Accepted):
n = int(input())
H = list(map(int, input().split()))
mh = 0
cnt = 0
for i in range(n - 1):
    mh = max(mh, H[i])
    if H[i] <= H[i + 1] and mh < H[i + 1]:
        continue
    else:
        cnt += mh - H[i + 1]
print(cnt)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a_list = list(map(int, input().split()))

h_list = [0]*(n+10)

for i in range(1,len(a_list)):
    if a_list[i] < a_list[i-1]:
        h_list[i] = a_list[i-1] + h_list[i-1] - a_list[i] 
    elif a_list[i] >= a_list[i-1]:
        h_list[i] = 0
        
print(sum(h_list))

Failing test case input:
5
2 0 1 31 2

Expected output:
32


Actual output:
31


Fixed submission (verdict: Accepted):
n = int(input())
a_list = list(map(int, input().split()))
 
h_list = [0]*(n+10)
 
for i in range(1,len(a_list)):
    if a_list[i]  < a_list[i-1] + h_list[i-1]:
        h_list[i] = a_list[i-1] + h_list[i-1] - a_list[i] 
    elif a_list[i] >= a_list[i-1] + h_list[i-1]:
        h_list[i] = 0
        
print(sum(h_list))

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
s = 0
if N==1:
  print(0)
  exit()

for i,a in enumerate(A):
  if i==0:
    continue
  
  s+=(a<A[i-1])*a

print(s)

Failing test case input:
5
13 0 0 -1 0

Expected output:
53


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
s = 0
if N==1:
  print(0)
  exit()

for i,a in enumerate(A):
  if i==0:
    continue
  
  tmp = A[i-1] - a
  if tmp>0:
    A[i] = A[i-1]
    s += tmp

print(s)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = [int(x) for x in input().split()]
buf = 0

for i in range(N-1) :
    if A[i] - A[i+1] >0 :
        buf += A[i] - A[i+1]
if A[N-2] - A[N-1] >0 :
    buf += A[N-2] - A[N-1]
print(buf)

Failing test case input:
5
0 0 1 35 8

Expected output:
27


Actual output:
54


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(x) for x in input().split()]
buf = 0

for i in range(1,N) :
    if A[i-1] - A[i] > 0 :
        buf += A[i-1] - A[i]
        A[i] = A[i] + (A[i-1] - A[i])
print(buf)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
            print(mi - a[i+1], mi)
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Failing test case input:
5
1 2 -2 44 2

Expected output:
46


Actual output:
4 2
42 44
46


Fixed submission (verdict: Accepted):
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if mi > a[i+1] or a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
now = A[0]
ans = 0
for i in range(1,N):
    if A[i]<now:
        step = now - A[i]
        ans += now
    else:
        step = 0
    now = A[i]+step
print(ans)


Failing test case input:
5
1 1 2 96 8

Expected output:
88


Actual output:
96


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
now = A[0]
ans = 0
for i in range(1,N):
    if A[i]<now:
        step = now - A[i]
        ans += step
    else:
        step = 0
    now = A[i]+step
print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)


Failing test case input:
5
2 1 5 8 3

Expected output:
6


Actual output:
[2, 1, 5, 8, 3]
6


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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))

Failing test case input:
5
49 10 2 -4 -1

Expected output:
189


Actual output:
53


Fixed submission (verdict: Accepted):
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))
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
B = A[0]
ans = 0
for i in range(N):
  if B < A[i]:
    ans += B - A[i]
    B = A[i]
print(ans)

Failing test case input:
5
10 0 1 -1 1

Expected output:
39


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
B = A[0]
ans = 0
for i in range(N):
  if B > A[i]:
    ans += abs(A[i] - B)
  B = max(A[i],B)
print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    cost += max(0, mi - a[-1])
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Failing test case input:
5
19 -1 5 13 4

Expected output:
55


Actual output:
50


Fixed submission (verdict: Accepted):
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    mi = 0
    le = len(a)
    cost = 0
    for i in range(le-1):
        if mi > a[i+1] or a[i] > a[i+1]:
            mi = max(a[i], mi)
            cost += mi - a[i+1]
    print(cost)
    return 0

if __name__ == "__main__":
    solve()

Problem: p02578
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

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


Failing test case input:
5
0 0 1 19 2

Expected output:
17


Actual output:
19


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

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

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    highest = A[0]

    for height in range(len(A)-1):
        if A[height] > A[height+1]:
            if A[height] > highest:
                highest = A[height]
            count += highest - A[height+1]

    print(count)


if __name__ == '__main__':
    main()

Failing test case input:
5
49 10 1 -4 -1

Expected output:
190


Actual output:
140


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    max_height = 0

    for height in A:
        if max_height < height:
            max_height = height
        else:
            count += max_height - height
    print(count)


if __name__ == '__main__':
    main()
Problem: p02578
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
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)

Failing test case input:
5
21 -1 1 14 6

Expected output:
64


Actual output:
21 -1
21 1
21 14
21 6
64


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


def main():
    
    N = int(input())
    A = list(map(int, input().split()))

    
    dp = [0] * (N + 10)
    

    for i in range(1, N):
        for j in range(N):
            
            if A[i - 1] + dp[i - 1] <= A[i] + j:
                
                dp[i] = j
                break
    print(sum(dp[:N]))

if __name__ == "__main__":
    main()

Failing test case input:
5
13 0 0 -2 0

Expected output:
54


Actual output:
2


Fixed submission (verdict: Accepted):


def main():
    
    N = int(input())
    A = list(map(int, input().split()))

    
    ma = A[0]

    res = 0
    for i in range(1, N):
        if A[i] <= ma:
            res += ma - A[i]
        else:
            ma = A[i]
    print(res)

if __name__ == "__main__":
    main()

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))

a=0
result=0

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

Failing test case input:
5
4 -1 107 3 0

Expected output:
216


Actual output:
112


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))

a=0
result=0

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

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
a=0
s=[]
for i in A:
  if i<a:
    s.append(a-i)
    a=i
  else:
    a=i
print(sum(s))

Failing test case input:
5
5 -1 175 0 0

Expected output:
356


Actual output:
181


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
a=0
s=[]
for i in A:
  if i<a:
    s.append(a-i)
    
  else:
    a=i
print(sum(s))
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

count = 0

for i, j in enumerate(a):
    try:
        if j < a[i - 1]:
            b = a[i - 1] - j
            count += b
            j += b
        else:
            pass
    except IndexError:
        pass

print(count)


Failing test case input:
5
49 10 2 -4 -1

Expected output:
189


Actual output:
53


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

count = 0

for i, j in enumerate(a):
    try:
        if j > a[i + 1]:
            b = j - a[i + 1]
            count += b
            a[i + 1] = j
        else:
            pass
    except IndexError:
        pass

print(count)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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:]:
        print(ans)
        if pre > a:
            ans += pre - a
        else:
            pre = a
    print(ans)

Failing test case input:
5
2 -2 -1 83 5

Expected output:
85


Actual output:
0
4
7
7
85


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())

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

ans = 0
print(len(a))
for i in range(n-1):
    x = max(0, a[i+1] - a[i])
    ans += x
    a[i+1] += x

print(ans)


Failing test case input:
5
2 23 -14 -7 1

Expected output:
89


Actual output:
5
29


Fixed submission (verdict: Accepted):
n = int(input())

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

ans = 0
for i in range(n-1):
    x = max(0, a[i] - a[i+1])
    ans += x
    a[i+1] += x

print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
out = 0
for i in range(1, N):
  d = max(A[i] - A[i-1], 0)
  out += d
  A[i] += d
print(int(out))

Failing test case input:
5
21 -1 1 14 6

Expected output:
64


Actual output:
13


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
top = A[0]
sup = 0
for i in range(1, N):
  d = A[i] - top
  if d > 0:
    top += d
  else:
    sup -= d
print(sup)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
listA=list(map(int,input().split()))
listB=[0]

for i in range(len(listA)-1):
  if listA[i+1]>listA[i]:
    listB.append(listA[i+1]-listA[i])

print(sum(listB))

Failing test case input:
5
1 2 3 6 3

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
n=int(input())
listA=list(map(int,input().split()))
listB=[0]

for i in range(len(listA)-1):
  if listA[i+1]<listA[i]:
    listB.append(listA[i]-listA[i+1])
    listA[i+1]=listA[i]
  else:
    listB.append(0)
    
print(sum(listB))
Problem: p02578
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def minimumStoolHeight(A):
    stool_tot = 0
    height_min = 0
    
    if len(A) == 1:
        return 0
    
    height_min = A[0]
    for i in range(1, len(A)):
        if A[i] < A[i-1]:
            
            if A[i-1] > height_min:
                height_min = A[i-1]
            stool_tot += (height_min - A[i])
            
            print(i, height_min, stool_tot)
          
    return stool_tot        
        
N = int(input())
A = list(map(int, input().rstrip().split()))
print(minimumStoolHeight(A))

Failing test case input:
5
4 -1 76 3 0

Expected output:
154


Actual output:
1 4 5
3 76 78
4 76 154
154


Fixed submission (verdict: Accepted):
def minimumStoolHeight(A):
    stool_tot = 0
    height_min = 0
    
    if len(A) == 1:
        return 0
    
    height_min = A[0]
    for i in range(1, len(A)):
        if A[i] < height_min:
            stool_tot += (height_min - A[i])
        else:
            height_min = A[i]         
            
    return stool_tot  
  
N = int(input())
A = list(map(int, input().rstrip().split()))
print(minimumStoolHeight(A))

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    b.append(c)
    a[j+1]=a[j+1]+c

  if max(b)>-1:
    print(max(b))
  else:
    print(0)
    
else:
  print(0)


Failing test case input:
5
16 2 5 11 4

Expected output:
42


Actual output:
14


Fixed submission (verdict: Accepted):
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
    else:
      b.append(0)
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,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)


Failing test case input:
5
21 -2 1 14 6

Expected output:
65


Actual output:
31


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(input().split())
An = [int(num) for num in A]
print(An)

sum = 0

for i in range(1,N):
  if An[i-1]<=An[i]:
    continue
  else:
    sum += (An[i-1]-An[i])
    An[i] = An[i-1]
    
print(sum)

Failing test case input:
5
0 -1 0 36 2

Expected output:
35


Actual output:
[0, -1, 0, 36, 2]
35


Fixed submission (verdict: Accepted):
N = int(input())
A = list(input().split())
An = [int(num) for num in A]

sum = 0

for i in range(1,N):
  if An[i-1]<=An[i]:
    continue
  else:
    sum += (An[i-1]-An[i])
    An[i] = An[i-1]
    
print(sum)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
5
0 0 1 41 4

Expected output:
37


Actual output:
46


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i == 0:
        ans = 0
    else:
        if A[i] > A[i-1]:
            ans = ans + A[i] - A[i-1]
print(ans)

Failing test case input:
5
1 1 0 96 0

Expected output:
97


Actual output:
96


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i == 0:
        M = A[0]
    else:
        if A[i] > M:
            M = A[i]
        else:
            ans = ans + M - A[i]
print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
As = list(map(int , input().split()))
mx = As[-1]
sm = 0
for i in range(len(As)-2,0,-1):
  if As[i] < mx:
    sm+= mx - As[i]
  else:
    mx = As[i]
print(sm)

Failing test case input:
5
2 1 1 16 6

Expected output:
12


Actual output:
30


Fixed submission (verdict: Accepted):
N = int(input())
As = list(map(int , input().split()))
mx = As[0]
sm = 0
for i in range(N-1):
  if mx > As[i+1]:
    sm += mx - As[i+1]
  else:
    mx = As[i+1]
print(sm)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = [0]*N
A = list(map(int, input().split()))
 
sum_step = 0
 
for n in range(1, N):
  if A[n] >= A[n-1]:
    pass
  else:
    sum_step += A[n-1] - A[n]
  
print(sum_step)

Failing test case input:
5
1 0 -6 36 3

Expected output:
41


Actual output:
40


Fixed submission (verdict: Accepted):
N = int(input())
A = [0]*N
A = list(map(int, input().split()))
 
sum_step = 0
 
for n in range(1,N):
  if A[n] < A[n-1]:
    sum_step += A[n-1] - A[n]
    A[n] = A[n-1]

print(sum_step)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a_list = list(map(int,input().split()))

a_tmp = a_list[0]

sum = 0
for i in range(1, len(a_list)):
    if a_list[i] > a_tmp:
        sum += a_list[i] - a_tmp
        a_tmp = a_list[i]
    else:
        a_tmp = a_list[i]

print(sum)

Failing test case input:
5
5 -1 107 1 0

Expected output:
219


Actual output:
108


Fixed submission (verdict: Accepted):
n=int(input())
a_list = list(map(int,input().split()))

a_tmp = a_list[0]

sum = 0
for i in range(1, len(a_list)):
    if a_tmp > a_list[i]:
        sum += a_tmp - a_list[i]
    else:
        a_tmp = a_list[i]

print(sum)
Problem: p02578
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
a_list = list(map(int,input().split()))
ans = 0
min = a_list[0]
for i in range(1,N):
  if min > a_list[i]:
    ans += a_list[i]-min
  else:
    min = a_list[i]
print(ans)

Failing test case input:
5
1 2 3 6 3

Expected output:
3


Actual output:
-3


Fixed submission (verdict: Accepted):
N=int(input())
a_list = list(map(int,input().split()))
ans = 0
min = a_list[0]
for i in range(1,N):
  if min > a_list[i]:
    ans += min-a_list[i]
  else:
    min = a_list[i]
print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)    

Failing test case input:
5
1 2 0 25 2

Expected output:
25


Actual output:
[1, 2, 0, 25, 2]
sum =  25 main =  [1, 2, 2, 25, 25]


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


if __name__ == '__main__':
    N = int(input())

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

    M = max(li)
    

    MV = li[0]
    C = 0
    hai = li.index(M)
    
    for i in range(N):
        if i < hai:
            if MV > li[i]:
                C += MV - li[i]

        else:
            C += M - li[i]
        

    print(C)


Failing test case input:
5
1 2 -2 44 2

Expected output:
46


Actual output:
45


Fixed submission (verdict: Accepted):


if __name__ == '__main__':
    N = int(input())

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

    M = max(li)
    

    MV = li[0]
    C = 0
    hai = li.index(M)
    
    for i in range(N):
        if i < hai:
            if MV > li[i]:
                C += MV - li[i]
            else:
                MV = li[i]

        else:
            C += M - li[i]
        

    print(C)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))

ans=0

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

print(ans)

Failing test case input:
5
1 1 0 26 -1

Expected output:
28


Actual output:
-1
-27
28


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))

ans=0

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

print(ans)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
tmp=l[0]
ans=0
for i in range(n-1):
    if l[i+1]<=l[i]:
        ans+=(tmp-l[i+1])
    else:
        tmp=l[i+1]
print(ans)

Failing test case input:
5
21 -1 1 14 4

Expected output:
66


Actual output:
32


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
tmp=l[0]
ans=0
for i in range(n):
    if tmp>=l[i]:
        ans+=(tmp-l[i])
    else:
        tmp=l[i]
print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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

Failing test case input:
5
1 2 -2 44 2

Expected output:
46


Actual output:

Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
s = [0]*N
for i,n in enumerate(A):
    if i == 0:
        continue
    s[i] = max(0, A[i-1] + s[i-1] - A[i])

print(sum(s))
print(s)

Failing test case input:
5
10 1 5 11 3

Expected output:
22


Actual output:
22
[0, 9, 5, 0, 8]


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]
s = [0]*N
for i,n in enumerate(A):
    if i == 0:
        continue
    s[i] = max(0, A[i-1] + s[i-1] - A[i])

print(sum(s))

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
5
22 10 1 -3 0

Expected output:
80


Actual output:
25


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

ans = 0
high = 0
for i in range(1,N):
    af = A[i]
    bf = A[i-1]
    if bf > high:
        high = bf
    if high > af:
        ans += high - af
    print(high,bf,af,ans)

print(ans)

Failing test case input:
5
2 -1 0 50 5

Expected output:
50


Actual output:
2 2 -1 3
2 -1 0 5
2 0 50 5
50 50 5 50
50


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))

ans = 0
high = 0
for i in range(1,N):
    af = A[i]
    bf = A[i-1]
    if bf > high:
        high = bf
    if high > af:
        ans += high - af

print(ans)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
line = input()
A = [int(l) for l in line.split()]

total = 0

for i in range(N-1):
  diff = A[i-1] - A[i]
  if diff > 0 :
    total = total + diff
    A[i] = A[i] + diff

print(total)

Failing test case input:
5
13 1 5 0 2

Expected output:
44


Actual output:
33


Fixed submission (verdict: Accepted):
N = int(input())
line = input()
A = [int(l) for l in line.split()]

total = 0

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

print(total)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=[int(x) for x in input().split()]
mx=0
mae=a[0]
for i in a:
    mx+=i-mae
    mae=i
print(mx)

Failing test case input:
5
0 -1 1 19 4

Expected output:
16


Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(x) for x in input().split()]
mx=0
mae=a[0]
for i in a:
    if i<mae:
        mx=mx+mae-i
    else:
        mae=i
print(mx)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
loop = int(input())

tall = list(map(int, input().split()))
front = tall[0]
standard = front
result = 0


for i in range(1, loop):
  back = tall[i]
  
  if back-front > 0:
    standard = back
  elif back-front < 0:
    result += standard - back
  front = back

print(result)

Failing test case input:
5
13 1 5 -1 2

Expected output:
45


Actual output:
18


Fixed submission (verdict: Accepted):
loop = int(input())

tall = list(map(int, input().split()))
front = tall[0]
standard = front
result = 0


for i in range(1, loop):
  back = tall[i]
  
  if back-standard > 0:
    standard = back
  elif back-standard < 0:
    result += standard - back
  front = back

print(result)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(1,n):
  d=A[i]-A[i-1]
  if d>0:
    ans += d
    A[i]+=d
print(ans)

Failing test case input:
5
28 0 5 11 4

Expected output:
92


Actual output:
6


Fixed submission (verdict: Accepted):
n=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(1,n):
  d=A[i-1]-A[i]
  if d>0:
    ans += d
    A[i]+=d
print(ans)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def run(x, a_list):
    
    if x == 1:
        print(0)
    else:
        out = 0
        for i,v in enumerate(a_list):
            if i == 0:
                continue
            if i == x-1:
                break
            out += 0 if v < a_list[i-1] else v - a_list[i-1]
            
        print(out)
            


    



if __name__ == '__main__':
    x = int(input())
    a_list = list(map(int, input().split()))
    run(x, a_list)

Failing test case input:
5
13 1 5 1 2

Expected output:
43


Actual output:
4


Fixed submission (verdict: Accepted):
def run(x, a_list):
    
    if x == 1:
        print(0)
    else:
        out = 0
        prev = 0
        for i,v in enumerate(a_list):
            if i == 0:
                continue
            prev_height = prev + a_list[i-1]
            if v > prev_height:
                out += 0
                prev = 0
            else:
                out += prev_height - v
                prev = prev_height - v
            
        print(out)
            


    



if __name__ == '__main__':
    x = int(input())
    a_list = list(map(int, input().split()))
    run(x, a_list)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

_sum = 0

for e in range(len(a_list)):
    
    if e != 0 :
        
        if a_list[e] < a_list[e - 1] :
            
            _sum = _sum + (a_list[e - 1] - a_list[e])

print(_sum)

Failing test case input:
5
8 -1 107 2 0

Expected output:
221


Actual output:
116


Fixed submission (verdict: Accepted):

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

_sum = 0

for e in range(len(a_list)):
    
    if e != 0 :
        
        if a_list[e] < a_list[e - 1] :
            
            _sum = _sum + (a_list[e - 1] - a_list[e])
            a_list[e] = a_list[e] + (a_list[e - 1] - a_list[e])

print(_sum)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
li  =   lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw  =   lambda : sys.stdin.readline().strip().split()
ni  =   lambda : int(sys.stdin.readline().strip())
nsi =   lambda : sys.stdin.readline().strip()

from collections import defaultdict as df
import math

n=ni()
l=list(map(int,input().split()))
mn=l[0]
ans=0
for i in range(1,n):
    if(mn<l[i]):
        mn=l[i]
        print(l[i])
    else:
        ans+=mn-l[i]
print(ans)


Failing test case input:
5
1 1 2 96 8

Expected output:
88


Actual output:
2
96
88


Fixed submission (verdict: Accepted):
import sys
li  =   lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw  =   lambda : sys.stdin.readline().strip().split()
ni  =   lambda : int(sys.stdin.readline().strip())
nsi =   lambda : sys.stdin.readline().strip()

from collections import defaultdict as df
import math

n=ni()
l=list(map(int,input().split()))
mn=l[0]
ans=0
for i in range(1,n):
    if(mn<l[i]):
        mn=l[i]
    else:
        ans+=mn-l[i]
print(ans)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A = list(map(int, input().split()))

count=0
count2=0

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

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

count2=A[-2]-A[-1]
print(count2)

Failing test case input:
5
5 -1 107 1 0

Expected output:
219


Actual output:
6
106
107
0


Fixed submission (verdict: Accepted):
N=int(input())
A = list(map(int, input().split()))

count=0
count2=0

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

print(count2)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
ans = 0
m = a[0]
for i in range(1,n):
  if a[i] > m:
    ans += a[i]-m
    m = a[i]
print(ans)


Failing test case input:
5
0 -1 1 19 2

Expected output:
18


Actual output:
19


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
ans = 0
m = a[0]
for i in range(1,n):
  if a[i] <= m:
    ans += -a[i]+m
  else:
    m = a[i]
print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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 = s
    else:
        c = 0
print(sum(b))

Failing test case input:
5
4 0 0 96 -2

Expected output:
106


Actual output:
102


Fixed submission (verdict: Accepted):
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))

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
total = int(input())
tall = list(map(int, input().split()))
dif = 0
for i in range(total - 1):
    if tall[i+1] > tall[i]:
        var = tall[i+1] - tall[i]
        tall[i] += var
        dif += var
    else:
        pass
print(dif)


Failing test case input:
5
21 -1 1 14 6

Expected output:
64


Actual output:
15


Fixed submission (verdict: Accepted):
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)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
As = list(map(int,input().split()))
sum = 0
step =0

try:
    for i in range(n):
        if As[i] > As[i + 1]:
            step = As[i] - As[i + 1]
            print(step)
            As[i + 1] += step
            print("As["+str(i + 1)+"]:"+str(As[i + 1]))
            sum += step 
except IndexError:
    pass

print(sum)

Failing test case input:
5
16 2 5 6 2

Expected output:
49


Actual output:
14
As[1]:16
11
As[2]:16
10
As[3]:16
14
As[4]:16
49


Fixed submission (verdict: Accepted):
n = int(input())
As =list(map(int,input().split()))

sum = 0
step =0


for i in range(n):
    try:
        if As[i] > As[i + 1]:
            step = As[i] - As[i + 1]
            As[i + 1] += step
            sum += step 
    except IndexError:
        continue



print(sum)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(i) for i in input().split()]
print(a)
ans=0
for i in range(n-1):
  d = a[i-1] - a[i]
  if d<0:
    ans+= d+1
    a[i]=a[i]+d+1
  else:
    continue
    
print(abs(ans))

Failing test case input:
5
21 -4 1 18 6

Expected output:
63


Actual output:
[21, -4, 1, 18, 6]
38


Fixed submission (verdict: Accepted):
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))

Problem: p02578
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = input()
a_list = list(map(int, input().split()))
score = 0

for i in range(len(a_list) - 1):
  if a_list[i] < a_list[i+1]:
    score += a_list[i+1] - a_list[i]
    
print(score)

Failing test case input:
5
0 0 1 19 4

Expected output:
15


Actual output:
19


Fixed submission (verdict: Accepted):
n = input()
a_list = list(map(int, input().split()))
score = 0

for i in range(len(a_list) - 1):
  if a_list[i] > a_list[i+1]:
    score += a_list[i] - a_list[i+1]
    a_list[i+1] = a_list[i]
    
print(score)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
num = int(input())
line = list(map(int,input().split()))

mini = line[0]
x = 0
for i in range(1,num):
  if mini > line[1]:
    x += 1
  else:
    mini = line[i]
print(x)

Failing test case input:
5
0 -1 1 19 2

Expected output:
18


Actual output:
4


Fixed submission (verdict: Accepted):
num = int(input())
line = list(map(int,input().split()))

mini = line[0]
x = 0
for i in range(1,num):
  if mini > line[i]:
    x += mini - line[i]
  else:
    mini = line[i]
print(x)
Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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:
            x = list[i] - list[i+1]
            if x > 0:
                ans += x
print(ans)


Failing test case input:
5
1 0 0 67 2

Expected output:
67


Actual output:
66


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())

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

ans = 0
print(len(a))
for i in range(n-1):
    x = max(0, a[i] - a[i+1])
    ans += x
    a[i+1] += x

print(ans)


Failing test case input:
5
10 1 8 8 3

Expected output:
20


Actual output:
5
20


Fixed submission (verdict: Accepted):
n = int(input())

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

ans = 0
for i in range(n-1):
    x = max(0, a[i] - a[i+1])
    ans += x
    a[i+1] += x

print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def stepUp(val_list):
  counter = 0

  for i in range(len(val_list) - 1):
      current = val_list[i]
      up = val_list[i + 1]

      if (current > up):
          counter += current - up

  if (val_list[len(val_list) - 2] > val_list[len(val_list) -1]):
      counter += val_list[len(val_list) - 2] - val_list[len(val_list) -1]

  return counter

def userInput():
    a_count = int(input())
    a = list(map(int, input().rstrip().split()))
    
    return stepUp(a)
  
print(userInput())

Failing test case input:
5
1 1 2 96 2

Expected output:
94


Actual output:
188


Fixed submission (verdict: Accepted):
def stepUp(val_list):
    temp = 0
    counter = 0

    for i in range(len(val_list) - 1):
        current = val_list[i]
        up = val_list[i + 1]

        if (current > up):
            counter += current - up
            temp += current - up
            val_list[i + 1] = current
          
        temp = 0

    if (val_list[len(val_list) - 2] > val_list[len(val_list) -1]):
        counter += val_list[len(val_list) - 2] - val_list[len(val_list) -1]

    return counter

def userInput():
    a_count = int(input())
    a = list(map(int, input().rstrip().split()))
    
    return stepUp(a)
  
print(userInput())
Problem: p02578
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if a[i] > a[i+1]:
        ans += a[i]-a[i+1]
        a[i-1] = a[i]

print(ans)

Failing test case input:
5
5 -1 107 1 0

Expected output:
219


Actual output:
112


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if a[i] > a[i+1]:
        ans += a[i]-a[i+1]
        a[i+1] = a[i]

print(ans)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

res = a[0]
ans = 0
for i in range(n-1):
  if a[i]>=a[i+1]:
    ans += res-a[i+1]
  else:
    res = a[i+1]
    
print(ans)

Failing test case input:
5
10 2 1 -1 2

Expected output:
36


Actual output:
28


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

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

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
5
49 10 0 -4 -1

Expected output:
191


Actual output:
53


Fixed submission (verdict: Accepted):
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)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
ary_A = list(map(int, input().split()))

h_sum  = 0

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

print(h_sum)

Failing test case input:
5
16 2 5 11 4

Expected output:
42


Actual output:
9


Fixed submission (verdict: Accepted):
N = int(input())
ary_A = list(map(int, input().split()))

h_sum  = 0
temp_max = ary_A[0]

for i in range(len(ary_A) - 1):
    diff = ary_A[i + 1] - temp_max
    if diff < 0:
        h_sum += abs(diff)
    else:
        temp_max = ary_A[i + 1]

print(h_sum)

Problem: p02578
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    
    for i in range(1, len(a)):
        humidai = max(0, a[i] - a[i-1])
        ans +=  humidai
        a[i] += humidai
    print(ans)
        
        
if __name__ == '__main__':
    main()

Failing test case input:
5
0 0 1 41 11

Expected output:
30


Actual output:
40


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    
    for i in range(1, len(a)):
        humidai = max(0, a[i-1] - a[i])
        ans +=  humidai
        a[i] += humidai
    print(ans)
        
        
if __name__ == '__main__':
    main()