ZhenlongDai/ACPR huggingface dataset:
Problem: p03862
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def candy():
    boxNum, x = [int(i) for i in input().split()]
    ain = input()
    alist = ain.split(' ')

    s = 0

    for i in range(0, boxNum-1):
        if int(alist[i+1]) + int(alist[i]) > x:
            if int(alist[i]) > x:
                s = s + x - int(alist[i])
                alist[i] = x
            s = s + (int(alist[i+1]) + int(alist[i]) - x)
            alist[i+1] = x - int(alist[i])
        
    print(s)
    
candy()

Failing test case input:
2 0
1 10

Expected output:
11


Actual output:
9


Fixed submission (verdict: Accepted):
def candy():
    boxNum, x = [int(i) for i in input().split()]
    ain = input()
    alist = ain.split(' ')

    s = 0
    
    for i in range(0, boxNum-1):
        if int(alist[i+1]) + int(alist[i]) > x:
            s = s + (int(alist[i+1]) + int(alist[i]) - x)
            alist[i+1] = x - int(alist[i])
            if int(alist[i+1]) < 0:
                alist[i] = int(alist[i]) + int(alist[i+1])
                alist[i+1] = 0
        
    print(s)
    
candy()

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

N,x = map(int,input().split())
a = [int(i) for i in input().split()]
part_sum = [0 for i in range(N)]

ans = 0
if a[0] > x:
    ans += a[0]-x
    tmp = a[0]-x
else:
    tmp = a[0]
for i in range(1,N):
    if tmp + a[i] > x:
        ans += tmp + a[i] -x
        a[i] -= tmp + a[i] -x

    tmp = a[i]


print(ans)




Failing test case input:
2 0
4 0

Expected output:
4


Actual output:
8


Fixed submission (verdict: Accepted):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

N,x = map(int,input().split())
a = [int(i) for i in input().split()]
part_sum = [0 for i in range(N)]

ans = 0
if a[0] > x:
    ans += a[0]-x
    a[0] = x
left = a[0]
for i in range(1,N):
    if left + a[i] > x:
        ans += left + a[i] - x
        a[i] = x - left
    left = a[i]


print(ans)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

a[0] = min(a[0], x)
count = max(0, a[0] - x)

for i in range(len(a) - 1):
    if a[i] + a[i + 1] > x:
        tmp_num = max(0, a[i] + a[i + 1] - x)
        count += tmp_num
        a[i + 1] -= tmp_num
print(count)

Failing test case input:
2 0
5 5

Expected output:
10

Actual output:
5


Fixed submission (verdict: Accepted):


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

count = max(0, a[0] - x)
a[0] = min(a[0], x)

for i in range(len(a) - 1):
    if a[i] + a[i + 1] > x:
        tmp_num = max(0, a[i] + a[i + 1] - x)
        count += tmp_num
        a[i + 1] -= tmp_num
print(count)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
  if i == 0 and A[i] <= x:
    continue
  elif i == 0 and A[i] > x:
    ans += (A[i]-x)
    A[i] = x
    continue
  else:
    if A[i] + A[i-1] <= x:
      print(i)
      continue
    else:
      ans += (A[i]+A[i-1]-x)
      A[i] = x-A[i-1]
print(ans)

Failing test case input:
5 9
3 1 4 2 5

Expected output:
0


Actual output:
1
2
3
4
0


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

Problem: p03862
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

def eat(i,j,candies,counter):
    s=candies[i]+candies[j]
    if s>x:
        if candies[i]>=s-x:
            counter+=s-x
            candies[i]-=s+x
        else:
            counter+=s-x
            candies[j]-=s-x-candies[i]
            candies[i]=0
    return counter

def main(n,x,candies):
    counter=0
    for i in range(1,n):
        counter=eat(i,i-1,candies,counter)
    return counter

n,x=map(int,sys.stdin.readline().strip().split())
candies=list(map(int,sys.stdin.readline().strip().split()))
print(main(n,x,candies))


Failing test case input:
3 3
2 2 4

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

def eat(i,candies,counter):
    s=candies[i]+candies[i-1]
    nc=max(0,s-x)
    counter+=nc
    candies[i]-=nc
    return counter

def main(n,x,candies):
    counter=0
    if candies[0]>x:
        counter=candies[0]-x
        candies[0]=x
    for i in range(1,n):
        counter=eat(i,candies,counter)
    return counter

n,x=map(int,sys.stdin.readline().strip().split())
candies=list(map(int,sys.stdin.readline().strip().split()))
print(main(n,x,candies))

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x=map(int,input().split())
a=input().split()
numbers=[int(b) for b in a]
count=0
n=len(numbers)
while numbers[0]>=x:
    numbers[0]-=1
    count+=1
for c in range(n-1):
    while numbers[c] + numbers[c+1] >x:
        numbers[c+1]-=1
        count+=1
print(count)


Failing test case input:
6 0
0 0 1 2 0 5

Expected output:
8


Actual output:
9


