ZhenlongDai/ACPR huggingface dataset:
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys


Nx = input().split()
an = input().split()

anx = list()

for item in an:
    anx.append(int(item))

x = int(Nx[1])
N = int(Nx[0])
i = 0
count = 0
while i < N - 1:
    sum = anx[i] + anx[i + 1]
    
    if sum > x:
        count+= sum - x
        num = sum - x
        anxi = anx[i]
        anxi -= num
        if anxi < 0:
            anxi2 = anx[i + 1] + anxi
            anx[i+1] = anxi2
            anxi = 0
        anx[i] = anxi
    i += 1
print(count)


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

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import sys


Nx = input().split()
an = input().split()

anx = list()

for item in an:
    anx.append(int(item))

x = int(Nx[1])
N = int(Nx[0])
i = 0
count = 0
while i < N - 1:
    sum = anx[i] + anx[i + 1]
    
    if sum > x:
        count += sum - x
        num = sum - x
        anxi = anx[i+1]
        anxi -= num
        if anxi < 0:
            anxi2 = anx[i] + anxi
            anx[i] = anxi2
            anxi = 0
        anx[i+1] = anxi
    i += 1
print(count)

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

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

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
def inpl(): return input().split()
n, x = map(int, inpl())
a = list(map(int, inpl()))
ans = 0
if a[0] > x:
    ans += a[0] - x
    a[0] = x        
for i in range(1, n):
    if (a[i-1] + a[i]) > x:
        ans += (a[i-1] + a[i]) - x
        a[i] = 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()))
b=[]
for i in range(1,n):
  b.append(max(0,a[i]+a[i-1]-x))
print(sum(b))
  

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

Expected output:
11

Actual output:
18


Fixed submission (verdict: Accepted):
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
  k=max(0,a[i]+a[i-1]-x)
  ans+=k
  a[i]=max(0,a[i]-k)
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()))
import copy
tmpa = copy.deepcopy(a)

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

ans = 0
for i in range(N):
    ans += abs(a[i] - tmpa[i])
print(ans)


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

Expected output:
13


Actual output:
16


Fixed submission (verdict: Accepted):
N,x = map(int,input().split())
a = [0] + list(map(int,input().split()))
import copy
tmpa = copy.deepcopy(a)

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

ans = 0
for i in range(N+1):
    ans += abs(a[i] - tmpa[i])
print(ans)

Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
N,x = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
ans = 0
for i in range(0,N-1):
    l = As[i]
    r = As[i+1]
    diff = (r+l) - x
    if diff >= r:
        ans += r

        diff -= r
        As[i + 1] = r = 0
        ans += diff

    else:
        r -= diff
        As[i + 1] = r
        ans += diff

print(max(ans,0))






Failing test case input:
3 3
4 4 2

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
import itertools
N,x = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
ans = 0
for i in range(0,N-1):
    l = As[i]
    r = As[i+1]
    diff = max((r+l) - x,0)
    if diff >= r:
        ans += r

        diff -= r
        As[i + 1] = r = 0
        ans += diff

    else:
        r -= diff
        As[i + 1] = r
        ans += 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()))

ans = 0
for i in range(N-1):
  diff = A[i] + A[i+1] - x
  if diff > 0:
    if diff <= A[i+1]:
      A[i+1] -= diff
    else:
      A[i] -= diff - A[i+1]
      A[i] = 0
    ans += diff
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()))
sumA = sum(A)
for i in range(1,N):
  diff = A[i] + A[i-1] - x
  if diff > 0:
    if diff <= A[i]:
      A[i] -= diff
    else:
      A[i-1] -= diff - A[i]
      A[i] = 0
print(sumA - sum(A))

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+=x-a[0]
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
4 0

Expected output:
4


Actual output:
0


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
for i in range(1,n):
    if a[i-1]+a[i]>x:
        ans+=a[i]+a[i-1]-x
        if a[i]<x:
            a[i]=0
        else:
            a[i]=x-a[i-1]









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=list(map(int,input().split()))
ans=0
for i in range(1,n):
    if a[i-1]+a[i]>x:
        ans+=a[i]+a[i-1]-x
        if x<a[i-1]:
            a[i]=0
        else:
            a[i]=x-a[i-1]
print(ans)

Problem: p03862
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

n, x = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
for i in range(n-1):
    s = A[i+1] + A[i]
    if s > x:
        A[i] -= s - x
print(S - sum(A))

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

Expected output:
12


Actual output:
19


