qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
a, b, x = map(int, input().split())
if a == 0:
    num = int(b / x)
else:
    num = int(b / x) - int((a - 1) / x)
print(num)


# Fixed code:
a, b, x = map(int, input().split())
if a == 0:
    num = b // x + 1
else:
    num = b // x - (a - 1) // x
print(num)
# Buggy code:
a, b, x = map(int, input().split())

B = b // x
A = (a - 1) // x
print(B, A)

print(B - A)

# Fixed code:
a, b, x = map(int, input().split())

B = b // x
A = (a - 1) // x

print(B - A)
# Buggy code:
a,b,x=map(int,input().split())
print((b-a//x)+1)

# Fixed code:
a,b,x = map(int,input().split())
print((b+x)//x - (a-1+x)//x )
# Buggy code:
a,b,x = map(int,input().split())

#for i in range(a,b+1):
#	if i % x == 0:
#		ans = ans + 1

ans1 = b//x
ans2 = a//x

print(ans1)
print(ans2)

if b%x == 0:
	print(ans1-ans2+1)
else:
	print(ans1-ans2)




# Fixed code:
a,b,x = map(int,input().split())

#for i in range(a,b+1):
#	if i % x == 0:
#		ans = ans + 1

ans1 = a//x
ans2 = b//x

#print(ans1)
#print(ans2)

if a%x == 0:
	print(ans2-ans1+1)
else:
	print(ans2-ans1)
# Buggy code:
a, b, x = map(int, input().split())

print(b//x - (a//x-1))

# Fixed code:
a,b,x= map(int, input().split())

print(b//x - (a-1)//x)
# Buggy code:
a, b, x = map(int, input().split())
ans = 0
if a == 0: ans = b/x + 1
else: ans = b/x - (a-1)/x
print ans

# Fixed code:
a,b,x = map(int, input().split())
print(b//x+1 - ((a-1)//x+1 if a else 0))
# Buggy code:
import math
a,b,x = map(int,input().split())
print(sum([1 for i in range(a,b+1) if i % x == 0]))
#print(b // x - (a - 1) // x)


# Fixed code:
import math
a,b,x = map(int,input().split())
c = 0
#print(sum([1 for i in range(a,b+1) if i % x == 0]))
print(b // x - (a - 1) // x)
# Buggy code:
a,b,c=map(int,input().split())
print(a//c-b//c)

# Fixed code:
a,b,c = map(int,input().split())

print(b//c-(a-1)//c)
# Buggy code:
a,b,x = map(int,input().split())
print(int(b/x)-int((a-1)/x))

# Fixed code:
a,b,x = map(int, input().split())
a -= 1
print(b//x-a//x)
# Buggy code:
a,b,n = map(int,input().split())
if a%n==0:
    k=1
else:
    k=0
print(int((b-a)/n)+k)


# Fixed code:
a,b,x = map(int,input().split())
if a%x==0:
    k=1
else:
    k=0
print(b//x - a//x + k)
# Buggy code:
a,b,x = map(int, input().split())
print((b+1)//x-(a-1)//x)

# Fixed code:
a,b,x = map(int,input().split())

print(b//x - ( a - 1 )//x)
# Buggy code:
a, b, x = map(int, input().split())
if b == a and b % x != 0:
    print(0)
else:
    if (b-a) % x == 0:
        print((b-a)//x+1)
    else:
        print((b-a)//x)

# Fixed code:
a,b,x = map(int,input().split())
if a%x == 0:
    print(b//x-a//x + 1)
else:
    print(b//x-a//x)
# Buggy code:
a,b,x = map(int, input().split())
print(b/x - a/x + 1)

# Fixed code:
a,b,x=map(int, input().split())
print(b//x - (a-1)//x)
# Buggy code:
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    a,b,x = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = math.floor(b/x)-math.ceil(a/x)+1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


# Fixed code:
from sys import stdin


def ceil(a,b):
    return (a+b-1)//b


def floor(a,b):
    return a//b


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    a,b,x = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = floor(b,x)-ceil(a,x)+1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)
# Buggy code:
a,b,x = map(int, input().split())
print((b-a)//x + 1)

# Fixed code:

a , b , x = map(int , input().split())
print(b//x  - (a-1)//x)
# Buggy code:
a, b, x = map(int, input().split())

ans = 0
if a == 0:
    ans = 1
ans += int((b - a) / x )
print(ans)

# Fixed code:
a, b, x = map(int, input().split())
ans = b//x - a//x
if a % x == 0:
  ans += 1
print(ans)
# Buggy code:
a,b,x = map(int, input().split())

c = b - a

d = c // x

print(d)

# Fixed code:
a,b,x = map(int, input().split())

c = (b // x) - ((a - 1) // x)
d = c

print(d)
# Buggy code:
a,b,x=map(int,input().split())

print(a,b,x)

aw=a//x
bw=b//x
ans=bw-aw

if b%x==0:
    ans+=1

print(ans)

# Fixed code:
a,b,x=map(int,input().split())
aw=a//x
bw=b//x
ans=bw-aw

if a%x==0:
    ans+=1

print(ans)
# Buggy code:
a,b,x=map(int,input().split())
s=(b-a-1)//x
if a%x==0:
    s+=1
if b%x==0:
    s+=1
print(s)
        


# Fixed code:
a,b,x=map(int,input().split())
if a==0:
    s=b//x+1
else:
    s=b//x-(a-1)//x
print(s)
# Buggy code:
a, b, x = map(int, input().split())
print(int((b-a+1)//x))

# Fixed code:
a, b, x = map(int,input().split())
print((b//x)-(a-1)//x)
# Buggy code:
a, b, x = map(int, input().split())
print(b//x-a//x+1 if (b-a)!=0 else 0)

# Fixed code:
a,b,x = map(int, input().split())
print(b//x - a//x + (1 if a%x==0 else 0))
# Buggy code:
(a,b,x) = map(int,input().split())
if a==0:
    print(int(b/x)+1)
else:
    print(int(b/x)-int(a/x))

# Fixed code:
a, b, x = map(int, input().split())
if a == 0:
    print(b//x + 1)
else:
    print(b//x - (a-1)//x)
# Buggy code:
a, b, x  = list(map(int, input().split()))
print(b//x - a//x + 1)

# Fixed code:
a, b, x  = list(map(int, input().split()))
print(b//x - (a-1)//x)
# Buggy code:
a, b, x = map(int, input().split())

print(int(b/x)-int(a/x)+1)

# Fixed code:
a, b, x = map(int, input().split())

print((b//x+1)-((a-1)//x+1))
# Buggy code:
a,b,x = map(int,input().split())
def f(p):
    q = p//x
ans = f(b) - f(a-1)
print(ans)

# Fixed code:
a,b,x = map(int,input().split())
def f(p):
    q = p//x
    return q
ans = f(b) - f(a-1)
print(ans)
# Buggy code:
a, b, x = list(map(int, input().split(' ')))

if a == 0:
    min_ = 0
else:
    min_ = a // x + 1
if b == 0:
    max_ = 0
else:
    max_ = b // x + 1
#print(min_, max_)
print(max_ - min_)

# Fixed code:
a, b, x = list(map(int, input().split(' ')))

if a == 0:
    min_ = 0
else:
    min_ = (a - 1) // x + 1
max_ = b // x + 1
#print(min_, max_)
print(max_ - min_)
# Buggy code:
# -*- coding:utf-8 -*-
import math
import sys
a, b, x = map(int,input().split())

if a == b:
    if a%x == 0:
        print(1)
    else:
        print(0)
    sys.exit()

ans= math.floor(b / x) - math.floor(a / x) + 1
print(ans)

"""
for tmp in range (a, b+1):
    if tmp % x == 0:
        ans += 1
"""


# Fixed code:
# -*- coding:utf-8 -*-
import math
import sys
a, b, x = map(int,input().split())
"""
if a == b:
    if a%x == 0:
        print(1)
    else:
        print(0)
    sys.exit()
"""
if a%x == 0:
    ans= b // x - a // x + 1
else:    
    ans= b // x - a // x

print(ans)

"""
for tmp in range (a, b+1):
    if tmp % x == 0:
        ans += 1
"""
# Buggy code:
a, b, x = map(int, input().split())
if a != 0:
    print((b // x) - (a - 1) // x)
else:
    print(b//x)


# Fixed code:
a, b, x = map(int, input().split())
if a != 0:
    print(b // x - (a - 1) // x)
else:
    print(b // x + 1)
# Buggy code:
# coding: utf-8
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))

# Fixed code:
# coding: utf-8
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))
# Buggy code:
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)


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

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

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

print(ans)
# Buggy code:
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):
    while (alist[al-1]+alist[al]) > x:
        alist[al] -= 1
        ans += 1

print(ans)

# Fixed code:
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)
# Buggy code:
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)

# Fixed code:
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)
# Buggy code:
n,x = map(int,input().split())
a = list((map(int,input().split())))

b = [0]
for i in range(n):
    b.append(a[i])
b.append(0)    
count = 0

if b[1] > x:
    counter = b[1] - x
    b[1] = x
for i in range(n+1):
    if b[i] + b[i+1] > x:
        s = b[i] + b[i+1] - x
        if b[i] - s > -1:
            b[i] = b[i] -s
            counter = counter + s
        else:
            k = b[i]
            counter = counter + s
            b[i] = 0
            b[i+1] = x
        
print(counter)

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

b = [0]
for i in range(n):
    b.append(a[i])
b.append(0)    
counter = 0

if b[1] > x:
    counter = b[1] - x
    b[1] = x
for i in range(n+1):
    if b[i] + b[i+1] > x:
        s = b[i] + b[i+1] - x
        if b[i+1] - s > -1:
            b[i+1] = b[i+1] -s
            counter = counter + s
        else:
            k = b[i+1]
            counter = counter + s
            b[i+1] = 0
            b[i] = x
        
print(counter)
# Buggy code:
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)

# Fixed code:
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)
# Buggy code:
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)


# Fixed code:
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)
# Buggy code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N - 1):
  s = A[i] + A[i + 1] - x
  ans += max(0, s)
  if s > 0:
    if s <= A[i + 1]:
      A[i + 1] -= s
    else:
      A[i + 1] = 0
print(ans)

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

# Fixed code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
if a[0] > x:
    ans += a[1]
    a[1] = 0
    ans += (a[0] - x)
    a[0] = x
elif (a[0] + a[1]) > x:
    ans += (a[0] + a[1] - x)
    a[1] = x - a[0]
for i in range(2,N):
    if (a[i - 1] + a[i]) > x:
        ans += (a[i - 1] + a[i] - x)
        a[i] = x - a[i - 1] 
print(ans)
# Buggy code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
b = [a[i] + a[i+1] for i in range(n-1)]

ans = max(0, a[0] - x)
b[0] -= ans

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

# Fixed code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
b = [a[i] + a[i+1] for i in range(n-1)] + [0]
 
ans = max(0, a[0] - x)
b[0] -= ans
 
for i in range(n-1):
  diff = max(0, b[i] - x)
  ans += diff
  b[i] -= diff
  b[i+1] -= diff
print(ans)
# Buggy code:
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:
        #print("OK3")
        diff = (a[i] + a[i + 1]) - x
        ans += diff
        a[i + 1] -= diff
    #print(a)

print(ans)

# Fixed code:
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:
        #print("OK3")
        diff = (a[i] + a[i + 1]) - x
        ans += diff
        a[i + 1] -= diff
    #print(a)

print(ans)
# Buggy code:
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)

# Fixed code:
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)
# Buggy code:
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 a[i] >= x:
        ans += wa[i]-x
        a[i] -= wa[i]-x
        wa[i] -= wa[i]-x
        wa[i+1] -= wa[i+1]-x
        continue
    if a[i] < x:
        ans += wa[i]-x
        a[i] = 0
        a[i] = x
        wa[i] = x

print(ans)

# Fixed code:
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)
# Buggy code:
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)

# Fixed code:
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)
# Buggy code:
n,x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
if a[0]>x:
  ans += a[0]-x
  a[0]=x  
else:
  pass
j = 1
while j <= n-1:
  if a[j-1]+a[j]<=x:
    pass
  else:
    ans += a[j]-x
    a[j]=x
print(ans)

# Fixed code:
n,x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
if a[0]>x:
  ans += a[0]-x
  a[0]=x  
else:
  pass
j = 1
while j <= n-1:
  if a[j-1]+a[j]<=x:
    j += 1
  else:
    ans += a[j]-x+a[j-1]
    a[j]=x-a[j-1]
    j += 1
print(ans)
# Buggy code:
N,x=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
for i in range(N):
  cnt+=max(A[i]-x,0)
  A[i]=min(A[i],x)
for i in range(1,N):
  d=max(A[i]+A[i-1]-x,0)
  A[i]-=d
  cnt+=d
print(cnt,A)

# Fixed code:
N,x=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
for i in range(N):
  cnt+=max(A[i]-x,0)
  A[i]=min(A[i],x)
for i in range(1,N):
  d=max(A[i]+A[i-1]-x,0)
  A[i]-=d
  cnt+=d
print(cnt)
# Buggy code:
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)

# Fixed code:
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)
# Buggy code:
# problem C
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
if x < num_list[0]:
    count = n - num_list[0]
    num_list[0] = x
else:
    count = 0


for i in range(N-1):
    n = num_list[i] + num_list[i+1]
    if x < n:
        num_list[i+1] = x - num_list[i]
        count += n - x
    else:
        pass
print(count)

# Fixed code:
# problem C
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
if x < num_list[0]:
    count = num_list[0] - x
    num_list[0] = x
else:
    count = 0

for i in range(N-1):
    n = num_list[i] + num_list[i+1]
    if x < n:
        num_list[i+1] = x - num_list[i]
        count += n - x
    else:
        pass
print(count)
# Buggy code:
def minCandies(boxes,limit):
    out = 0
    for i in range(len(boxes) - 1):
        total = boxes[i] + boxes[i + 1]
        if total > limit:
            out += total - limit
            boxes[i + 1] = boxes[i + 1] - (total - limit)
            if boxes[i + 1] < 0:
                boxes[i + 1] = 0
    return out
    
num_of_boxes, limit = map(int,input().split())
boxes = list(map(int,input().split()))

if limit == 0:
    return sum(boxes)
elif max([a + b for (a,b) in zip(boxes[:-1],boxes[1:])) <= limit:
    return 0
else:
    return minCandies(boxes,limit)


# Fixed code:
def minCandies(boxes,limit):
    out = 0
    for i in range(len(boxes) - 1):
        total = boxes[i] + boxes[i + 1]
        if total > limit:
            out += total - limit
            boxes[i + 1] = boxes[i + 1] - (total - limit)
            if boxes[i + 1] < 0:
                boxes[i + 1] = 0
    return out

num_of_boxes, limit = map(int,input().split())
boxes = list(map(int,input().split()))

if limit == 0:
    print(sum(boxes))
elif max([a + b for (a,b) in zip(boxes[:-1],boxes[1:])]) <= limit:
    print(0)
else:
    print(minCandies(boxes,limit))
# Buggy code:
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:
        a[i] -= (a[i] + a[i-1] - x)
        cnt += (a[i] + a[i-1] - x)
    else:
        break
print(cnt)


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

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

if a[0] > x:
    cnt = a[0] - x
    a[0] = x
else:
    cnt = 0

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

print(cnt)
# Buggy code:
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:
        ooi = a[i] + a[i+1] - x
        if a[i] < a[i+1]:
            if ooi < a[i+1]:
                a[i+1] -= ooi
            else:
                a[i] -= (ooi-a[i+1])
                a[i+1] = 0
        else:
            if ooi < a[i]:
                a[i] -= ooi
            else:
                a[i+1] -= (ooi - a[i])
                a[i] = 0
        ans += ooi

print(ans)

# Fixed code:
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:
        ooi = a[i] + a[i+1] - x
        if ooi < a[i+1]:
            a[i+1] -= ooi
        else:
            a[i] -= (ooi-a[i+1])
            a[i+1] = 0
        ans += ooi

print(ans)
# Buggy code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
counter = 0
pointer = 1
if a[0] > x:
    counter += x - a[0]
    a[0] = x
while pointer <= n - 1:
    if a[pointer - 1] + a[pointer] > x:
        eat = a[pointer - 1] + a[pointer] - x
        counter += eat
        a[pointer] -= eat
    pointer += 1
print(counter)


# Fixed code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
counter = 0
pointer = 1
if a[0] > x:
    counter += a[0] - x
    a[0] = x
while pointer <= n - 1:
    if a[pointer - 1] + a[pointer] > x:
        eat = a[pointer - 1] + a[pointer] - x
        counter += eat
        a[pointer] -= eat
    pointer += 1
print(counter)
# Buggy code:


def read_input():
    n, x = map(int, input().split())
    alist = list(map(int, input().split()))

    return n, x, alist

def submit():
    n, x, alist = read_input()

    edit = 0

    if alist[0] > x:
        edit += x - alist[0]
        alist[0] = x

    for i in range(n - 1):
        if alist[i] + alist[i + 1] > x:
            diff = alist[i] + alist[i + 1] - x
            edit += diff
            alist[i + 1] = alist[i + 1] - diff

    print(edit)


if __name__ == '__main__':
    submit()

    

# Fixed code:


def read_input():
    n, x = map(int, input().split())
    alist = list(map(int, input().split()))

    return n, x, alist

def submit():
    n, x, alist = read_input()

    edit = 0

    if alist[0] > x:
        edit += alist[0] - x
        alist[0] = x

    for i in range(n - 1):
        if alist[i] + alist[i + 1] > x:
            diff = alist[i] + alist[i + 1] - x
            edit += diff
            alist[i + 1] = alist[i + 1] - diff

    print(edit)


if __name__ == '__main__':
    submit()
# Buggy code:
n,x=map(int,input().split())

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

c=0

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

# Fixed code:
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(0,n-1):
  if a[i]+a[i+1]>x:
    c+=(a[i]+a[i+1]-x)
    a[i+1]-=(a[i]+a[i+1]-x)
print(c)
# Buggy code:
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):
        if(a[i-1] > x):
            eat = (x - a[i-1]) + a[i]
            a[i] -= a[i]
            a[i-1] -= x - a[i-1]
            ans += eat
        else:
            eat = (a[i-1] + a[i]) - x
            a[i] -= eat
            ans += eat
print(ans)

# Fixed code:
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):
        if(a[i-1] > x):
            eat = (a[i-1] - x) + a[i]
            a[i] -= a[i]
            a[i-1] -= a[i-1] - x
            ans += eat
        else:
            eat = (a[i-1] + a[i]) - x
            a[i] -= eat
            ans += eat
print(ans)
# Buggy code:
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)

# Fixed code:
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)