Fixed submission (verdict: Accepted):
N,x=map(int,input().split())
a=input().split()
numbers=[int(b) for b in a]
count=0
n=len(numbers)
if numbers[0]>x:
    count = numbers[0] - x
    numbers[0]=x
for c in range(n-1):
    if numbers[c] + numbers[c+1]>x:
        count+=numbers[c+1]-(x-numbers[c])
        numbers[c+1]=x-numbers[c]
print(count)
Problem: p03862
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, x = map(int, input().split())
a=list(map(int, input().split()))

count=0
for i in range(1, N):
    if a[i]+a[i-1] > x:
        count += min(a[i] + a[i - 1] - x, a[i])
        a[i]=max(0, x-a[i-1])
if a[0]+a[1] > x:
    count+=a[0]-x
    a[0]=x
print(a)
print(count)



Failing test case input:
-2 63
5 1 4 3 0

Expected output:
0


Actual output:
[5, 1, 4, 3, 0]
0


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

count=0
for i in range(1, N):
    if a[i]+a[i-1] > x:
        count += min(a[i] + a[i - 1] - x, a[i])
        a[i]=max(0, x-a[i-1])
if a[0]+a[1] > x:
    count+=a[0]-x
    a[0]=x

print(count)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import copy

N, x = map(int, input().split())
A = list(map(int, input().split()))
B = copy.deepcopy(A)

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

cnt = sum(B) - sum(A)
print(cnt)


Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
12


Fixed submission (verdict: Accepted):

N, x = map(int, input().split())
A = list(map(int, input().split()))
sum_s = sum(A)

for i in range(N-1):
    s = A[i] + A[i+1] - x
    if s > 0:
        A[i+1] = x - A[i]
        if A[i+1] >= 0:
            pass
        else:
            A[i] = A[i] + A[i+1]
            A[i+1] = 0
    else:
        pass

sum_e = sum(A)
print(sum_s - sum_e)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x = map(int,input().split())
a = [i for i in map(int,input().split())]

ans = 0
while a[0] > x:
  a[0] -= 1
  ans += 1
while a[-1] > x:
  a[-1] -= 1
  ans += 1

for i in range(1,len(a)-1):
  if a[i] == 0:
    break
  while a[i-1]+a[i] > x or a[i]+a[i+1] > x:
    a[i] -= 1
    ans += 1
    if a[i] == 0:
      break

print(ans)

Failing test case input:
6 0
0 0 1 2 0 5

Expected output:
8


Actual output:
5


Fixed submission (verdict: Accepted):
N,x = map(int,input().split())
a = [i for i in map(int,input().split())]

ans = 0
if a[-1] > x:
  ans += a[-1] - x
  a[-1] = x


for i in range(N-2,-1,-1):
  if a[i] > x-a[i+1]:
    if x - a[i+1] < 0:
      ans += a[i]
      a[i] = 0
    else:
      ans += a[i] - (x - a[i+1])
      a[i] = (x - a[i+1])

print(ans)
Problem: p03862
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def solve():
    n, x = map(int, input().split())
    s = list(map(int, input().split()))
    cnt, tmp, flg = 0, 0, False
    for i in range(n - 1):
        if i == 0 and s[i] > x:
            cnt += s[i] - x
            s[i] = x
        elif s[i] + s[i + 1] > x:
            tmp = s[i] + s[i + 1] - x
            cnt += tmp
            s[i + 1] -= tmp
    print(cnt)



solve()


Failing test case input:
6 1
2 6 1 2 0 5

Expected output:
13


Actual output:
11


Fixed submission (verdict: Accepted):
def solve():
    n, x = map(int, input().split())
    s = list(map(int, input().split()))
    cnt, tmp, flg = 0, 0, False
    for i in range(n - 1):
        if i == 0 and s[i] > x:
            cnt += s[i] - x
            s[i] = x
        if s[i] + s[i + 1] > x:
            tmp = s[i] + s[i + 1] - x
            cnt += tmp
            s[i + 1] -= tmp
    print(cnt)



solve()

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N,x = map(int, input().split())
candy_list = list(map(int, input().split()))

count_candy_eat = 0

if(candy_list[-1] == 0):
    candy_list[::-1]

for i in range(N):
    if(i == 0):
        continue
    else:
        if(candy_list[i-1] + candy_list[i] > x):
            count_candy_eat += candy_list[i-1] + candy_list[i] - x
            candy_list[i] = candy_list[i] - count_candy_eat

print(count_candy_eat)

Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):


N,x = map(int, input().split())
candy_list = list(map(int, input().split()))

count_candy_eat = 0

for i in range(N):
    if(i == 0):
        if(candy_list[0] > x):
            count_candy_eat += candy_list[0] - x
            candy_list[0] = x
    else:
        if(candy_list[i-1] + candy_list[i] > x):
            if(x - candy_list[i-1] > 0):
                count_candy_eat += candy_list[i-1] + candy_list[i] - x
                candy_list[i] = x - candy_list[i-1]
            else:
                count_candy_eat += candy_list[i]
                candy_list[i] = 0