Fixed submission (verdict: Accepted):

n, x = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
if A[0] > x:
    A[0] = x
for i in range(n-1):
    s = A[i+1] + A[i]
    if s > x:
        A[i+1] -= s - x
print(S - sum(A))

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 += 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:
3 3
8 4 2

Expected output:
9


Actual output:
7


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 (Python (3.8.2), verdict: Wrong Answer):
N, x = map(int, input().split())
a = list(map(int, input().split()))

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

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

print(Sum)



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()))

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

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


Failing test case input:
2 0
4 0

Expected output:
4


Actual output:
8


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

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:
            a[i + 1] = 0
            dif -= a[i + 1]
            a[i] -= dif


print(ans)


Failing test case input:
2 0
7 5

Expected output:
12


Actual output:
0


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.4.3), verdict: Wrong Answer):
n,x=map(int,input().split())
a=list(map(int,input().split()))
eat=0
for i in range(1,n):
  s=a[i-1]+a[i]-x
  if(x>0):
    eat+=s
    a[i]-=s
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=map(int,input().split())
a=list(map(int,input().split()))
eat=0
for i in range(1,n):
  s=a[i-1]+a[i]-x
  if(s>0):
    eat+=min(s,a[i])
    a[i]-=min(s,a[i])
s=a[1]+a[0]-x
eat+=max(s,0)
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()))

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:
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()))
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 = [int(x) for x in input().split()]

D = [0]*N
answer = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        d = A[i] + A[i+1] - x
        e = max(A[i+1], d)
        answer += e
        A[i+1] -= e
        d -= e
        if d > 0:
            A[i] -= d
            answer += d
print(answer) 



















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 = [int(x) for x in input().split()]

D = [0]*N
answer = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        d = A[i] + A[i+1] - x
        e = min(A[i+1], d)
        answer += e
        A[i+1] -= e
        d -= e
        if d > 0:
            A[i] -= d
            answer += d
print(answer)

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

import math
N, x = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
for tmp in range (0,N-1):
    if a[tmp] + a[tmp+1] <= x:
        continue
    else:
        tmp2 = (a[tmp]+a[tmp+1]) - x 
        if a[tmp+1] >= a[tmp]:
            if a[tmp+1] - tmp2 >= 0:
                a[tmp+1] -= tmp2
                ans += tmp2
            else: 
                ans += tmp2
                a[tmp] += a[tmp+1] - tmp2 
                tmp2 += a[tmp+1] - tmp2
                a[tmp+1] -= tmp2
print(ans)

Failing test case input:
2 0
2 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):

import math
N, x = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
for tmp in range (0,N-1):
    if a[tmp] + a[tmp+1] <= x:
        continue
    else:
        tmp2 = (a[tmp]+a[tmp+1]) - x 
        if a[tmp+1] - tmp2 >= 0:
            a[tmp+1] -= tmp2
            ans += tmp2
        else: 
            ans += tmp2
            a[tmp] += a[tmp+1] - tmp2 
            tmp2 += a[tmp+1] - tmp2
            a[tmp+1] -= tmp2
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()))
count=0
for i in range(1,n):
    if a[i-1]<0:
        a[i-1]=0
    b=a[i-1]+a[i]
    if b>x:
        a[i]-=b-x
        count+=b-x
print(count)
print(a)

Failing test case input:
3 3
2 2 4

Expected output:
3


Actual output:
3
[2, 1, 2]


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-1]<0:
        a[i-1]=0
    b=a[i-1]+a[i]
    if b>x:
        a[i]-=b-x
        count+=b-x
print(count)
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()]
b=c=0
if a[0]<=x:
  c=0;b=a[0]
else:
  c=a[0]-x;b=x
for i in range(1,len(a)):
  if b+a[i]>x:
    c+=(a[i]+b-x)
    b=b-x
  else:
    b=a[i]
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())
a=[int(i)for i in input().split()]
c=0
if a[0]>x:
  c=a[0]-x
  a[0]=x
for i in range(n-1):
  if a[i]+a[i+1]>x:
    c+=a[i]+a[i+1]-x
    a[i+1]=x-a[i]
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()))
d = []
for i in range(n-1):
  d.append(a[i] + a[i+1])
ans = 0
for i in range(n-1):
  now = d[i] - x
  if now > 0:
    ans += now
    d[i] -= now
    d[i-1] -= now
print(ans)

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

Expected output:
12


Actual output:
16


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

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

