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

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

cou = 0

if lis[0] > x:

  cou += (lis[0] - x)

  lis[0] -= (lis[0] -x)

for i in range(n-1):

  if lis[i+1] + lis[i] > x:

    cou += (lis[i+1] + lis[i] -x)

    lis[i+1] -= (lis[i+1] + lis[i] -x)

print(cou)
n,k = list(map(int,input().split()))

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

cou = lis[0]

ans = 0

if cou > k:

    ans += cou-k

    cou = k

for i in range(1,n):

    if cou + lis[i] > k:

        num = cou+lis[i]-k

        cou = lis[i]-num

        ans += num

    else:

        cou = lis[i]

print(ans)
n, x = list(map(int, input().split()))
lis = list(map(int, input().split()))
cou = 0
if lis[0] > x:
    cou += lis[0] - x
    lis[0] -= lis[0] - x
for i in range(n - 1):
    if lis[i + 1] + lis[i] > x:
        cou += lis[i + 1] + lis[i] - x
        lis[i + 1] -= lis[i + 1] + lis[i] - x
print(cou)

n, k = list(map(int, input().split()))
lis = list(map(int, input().split()))
cou = lis[0]
ans = 0
if cou > k:
    ans += cou - k
    cou = k
for i in range(1, n):
    if cou + lis[i] > k:
        num = cou + lis[i] - k
        cou = lis[i] - num
        ans += num
    else:
        cou = lis[i]
print(ans)

-n, x = list(map(int, input().split())) +n, k = list(map(int, input().split())) -cou = 0 -if lis[0] > x: -    cou += lis[0] - x -    lis[0] -= lis[0] - x -for i in range(n - 1): -    if lis[i + 1] + lis[i] > x: -        cou += lis[i + 1] + lis[i] - x -        lis[i + 1] -= lis[i + 1] + lis[i] - x -print(cou) +cou = lis[0] +ans = 0 +if cou > k: +    ans += cou - k +    cou = k +for i in range(1, n): +    if cou + lis[i] > k: +        num = cou + lis[i] - k +        cou = lis[i] - num +        ans += num +    else: +        cou = lis[i] +print(ans)