print(count_candy_eat)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0











for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        if array[i+1] - (array[i] + array[i+1] - x) >= 0:
            array[i+1]=array[i+1] - (array[i] + array[i+1] - x)
        else:
            array[i] - (x-array[i+1])
            array[i+1]- x


print(sum(array2)-sum(array))

Failing test case input:
2 0
2 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0











for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        
        
        if (array[i]+array[i+1])-x <= array[i+1]:
            array[i+1]= array[i+1] - (array[i]+array[i+1]-x)
        else:
            
            array[i]= array[i]-(array[i]-x)
            array[i+1]=0



print(sum(array2)-sum(array))
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input=sys.stdin.readline

def main():
    N,x = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(0, N-1):
        if A[i] + A[i+1] > x:
            j = (max(A[i:i+2]) + min(A[i:i+2])) - x
            if A[i] > A[i+1]:
                A[i] -= j
            else:
                A[i+1] -= j
            ans += j
            
    print(ans)

if __name__ == '__main__':
    main()


Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
12


Fixed submission (verdict: Accepted):
import sys
input=sys.stdin.readline

def main():
    N,x = map(int, input().split())
    A = list(map(int, input().split()))
    s0 = sum(A)
    if A[0] > x:
        A[0] = x
    for i in range(N-1):
        if A[i] + A[i+1] > x:
            j = A[i] + A[i+1] - x
            A[i+1] -= j
    print(s0-sum(A))

if __name__ == '__main__':
    main()

Problem: p03862
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,x=map(int,input().split())
a=list(map(int,input().split()))

count=0
if a[0]>x:
    a[0]=x
    count+=x-a[0]
for i in range(1,N):
    if a[i]+a[i-1]>x:
        a[i]=x-a[i-1]
        count+=a[0]+a[i-1]-x
print(count)

Failing test case input:
6 1
2 6 1 2 0 5

Expected output:
13


Actual output:
2


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

count=0
if a[0]>x:
    count=(a[0]-x)
    a[0]=x

for i in range(1,N):
    if a[i]+a[i-1]>x:
        count+=(a[i]+a[i-1]-x)
        a[i]=x-a[i-1]
print(count)

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

cnt = 0

for i in range(1,n):
    if a[i-1]+a[i]<=x:
        pass
    else:
        if (a[i]+a[i-1])-x > a[i]:
            a[i] = 0
            cnt += (a[i]+a[i-1])-x
        else:    
            cnt += (a[i]+a[i-1])-x
            a[i]-= (a[i]+a[i-1])-x

print(cnt)


Failing test case input:
2 0
1 10

Expected output:
11


Actual output:
1


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

cnt = 0

for i in range(n-1):
    if a[i]+a[i+1]<=x:
        pass
    else:
        if (a[i+1]+a[i])-x > a[i+1]:
            cnt += (a[i+1]+a[i])-x
            a[i+1] = 0

        else:
            cnt += (a[i+1]+a[i])-x
            a[i+1] -= (a[i+1]+a[i])-x

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

Failing test case input:
6 1
1 6 1 2 0 4

Expected output:
11

Actual output:
15


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

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int,input().split())
a = list(map(int,input().split()))
Nc = 0
if a[0] > x:
    Nc += a[0] - x
    a[0] = x
print(Nc)
for i in range(N-1):
    if (a[i] + a[i+1] - x) > 0:
        Nc += a[i] + a[i+1] -x
        a[i+1] = x - a[i]

print(Nc)

Failing test case input:
5 9
3 1 4 1 5

Expected output:
0

Actual output:
0
0


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

print(Nc)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
count = 0
if a[1] > x:
    difference = x-a[1]
    count += difference
    a[1] -= difference
     
for i in range(N-1):
    difference = x - (a[i] + a[i+1])
    if difference < 0:
        count += abs(difference)
        a[i+1] += difference

print(a)
print(count)

Failing test case input:
-4 124
6 2 2 0 3

Expected output:
0


Actual output:
[6, 2, 2, 0, 3]
0


Fixed submission (verdict: Accepted):
N,x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
count = 0
if a[1] > x:
    difference = x-a[1]
    count += difference
    a[1] -= difference
     
for i in range(N-1):
    difference = x - (a[i] + a[i+1])
    if difference < 0:
        count += abs(difference)
        a[i+1] += difference
        if a[i+1] < 0:
            a[i] += a[i]
            a[i+1] = 0 


print(count)

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

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


Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N,x = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
ans += max(0,A[0]-x)
A[0] -= max(0,A[0]-x)
for i in range(N-1) :
    ans += max(0,A[i]+A[i+1]-x)
    A[i+1] -= max(0,A[i]+A[i+1]-x)
print(ans)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int,input().split())
cList = list(map(int,input().split()))

count = 0
if cList[0] > x:
  cList[0] = x
  count += cList[0]- x