D = [0]*N
for i in range(N-1):
    D[i] = max(A[i] + A[i+1] - x, 0)

answer = 0
for i in range(N-1):
    if D[i] > 0:
        if D[i+1] > 0:
            
            e = max(D[i], A[i+1])
            D[i+1] -= e
            D[i] -= e
            A[i+1] -= e
            answer += e
        e = D[i]
        D[i] -= e
        answer += e
        A[i] -= e
print(answer) 



















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 = [int(x) for x in input().split()]

D = [0]*N
answer = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        d = A[i] + A[i+1] - x
        e = min(A[i+1], d)
        answer += e
        A[i+1] -= e
        d -= e
        if d > 0:
            A[i] -= d
            answer += d
print(answer)

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

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

Failing test case input:
2 0
5 9

Expected output:
14


Actual output:
9


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

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

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

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
N,x=map(int,input().split())
a=[int(x) for x 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]=x-a[i]
print(cnt)

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

if alist[0] > x:
    alist[0] -= (alist[0] - x)

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

print(ans)

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())
alist = list(map(int,input().split()))
ans = 0

if alist[0] > x:
    ans += (alist[0] - x)
    alist[0] -= (alist[0] - x)

for al in range(1,N):
    if (alist[al-1]+alist[al]) > x:
        ans += (alist[al-1]+alist[al]) - x
        alist[al] -= (alist[al-1]+alist[al]) - 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()))
cnt = 0

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

for a in A[1:]:
  if _a + a > x:
    dif = _a + a - x
    cnt += dif
    _a = a - dif
  
print(cnt)

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

Expected output:
0


Actual output:
1


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

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

for a in A[1:]:
    if _a + a > x:
        dif = _a + a - x
        cnt += dif
        _a = a - dif
    else:
        _a = a

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()))
cnt = 0

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

for a in A:
  if _a + a > x:
    dif = _a + a - x
    cnt += dif
    _a = a - dif
  
print(cnt)

Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
18


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

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

for a in A[1:]:
    if _a + a > x:
        dif = _a + a - x
        cnt += dif
        _a = a - dif
    else:
        _a = a

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

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

Expected output:
11

Actual output:
18


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

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(n):
    if a[i] >= x:
        ans += a[i]-x
        a[i] = x
for j in range(n-1):
    if a[j] + a[j+1] > x:
        ans += a[j+1] - (x - a[j])
        a[j+1] = x - a[j] - a[j+1]
print(ans)


Failing test case input:
3 3
2 2 4

Expected output:
3


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(n):
    if a[i] >= x:
        ans += a[i]-x
        a[i] = x
for j in range(n-1):
    if a[j] + a[j+1] >= x:
        d = a[j]+ a[j+1] - x
        ans += d
        a[j+1] -= d
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
for i in range(n):
    if a[i] + a[i - 1] > x:
        
        v = a[i] + a[i - 1] - x
        ans += v
        if i == n - 1:
            a[n - 1] -= v
        else:
            
            if a[i] - v >= 0:
                a[i] -= v
            else:
                
                a[i-1] -= v - a[i]
                a[i] = 0
print(ans)

Failing test case input:
3 3
2 4 2

Expected output:
3


Actual output:
4


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

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

        else:
            A[i+1] = 0

print(ans)


Failing test case input:
3 3
2 2 4

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
A = [int(x) for x in 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:
            A[i+1] = 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()))
A.append(0)
CA = [a for a in A]
for i in range(N):
    total = CA[i] + CA[i+1]
    if x < total:
        if CA[i + 1] <= (total - x):
            rest = total - x - CA[i + 1]
            CA[i + 1] = 0
            CA[i] = CA[i] - rest if CA[i] - rest > 0 else 0
        else:
            CA[i + 1] = total - x
cnt = 0
for a, ca in zip(A, CA):
    cnt += (a - ca)
print(cnt)


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

Expected output:
3


Actual output:
6


Fixed submission (verdict: Accepted):
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.append(0)
CA = [a for a in A]
for i in range(N):
    total = CA[i] + CA[i+1]
    if x < total:
        if CA[i + 1] <= (total - x):
            rest = total - x - CA[i + 1]
            CA[i + 1] = 0
            CA[i] -= rest
        else:
            CA[i + 1] -= total - x


cnt = 0
for a, ca in zip(A, CA):
    cnt += (a - ca)
print(cnt)
Problem: p03862
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, x: int, a: "List[int]"):
    ret = 0
    for i in range(1, N):
        if a[i] + a[i - 1] > x:
            ret += (a[i] + a[i - 1]) - x
            tmp = min(ret, a[i])
            a[i] -= tmp
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, x, a)

if __name__ == '__main__':
    main()


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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, x: int, a: "List[int]"):
    ret = 0
    for i in range(1, N):
        if a[i] + a[i - 1] > x:
            hoge = (a[i] + a[i - 1]) - x
            ret += hoge
            tmp = min(hoge, a[i])
            a[i] -= tmp
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, x, a)

if __name__ == '__main__':
    main()

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
  before = max(nums[i]-ope, 0)
  cnt += ope
print(cnt)

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

Expected output:
0


Actual output:
-6


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):
import sys
stdin = sys.stdin
from itertools import product

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, x = na()
a = na()
b = list()

apre = a[0]
ans = 0
for ai in a:
    eat = max(0, apre + ai - x)
    ans += eat
    apre = ai - eat
print(ans)

Failing test case input:
0 9
7 1 4 1 4

Expected output:
0


Actual output:
5


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
from itertools import product

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, x = na()
a = na()
apre = 0
ans = 0
for ai in a:
    eat = max(0, apre + ai - x)
    ans += eat
    apre = ai - eat
print(ans)
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

    if int(alist[0]) > x:
        s = x - int(alist[0])
        alist[0] = x

    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])
        
    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):

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 and a[i + 1] >= 1: 
        ans += min(a[i] + a[i + 1] - x, a[i + 1])
        a[i + 1] -= min(x, a[i + 1])
    if a[i] + a[i + 1] > x: 
        ans += a[i] + a[i + 1] - x
        a[i] -= x
print(ans)

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

Expected output:
13


Actual output:
25


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 and a[i + 1] >= 1: 
        ans += min(a[i] + a[i + 1] - x, a[i + 1])
        a[i + 1] -= min(a[i] + a[i + 1] - x, a[i + 1])
    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,k=map(int,input().split())
l=[int(i) for i in input().split()]
sm=0 
for i in range(n-1):
    if l[i]+l[i+1]<=k:
        continue 
    else: 
        sm+=l[i]+l[i+1]-k 
        req=l[i]+l[i+1]-k 
        if l[i+1]>=sm: 
            l[i+1]-=sm 
            req=0 
        else: 
            
            req-=l[i+1]
            l[i]-=req
            l[i+1]=0

print(sm)

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
sm=0 
for i in range(n-1):
    if l[i]+l[i+1]<=k:
        continue 
    else: 
        sm+=l[i]+l[i+1]-k 
        req=l[i]+l[i+1]-k 
        if l[i+1]>=req: 
            l[i+1]-=req 
            req=0 
        else: 
            
            req-=l[i+1]
            l[i]-=req
            l[i+1]=0
print(sm)
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:
        eat=A[i+1]+A[i]-x
        A[i+1]=max(A[i+1],A[i])-eat
        ans+=eat
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()))+[0]
ans=0
for i in range(N):
    eated=max(0,A[i]+A[i-1]-x)
    ans+=eated
    A[i]-=eated
print(ans)

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

if a[0] > x:
    a[0] = x

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

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

Expected output:
12


Actual output:
11


Fixed submission (verdict: Accepted):
N, x, *a = map(int, open(0).read().split())
ans = 0

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

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

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

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

c = 0
p = 0
if a[0] > g:
    c += a[0] - g
    a[0] = g
while p <= f-1:
    if a[p-1] + a[p] > g:
        eat = a[p-1] + a[p] - g
        c += eat
        a[p] -= eat
    p += 1
print(c)


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

Expected output:
13


Actual output:
16


Fixed submission (verdict: Accepted):
f,g = list(map(int,input().split()))

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

c = 0
p = 1
if a[0] > g:
    c += a[0] - g
    a[0] = g
while p <= f-1:
    if a[p-1] + a[p] > g:
        eat = a[p-1] + a[p] - g
        c += eat
        a[p] -= eat
    p += 1
print(c)

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(len(a)):
    if a[i] > x:
        cnt += a[i]-x
        a[i] = x

for i in range(1, len(a)):
    if a[i-1] + a[i] > x:
        cnt += abs(a[i]-x)

print(cnt)


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

Expected output:
3


Actual output:
7


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

cnt = 0
for i in range(len(a)):
    if a[i] > x:
        cnt += a[i]-x
        a[i] = x