for i in range(1,n):
  tmp = cList[i-1]+cList[i]-x
  if tmp > 0:
    cList[i] -= tmp
    count += tmp

print(count)
 

Failing test case input:
2 0
1 9

Expected output:
10


Actual output:
9


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

count = 0
if cList[0] > x:
  count += cList[0]- x
  cList[0] = x
for i in range(1,n):
  tmp = cList[i-1]+cList[i]-x
  if tmp > 0:
    cList[i] -= tmp
    count += tmp

print(count)

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

count = 0
for i in range(len(a)-1):
    if a[i+1]+a[i]>x:
        c = min((a[i+1]+a[i]-x),a[i+1])
        a[i+1] -= c
        count += c
    if a[i+1]+a[i]>x:
        c = a[i]
        a[i] -=c
        count += c
print(count)

Failing test case input:
6 1
2 6 1 2 0 4

Expected output:
12


Actual output:
13


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

count = 0
for i in range(len(a)-1):
    if a[i+1]+a[i]>x:
        c = min((a[i+1]+a[i]-x),a[i+1])
        a[i+1] -= c
        count += c
    if a[i+1]+a[i]>x:
        c = min(a[i+1]+a[i]-x,a[i])
        a[i] -=c
        count += c
print(count)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0











for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        
        
        if (array[i]+array[i+1])-x <= array[i+1]:
            array[i+1]= array[i+1] - (array[i]+array[i+1]-x)
        else:
            
            array[i]= array[i]-(array[i]-x)
            array[i+1]=0

print(array2)
print(array)
print(sum(array2)-sum(array))

Failing test case input:
-2 124
6 2 2 6 6

Expected output:
0


Actual output:
[6, 2, 2, 6, 6]
[6, 2, 2, 6, 6]
0


Fixed submission (verdict: Accepted):
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0











for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        
        
        if (array[i]+array[i+1])-x <= array[i+1]:
            array[i+1]= array[i+1] - (array[i]+array[i+1]-x)
        else:
            
            array[i]= array[i]-(array[i]-x)
            array[i+1]=0



print(sum(array2)-sum(array))
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x = map(int,input().split())
A = list(map(int,input().split()))

tmp = A[0] + A[1]
red = max(0,tmp - x)
ans = red
if red > 0:
    if red <= A[1]:
        A[1] -= red
    else:
        A[0] -= red - A[1]
tmp = A[0] + A[1]


for i in range(2,N):
    tmp += A[i]
    tmp -= A[i-2]
    
    red = max(0,tmp - x)
    ans += red
    if red > 0:
        if red <= A[i]:
            A[i] -= red
        else:
            A[i-1] -= red - A[i]
    tmp = A[i-1] + A[i]   
print(ans)


Failing test case input:
6 1
2 6 1 2 0 5

Expected output:
13


Actual output:
19


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

tmp = A[0] + A[1]
red = max(0,tmp - x)
ans = red
if red > 0:
    if red <= A[1]:
        A[1] -= red
    else:
        A[0] -= red - A[1]
        A[1] = 0
tmp = A[0] + A[1]


for i in range(2,N):
    tmp += A[i]
    tmp -= A[i-2]
    
    red = max(0,tmp - x)
    ans += red
    if red > 0:
        if red <= A[i]:
            A[i] -= red
        else:
            A[i-1] -= red - A[i]
    tmp = A[i-1] + A[i]   
print(ans)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0]
for i in range(1,N):
  b.append(a[i]+a[i+1])

cnt = 0  
for i in range(1,N):
  if b[i] > x:
    c = b[i] - x
    if a[i+1] >= c:
      cnt += c
      if i+1 <= N-1:
        b[i+1] -= c
    else:
      cnt += c
print(cnt)    

Failing test case input:
3 3
4 4 2

Expected output:
5


Actual output:
8


Fixed submission (verdict: Accepted):
N,x = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0]
for i in range(1,N):
  b.append(a[i]+a[i+1])

cnt = 0  
for i in range(1,N):
  if b[i] > x:
    c = b[i] - x
    if a[i+1] >= c:
      cnt += c
      if i+1 <= N-1:
        b[i+1] -= c
    else:
      if i+1 <= N-1:
        b[i+1] -= a[i+1]
      cnt += c
print(cnt)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
iN,ix = [int(_) for _ in input().split()]
aA =[int(_) for _ in input().split()]


if ix == 0 :
    print(sum(aA))
else:
    iCount = 0
    for i in range(1,iN):
        i差 = aA[i-1] + aA[i] -ix
        if 0 < i差  :
            if aA[i] <= i差:
                aA[i] = 0
                iCount += i差
            else:
                iCount += i差
                aA[i] = i差
    print(iCount)


Failing test case input:
3 3
2 4 2

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
def 解():
    iN,ix = [int(_) for _ in input().split()]
    aA =[int(_) for _ in input().split()]

    
    if ix == 0 :
        print(sum(aA))
    else:
        iCount = 0
        for i in range(1,iN):
            i差 = aA[i-1] + aA[i] -ix
            if 0 < i差  :
                if aA[i] <= i差:
                    aA[i] = 0
                    iCount += i差
                else:
                    iCount += i差
                    aA[i] -= i差

        print(iCount)
解()
Problem: p03862
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def candy():
    boxNum, x = [int(i) for i in input().split()]
    ain = input()
    alist = ain.split(' ')

    s = 0
    for i in range(0, boxNum-1):
        if int(alist[i]) > x:
            s = s + (int(alist[i+1]) -x)
            alist[i+1] = 0

        elif int(alist[i+1]) + int(alist[i]) > x:
            s = s + (int(alist[i+1]) + int(alist[i]) - x)
            alist[i+1] = x - int(alist[i])
        
    print(s)
    
candy()

Failing test case input:
2 0
7 5

Expected output:
12


Actual output:
5


Fixed submission (verdict: Accepted):
def candy():
    n = []
    n = input().split()
    N = int(n[0])
    x = int(n[1])
    alist = [int(i) for i in input().split()]

    s = 0
    for i in range(0, N - 1):
        c = int(alist[i])
        d = int(alist[i + 1])
        if int( alist[i] + alist[i + 1] ) > x:
            if int( alist[i] ) >= x:
                alist[i] = x
                alist[i + 1] = 0
            else :
                alist[i + 1] = int(x - alist[i] )
            s += c - int(alist[i]) + d - int(alist[i + 1])
        
    print(s)
candy()

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,X = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 0
for i in range(1,N):
    if X < a[i]+a[i-1]:
        ans += a[i]+a[i-1]-X
        a[i] = X-a[i-1] if X <= a[i] else 0
print(ans)

Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
2


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

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if n==2:
    print(max(0, sum(a)-x))
    exit()
for i in range(n-1):
    s = a[i] + a[i+1]
    if s <= x:
        continue
    else:
        d = s-x
        if a[i+1] >= 1:
            if a[i+1] >= d:
                ans += d
                a[i+1] -= d
            else:
                ans += a[i+1]
                a[i+1] = 0
                ans += a[i]-(d-a[i+1])
                a[i] -= a[i]-(d-a[i+1])
        else:
            ans += d
            a[i] -= d
print(ans)



Failing test case input:
6 1
2 6 1 2 0 4

Expected output:
12


Actual output:
6


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if n==2:
    print(max(0, sum(a)-x))
    exit()
for i in range(n-1):
    s = a[i] + a[i+1]
    if s <= x:
        continue
    else:
        d = s-x
        ans += d
        if a[i+1] >= 1:
            if a[i+1] >= d:
                a[i+1] -= d
            else:
                a[i+1] = 0
                a[i] -= d-a[i+1]
        else:
            a[i] -= d
print(ans)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = max(0, a[0] - x)
for i in range(n - 1):
    if a[i] + a[i + 1] > x:
        
        diff = (a[i] + a[i + 1]) - x
        ans += diff
        a[i + 1] -= diff
    

print(ans)

Failing test case input:
6 1
2 6 1 2 0 5

Expected output:
13


Actual output:
14


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

print(ans)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int, input().split())
*A, = map(int, input().split())
ans = 0
for i in range(N-1):
    S = A[i] + A[i+1]
    if S > x:
        ans += S - x
        t = min(S, A[i+1])
        A[i+1] -= t
print(ans)

Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
*A, = map(int, input().split())
ans = max(A[0] - x, 0)
if A[0] > x: A[0] = x
for i in range(N-1):
    S = A[i] + A[i+1]
    if S > x:
        ans += S - x
        A[i+1] -= min(S - x, A[i+1])
print(ans)

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


Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
2


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

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

ans = 0
p = 0

for ai in a:
  if p + ai > x:
    d = p + ai - x
    ans += d
    p = ai - d
    
print(ans)

Failing test case input:
3 3
2 2 4

Expected output:
3


Actual output:
1


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

ans = 0
p = 0

for ai in a:
  if p + ai > x:
    d = p + ai - x
    ans += d
    p = ai - d
  else:
    p=ai
    
print(ans)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

def main():
    n, x = list(map(int, input().rstrip().split()))
    A = list(map(int, input().rstrip().split()))
    B = A
    cnt_a, cnt_b = 0, 0
    for i in range(n - 1):
        if i % 2 == 0:
            dif = min(0, x - (A[i] + A[i + 1]))
            A[i] -= dif
            cnt_a += abs(dif)
        else:
            dif = min(0, x - (B[i] + B[i - 1]))
            B[i] -= dif
            cnt_b += abs(dif)
    print(min(cnt_a, cnt_b))


if __name__ == "__main__":
    main()

Failing test case input:
2 0
1 10

Expected output:
11


Actual output:
0


Fixed submission (verdict: Accepted):