for i in range(1, len(a)):
    if a[i-1] + a[i] > x:
        cnt += a[i-1]+a[i] - x
        a[i] = a[i] - (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()))

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

Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
4


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

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

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


if __name__ == "__main__":
    resolve()


Failing test case input:
2 0
4 0

Expected output:
4


Actual output:
0


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


if __name__ == "__main__":
    resolve()

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

count = 0

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

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()))

count = 0

for i in range(n-1):
    if a[i] > x:
        count += a[i] - x
        a[i] = x
        
        count += a[i+1]
        a[i+1] = 0
        
    elif a[i]+a[i+1] > x:
        count = count + a[i+1] + a[i] - x
        a[i+1] = x - a[i] 
    
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
prev = A[0]
for i in A[1:]:
    if prev + i > x:
        tmp = prev + i - x
        ans += tmp
        prev = -tmp
    else:
        prev = i
print(ans)

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())
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( ))
a = list(map(int, input().split( )))
a.append(0)
cnt = 0
for i in range(n):
    if a[i]>x:
        cnt += a[i]-x
        a[i]=x 
    else:
        cnt += max(a[i]+a[i+1]-x,0)
        a[i+1] -= max(a[i]+a[i+1]-x,0)
print(cnt)


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

Expected output:
13


Actual output:
12


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

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


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 = [int(i) for i in input().split()]
op = 0
for i in range(1, n):
    s = a[i-1] + a[i]
    if s > x:
        op += s - x
        if a[i] < s - x:
            a[i] = 0
        else:
            a[i] -= s - x
print(op)

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()]
b=c=0
if a[0]<x:
  c=0;b=a[0]
else:
  c=a[0]-x;b=x
for i in range(1,len(a)):
  if b+a[i]>x:
    c+=(a[i]+b-x)
    b=b-x
  else:
    b=a[i]
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())
a=[int(i)for i in input().split()]
c=0
if a[0]>x:
  c=a[0]-x
  a[0]=x
for i in range(n-1):
  if a[i]+a[i+1]>x:
    c+=a[i]+a[i+1]-x
    a[i+1]=x-a[i]
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()))
s = 0
for i in range(n-1):
  while a[i] + a[i+1] > x:
    if a[i] > x:
      s += a[i]
      a[i] = 0
    else:
      t = x - a[i]
      s += a[i+1] - t
      a[i+1] = t
print(s)


Failing test case input:
3 3
4 4 2

Expected output:
5


Actual output:
7


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] + a[i+1] > x:
        s += (a[i] + a[i+1]) - x
        a[i+1] = x - a[i]

print(s)
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])
        A[i+1] -= S - 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 (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    ans+=a[0]-x
for i in range(1,n):
    if a[i]+a[i-1]>x:
        ans+=a[i]-(x-a[i-1])
        a[i]=x-a[i-1]

print(ans)


Failing test case input:
2 0
1 0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
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]-(x-a[i-1])
        a[i]=x-a[i-1]

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(' ')))
wa = [a[0]]+[a[i]+a[i+1] for i in range(N-1)]+[a[-1]]
ans = 0

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

print(ans)

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

Expected output:
0

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


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

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

if wa[-1] > x:
    ans += wa[-1]-x
    a[-1] = wa[-1]-x
    wa[-1] -= wa[-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()))
ans=0
if a[0]>x:
    ans+=x-a[0]
    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]=x-a[i-1]
print(ans)

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

Expected output:
12


Actual output:
10


Fixed submission (verdict: Accepted):
n,x=map(int, input().split())
a=list(map(int, input().split()))
b=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]
ans=0
for i in range(n):
    ans+=b[i]-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

for i in range(n-1):
    overflow = a[i]+a[i+1]-x
    ans += overflow
    if a[i+1]>= overflow:
        a[i+1] -= overflow
    else:

        a[i] -= overflow -a[i+1]
        a[i+1]=0
 
print(ans)

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

Expected output:
0


Actual output:
-6


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

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

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()]
b=a[0]
c=0
for i in range(1,len(a)):
  if b+a[i]>x:
    c+=(b+a[i]-x)
    b=b-x
  else:
    b=a[i]
print(c)

Failing test case input:
3 3
8 4 2

Expected output:
9


Actual output:
13


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

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

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

print(result, a)

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

Expected output:
0


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


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

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

print(result)

Problem: p03862
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n , x= map(int , input().split())
arr = list(map(int , input().split()))
ans = []
tot=0
for i in range(1,n):
	if arr[i]+arr[i-1]>x:
		tot = tot+((arr[i]+arr[i-1])-x)
		arr[i]=arr[i]-(arr[i]+arr[i-1])-x
print(tot)

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())
arr = list(map(int , input().split()))
ans = []
tot=0
if arr[0]>x:
	tot = tot+(arr[0]-x)
	arr[0]=x
for i in range(1,n):
	if arr[i]+arr[i-1]>x:
		dif = ((arr[i]+arr[i-1])-x)
		tot = tot+dif
		if arr[i]-dif>=0:
			arr[i]=arr[i]-dif
		else:
			arr[i-1]=arr[i-1]-dif
print(tot)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range(N):
  ans=num_list[N-1]+i+1-num_list[0]
  ans_list.append(ans)
print(min(ans_list))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range (N):
  if i==0:
    ans=num_list[N-1]-num_list[i]
    ans_list.append(ans)
  else:
    ans=num_list[N-1]-num_list[i]+i-num_list[i-1]
    ans_list.append(ans)

print(min(ans_list))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = list(input())
answer = n
left_count = 0
right_count = s.count('E')
for i in range(n):
  if i != 0 and s[i-1] == 'W':
    left_count += 1
    if s[i] == 'E':
      right_count -= 1
      total = left_count + right_count
      answer = min(answer, total)
print(answer)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = list(input())
answer = n
left_count = 0
right_count = s.count('E')
for i in range(n):
  if i != 0 and s[i-1] == 'W':
    left_count += 1
  if s[i] == 'E':
    right_count -= 1
  total = left_count + right_count
  answer = min(answer, total)
print(answer)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
t=s.count('E')
ans=10**6
e=0
w=0
for i in range(n):
  if s[i]=='E':
    e+=1
    ans=min(ans,t-e+w-1)
  elif s[i]=='W':
    w+=1
    ans=min(ans,t-e+w-1)
print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
t=s.count('E')
ans=10**9
e=0
w=0
for i in range(n):
  if s[i]=='E':
    e+=1
    ans=min(ans,t-e+w)
  elif s[i]=='W':
    w+=1
    ans=min(ans,t-e+w-1)
print(ans)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    people_num = int(input())
    directions = input()
    east_direction = [0]
    for i in range(people_num):
        if directions[i] == "E":
            east_direction.append(east_direction[i] + 1)
        else:
            east_direction.append(east_direction[i])
    answer = float("inf")
    print(east_direction)
    for i in range(1, people_num + 1):
        change_to_east = i - 1 - east_direction[i - 1]
        change_to_west = east_direction[-1] - east_direction[i]
        answer = min(answer, change_to_east + change_to_west)
    print(answer)


if __name__ == '__main__':
    main()

Failing test case input:
5
WEEWW

Expected output:
1

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


Fixed submission (verdict: Accepted):
def main():
    people_num = int(input())
    directions = input()
    east_direction = [0]
    for i in range(people_num):
        if directions[i] == "E":
            east_direction.append(east_direction[i] + 1)
        else:
            east_direction.append(east_direction[i])
    answer = float("inf")
    for i in range(1, people_num + 1):
        change_to_east = i - 1 - east_direction[i - 1]
        change_to_west = east_direction[-1] - east_direction[i]
        answer = min(answer, change_to_east + change_to_west)
    print(answer)


if __name__ == '__main__':
    main()

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
s1 = S[1:]
b = []
b.append(s1.count('E'))
j = 1
while j < N:
  b.append(0)
  b[j] = b[j-1]
  if S[j] == 'E':
    b[j] += -1
  if S[j-1] == 'W':
    b[j] += 1
  j += 1
print(b)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[2, 2, 1, 1, 2]


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
s1 = S[1:]
b = []
b.append(s1.count('E'))
j = 1
while j < N:
  b.append(0)
  b[j] = b[j-1]
  if S[j] == 'E':
    b[j] += -1
  if S[j-1] == 'W':
    b[j] += 1
  j += 1
print(min(b))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
cnt = S.count('E',1,N)
ans = [cnt]

for i in range(1,N):
    if S[i-1] == 'W':cnt += 1
    if S[i] == 'E': cnt -=1
    ans.append(cnt)
print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[2, 2, 1, 1, 2]


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
cnt = S.count('E',1,N)
ans = [cnt]

for i in range(1,N):
    if S[i-1] == 'W':cnt += 1
    if S[i] == 'E': cnt -=1
    ans.append(cnt)
print(min(ans))