def main():
    n, x = list(map(int, input().rstrip().split()))
    A = list(map(int, input().rstrip().split()))
    ans = 0
    if A[0] > x:
        ans += A[0] - x
        A[0] = x
    for i in range(n - 1):
        dif = A[i] + A[i + 1] - x
        if dif > 0:
            A[i + 1] -= dif
            ans += dif
    print(ans)


if __name__ == "__main__":
    main()

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
l=list(map(int,input().split()))
c=0 
for i in range(n-1):
  a=l[i]
  b=l[i+1]
  if a+b<=x:
    continue
  c1=a+b-x
  c+=c1
  if b>=x:
    l[i+1]-=c1
  else:
    l[i]-=c1-b
    l[i+1]=0
print(c)

Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
l=list(map(int,input().split()))
c=0 
for i in range(n-1):
  a=l[i]
  b=l[i+1]
  if a+b<=x:
    continue
  c1=a+b-x
  c+=c1
  if b>=c1:
    l[i+1]-=c1
  else:
    l[i]-=c1-b
    l[i+1]=0
print(c)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int,input().split())
a = list(map(int,input().split()))
Nc = 0
for i in range(N):
    if a[i] > x:
        Nc = Nc + (a[i]-x)
        a[i] = x
if N>= 2:
    for i in range(1,N-1):
        Nc = Nc + max(a[i] + max(a[i-1],a[i+1]) - x, 0)
        a[i] -= max(a[i] + max(a[i-1],a[i+1]) - x, 0)
print(Nc)

Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
4


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

print(Nc)
Problem: p03862
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def resolve():
	n, x = map(int, input().split())
	a = list(map(int, input().split()))
	dp = [0]*n
	for i in range(n):
		if i != 0:
			if (a[i] + a[i-1]) > x:
				dp[i] = a[i] + a[i-1] - x
				a[i] = a[i-1] - dp[i]
		if a[0] > x:
			dp[i] = a[0] - x
			a[0] = x
	print(sum(dp))
resolve()

Failing test case input:
6 0
0 0 1 2 0 5

Expected output:
8


Actual output:
7


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

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections

N, x = map(int, input().split())
A_lis = list(map(int, input().split()))
A_q = collections.deque(A_lis)

con = 0
tmp1 = A_q.popleft()
for i in range(N-1):
    tmp2 = A_q.popleft()
    if tmp1 + tmp2 > x:
        con += (tmp1 + tmp2) - x
        tmp1 = max(0, tmp1 - x)
    else:
        tmp1 = tmp2

print(con)


Failing test case input:
3 3
2 2 4

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import collections
import sys

N, x = map(int, input().split())
A_lis = list(map(int, input().split()))
A_q = collections.deque(A_lis)

sys.setrecursionlimit(10 ** 9)

con = 0
tmp1 = A_q.popleft()
for i in range(N-1):
    tmp2 = A_q.popleft()
    if tmp1 + tmp2 > x:
        con += int((tmp1 + tmp2) - x)
        tmp1 = max(0, x - tmp1)
    else:
        tmp1 = tmp2

print(con)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x=map(int,input().split())
S = [int(i) for i in input().split()]
pre,ans = 0,0
for i in range(N):
    tmp = pre+S[i]
    if tmp > x:
        ans += tmp-x
        S[i] -= tmp-x
        pre = S[i]
print(ans)

Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
N,x=map(int,input().split())
S = [int(i) for i in input().split()]
pre,ans = 0,0
for i in range(N):
    tmp = pre+S[i]
    if tmp > x:
        ans += tmp-x
        S[i] -= tmp-x
    pre = S[i]
print(ans)

Problem: p03862
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if a[0]>x:
    ans = x-a[0]
    a[0]=x
for i in range(n-1):
    b = a[i]+a[i+1]
    if b<=x:
        continue
    else:
        sub = b-x
        a[i+1] = a[i+1]-sub
        ans+=sub
print(ans)

Failing test case input:
2 0
2 0

Expected output:
2


Actual output:
-2


Fixed submission (verdict: Accepted):
n,x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if a[0]>x:
    ans = a[0]-x
    a[0]=x
for i in range(n-1):
    b = a[i]+a[i+1]
    if b<=x:
        continue
    else:
        sub = b-x
        a[i+1] = a[i+1]-sub
        ans+=sub
print(ans)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,X = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
if X == 0:
  print(sum(A))
else:
  for i in range(N-1):
    if A[i] + A[i+1] >=X:
      if A[i] > A[i+1]:
        ans += (A[i] + A[i+1] - X)
        A[i] -= (A[i] + A[i+1] - X)
      else:
        ans += (A[i] + A[i+1] - X)
        A[i+1] -= (A[i] + A[i+1] - X)
  print(ans)
  

Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
12


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

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

Failing test case input:
6 1
2 6 1 2 0 5

Expected output:
13


Actual output:
14


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
arr = list(map(int, input().split()))
s = sum(arr)
for i in range(1,N):
    if arr[i-1] + arr[i] >= x:
        if arr[i-1] <= x:
            arr[i] -= (arr[i] + arr[i-1]) - x
        else:
            arr[i] = 0
            if x-arr[i-1] > 0:
                arr[i-1] -= x-arr[i-1]
            else:
                arr[i-1] -= arr[i-1]-x
print(s-sum(arr))

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int, input().split())
As = list(map(int, input().split()))
r = 0
a = As[0]
if a > x:
  r += a-x
  p = x
else:
  p = a
for i in range(1, N):
  a = As[i]
  if p+a > x:
    r += p+a-x
    p = x-a
  else:
    p = a
print(r)


Failing test case input:
6 0
0 0 1 2 0 5

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
As = list(map(int, input().split()))
r = 0
a = As[0]
if a > x:
  r += a-x
  p = x
else:
  p = a

for i in range(1, N):
  a = As[i]
  if p+a > x:
    r += p+a-x
    p = a-(p+a-x)
  else:
    p = a
  
print(r)
Problem: p03862
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, x = map(int, input().split())
a = list(map(int, input().split()))
 
ans = 0
for i in range(-2, N - 2):
    
    count = a[i+1] + a[i+2] - x
    if count <= 0:
        continue
    
    ans += count
    
    
    if count < a[i+2]:
        a[i+2] -= count
        
    
    else:
        a[i+1] = a[i+1] - count + a[i+2]  
        a[i+2] = 0
    
print(ans)

Failing test case input:
5 9
6 1 4 2 5

Expected output:
0


Actual output:
2


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

ans = 0
for i in range(-1, N - 2):
    
    count = a[i + 1] + a[i + 2] - x
    if count <= 0:
        continue

    ans += count

    
    if count < a[i + 2]:
        a[i + 2] -= count

    
    else:
        a[i + 1] = a[i + 1] - count + a[i + 2]
        a[i + 2] = 0

print(ans)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
a = list(map(int, input().split()))
num = len(a)


ans = 0

for i in range(num - 1):
    tar = a[i] + a[i + 1]
    if (tar <= x):
        continue
    else:
        dif = tar - x
        if (a[i + 1] >= dif):
            ans += dif
            a[i + 1] -= dif

        else:
            ans += a[i + 1]

            a[i + 1] = 0
            dif -= a[i + 1]
            a[i] -= dif
            ans += dif


print(ans)


Failing test case input:
2 0
5 9

Expected output:
14


Actual output:
23


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


ans = 0

for i in range(num - 1):
    tar = a[i] + a[i + 1]
    if (tar <= x):
        continue
    else:
        dif = tar - x
        if (a[i + 1] >= dif):
            ans += dif
            a[i + 1] -= dif

        else:
            ans += a[i + 1]
            dif -= a[i + 1]
            a[i + 1] = 0

            a[i] -= dif
            ans += dif


print(ans)

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





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




r = 0
flow = 0

for i in range(1, N):
    t = (a[i] + a[i - 1]) - x
    if flow != 0:
        if t > 0:
            r += min(flow, t)
            flow = abs(t - min(flow, a[i-1]))
        else:
            r += flow
            flow = 0
    elif t > 0:
        flow = t

r += flow

print(r)

Failing test case input:
3 3
4 4 2

Expected output:
5


Actual output:
4


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

r1 = sum(a)
flow = 0

for i in range(1, N):
    t = (a[i] + a[i - 1]) - x
    if flow != 0:
        a[i-1] -= flow
        t -= flow
        flow = 0

    if t > 0:
        if t > a[i]:
            t -= a[i]
            a[i - 1] -= t
            t = a[i]

        flow = t

a[-1] -= flow

r2 = sum(a)

print(r1 - r2)
Problem: p03862
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,x=map(int,input().split())
A=list(map(int,input().split()))
ans=0
if A[0]>x:
  ans+=A[0]-x
  A[0]=x

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

print(ans)

Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
5


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

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

r = 0
for i in range(1, n):
  if a[i] + a[i-1] > x:
    r += abs(a[i]+a[i-1] - x)
  a[i] = a[i] - r  
  if a[i] < 0:
    a[i-1] += a[i]
    a[i] = 0
    
print(r)

Failing test case input:
6 1
1 6 1 2 0 4

Expected output:
11

Actual output:
10


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

if a[0] > x:
  a[0] = x
for i in range(n - 1):
  if a[i] + a[i+1] > x:
    a[i+1] += x - (a[i] + a[i+1])
r = sum_a - sum(a)
    
print(r)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n, x, *a = map(int, open(0).read().split())

    ans = 0
    tmp = 0
    for i, j in zip(a, a[1:]):
        i -= tmp
        if i + j > x:
            c = (i + j) - x
            ans += 1
            tmp = c
        else:
            tmp = 0

    print(ans)


if __name__ == '__main__':
    main()


Failing test case input:
6 1
2 6 1 2 0 4

Expected output:
12


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    n, x, *a = map(int, open(0).read().split())
    a = [0] + a
    ans = 0
    tmp = 0
    for i, j in zip(a, a[1:]):
        i -= tmp
        if i + j > x:
            c = (i + j) - x
            ans += c
            tmp = c
        else:
            tmp = 0

    print(ans)


if __name__ == '__main__':
    main()

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
A = [int(i) for i in input().split()]
if A[0] > x:
    A[0] = x
cnt = A[0] - x
for i in range(n - 1):
    if A[i] + A[i + 1] > x:
        cnt += (A[i] + A[i + 1]) - x
        A[i + 1] -= (A[i] + A[i + 1]) - x
print(cnt)

Failing test case input:
-4 58
10 1 2 6 3

Expected output:
0


Actual output:
-48


Fixed submission (verdict: Accepted):
n, x = map(int, input().split())
A = [int(i) for i in input().split()]

cnt = 0
if A[0] > x:
    cnt += A[0] - x
    A[0] = x

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

print(cnt)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,x = map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    a[0]=x
    ans+=a[0]-x
for i in range(len(a)-1):
    if a[i]+a[i+1]>x:  
        b=a[i+1]-x+a[i]
        a[i+1]=x-a[i]
        ans+=b
print(ans)


Failing test case input:
2 0
1 9

Expected output:
10


Actual output:
9


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

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

ans=0

if A[0] > x:
    ans += A[0]-x
    A[0]=x

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

print(ans)

Failing test case input:
5 5
5 1 4 1 5

Expected output:
2


Actual output:
5


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

ans=0

if A[0] > x:
    ans += A[0]-x
    A[0]=x

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

print(ans)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, x = map(int, input().split())
nums = list(map(int, input().split()))
before = nums[0]
cnt = 0
for i in range(1, N):
  ope = before+nums[i]-x
  if ope > 0:
    before = max(nums[i]-ope, 0)
    cnt += ope
print(cnt)

Failing test case input:
5 9
6 2 4 2 5

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
nums = list(map(int, input().split()))
before = nums[0]
cnt = 0
for i in range(1, N):
  ope = before+nums[i]-x
  if ope > 0:
    before = max(nums[i]-ope, 0)
    cnt += ope
  else:
    before = nums[i]
print(cnt)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x = list(map(int,input().split()))
a=list(map(int,input().split()))

eat=0

if a[0]>x:
  eat+=a[0]-x
  a[0]=x

if a[N-1]>x:
  eat+=a[N-1]-x
  a[N-1]=x
  
for i in range(N-2):
  if a[i]+a[i+1]>x:
    eat+=a[i+1]-x+a[i]
    a[i+1]=x-a[i]
    
print(eat)

Failing test case input:
5 5
5 1 4 1 5

Expected output:
2


Actual output:
1


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

eat=0

if a[0]>x:
  eat+=a[0]-x
  a[0]=x

if a[N-1]>x:
  eat+=a[N-1]-x
  a[N-1]=x
  
for i in range(N-1):
  if a[i]+a[i+1]>x:
    eat+=a[i+1]-x+a[i]
    a[i+1]=x-a[i]
    
print(eat)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,x=map(int,input().split())
A=list(map(int,input().split()))

s=0
if(A[0]>N):
    s+=A[0]-N
    A[0]=N

for i in range(N-1):
    if(A[i+1]>N):
        s+=A[i+1]-N
        A[i+1]=N
    if(A[i]+A[i+1]>N):
        t=A[i]+A[i+1]-N
        s+=t
        A[i+1]-=t

print(s)

Failing test case input:
-2 124
4 2 4 3 3

Expected output:
0


Actual output:
6


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

s=0
if(A[0]>x):
    s+=A[0]-x
    A[0]=x

for i in range(N-1):
    if(A[i+1]>x):
        s+=A[i+1]-x
        A[i+1]=x
    if(A[i]+A[i+1]>x):
        t=A[i]+A[i+1]-x
        s+=t
        A[i+1]-=t

print(s)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

N,x = map(int,input().split())
a = [int(i) for i in input().split()]
part_sum = [0 for i in range(N)]
tmp = 0
for i in range(N):
    tmp += a[i]
    part_sum[i] = tmp

window = [0 for i in range(N-1)]
for i in range(N-1):
    window[i] = a[i]+a[i+1]

ans = 0
cnt = 0
for i in range(N-1):
    if window[i]-cnt > x:
        ans += window[i]-x
        cnt = window[i]-x
    else:
        cnt = 0
print(ans)




Failing test case input:
5 5
5 1 4 2 5

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

N,x = map(int,input().split())
a = [int(i) for i in input().split()]
part_sum = [0 for i in range(N)]

ans = 0
if a[0] > x:
    ans += a[0]-x
    a[0] = x
left = a[0]
for i in range(1,N):
    if left + a[i] > x:
        ans += left + a[i] - x
        a[i] = x - left
    left = a[i]


print(ans)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
count = 0
if a[0] > x:
        count += x - a[0]
        a[0] = x
for i in range(1, n):
        t = a[i-1] + a[i]
        if t > x:
                count += t - x
                a[i] = a[i] - (t - x)
print(count)

Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
-1


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