CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, x = mi()
A = li()
adj = []

for i in range(N-1):
    adj.append(A[i]+A[i+1])

ans = 0
for i, num in enumerate(adj):
    if num > x:
        ans += num - x
        if i < N-2:
            adj[i+1] = max(adj[i+1] - (num-x), A[i+2])
print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, x = mi()
A = li()
adj = []
'''
for i in range(N-1):
    adj.append(A[i]+A[i+1])

ans = 0
for i, num in enumerate(adj):
    if num > x:
        ans += num - x
        if i < N-2:
            adj[i+1] = max(adj[i+1] - (num-x), A[i+2])
print(ans)
'''
ans = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        wa = A[i] + A[i+1]
        ans += wa - x
        if A[i+1] < wa - x:
            A[i+1] = 0
        else:
            A[i+1] -= wa - x

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

# Optimized solution
N,x=list(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)
# Original solution
N,X,*A = list(map(int,open(0).read().split()))
A+=[0]
s = 0

for n in range(N):
  d=max(0,A[n]+A[n-1]-X)
  s+=d
  A[n]-=d

print(s)

# Optimized solution
N,x = list(map(int,input().split()))
A = list(map(int,input().split()))
pre = 0
ans = 0

for a in A:
  eat = max(0,pre+a-x)
  pre = a - eat
  ans+= eat

print(ans)
# Original solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0

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

print(count)


# Optimized solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0

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

print(count)
# Original solution
N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A=[min(x,a)for a in A]
for i in range(N-1):A[i+1]-=max(0,A[i]+A[i+1]-x)
print((s-sum(A)))

# Optimized solution
N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A+=0,
for i in range(N):A[i]-=max(0,A[i]+A[i-1]-x)
print((s-sum(A)))
# Original solution
def main():
    N, x, *a = list(map(int, open(0).read().split()))
    ans = 0
    pre = a[0]
    for i in range(1, N):
        if x < pre + a[i]:
            cur = pre + a[i] - x
            ans += cur
            a[i] = a[i] - cur if cur < a[i] else 0
        pre = a[i]
    print(ans)
    return


main()


# Optimized solution
def main():
    N, x, *a = list(map(int, open(0).read().split()))
    ans = a[0] - x if x < a[0] else 0
    pre = min(a[0], x)
    for i in range(1, N):
        dif = pre + a[i] - x
        if 0 < dif:
            ans += dif
            a[i] -= dif
        pre = a[i]
    print(ans)
    return


main()
# Original solution
#003
N,x=input().split(" ")
s = input().split(" ")
list = []
for i in range(int(N)):
    list.append(int(s[i]))
count = 0

if(list[0]>int(x)):
    count+=list[0]-int(x)
    list[0]-=list[0]-int(x)

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

# Optimized solution
#003
N,x= [int(i) for i in input().split(" ")]
list = [int(i) for i in input().split(" ")]
count = 0 
for i in range(N):
    if(i==0):
        if list[i]>x:
            temp = list[i]-x
            count+=temp
            list[i]-=temp
    else:
        temp = list[i]+list[i-1]-x
        if(temp>0):
            count+=temp
            list[i]-=temp    
print(count)
# Original solution
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))

res = float('inf')
for b in (a,a[::-1]):
    tmp = 0
    for i in range(n-1):
        if b[i]+b[i+1]>x:
            tmp += b[i] + b[i+1] - x
            if b[i]>x:
                b[i],b[i+1] = x,0
            else:
                b[i+1] = x - b[i]
    res = min(res,tmp)

print(res)


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

res = 0
if a[0]>x:
    res += a[0] - x
    a[0] = x
if a[-1]>x:
    res += a[-1] - x
    a[-1] = x
for i in range(n-1):
    if a[i]+a[i+1]>x:
        res += a[i] + a[i+1] - x
        a[i+1] -= a[i] + a[i+1] - x
print(res)
# Original solution
N,x=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
    if sum(a[i:i+2])>x:
        while sum(a[i:i+2])>x:
            a[i+1]-=1
            ans+=1
        while sum(a[i:i+2])>x:
            a[i]-=1
            ans+=1

print(ans)

# Optimized solution
N,x=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
    ex=sum(a[i:i+2])-x
    if ex>0:
        ans+=ex
        if a[i+1]>=ex:
            a[i+1]-=ex
        else:
            a[i+1]=0
            a[i]-=ex-a[i+1]
print(ans)
# Original solution
N,x=list(map(int,input().split()))
A=list(map(int,input().split()))
ans=0
pre=0
for i in range(N-1):
    s=A[i]+A[i+1]-pre
    ans+=max(0,s-x)
    pre=min(max(0,s-x),A[i+1])
print(ans)

# Optimized solution
N, x = list(map(int, input().split()))
*A, = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    w = A[i] + A[i + 1]
    if w <= x: continue
    r = max(0, A[i + 1] - (w - x))
    l = x - r
    ans += A[i] - l + A[i + 1] - r
    A[i + 1] = r
print(ans)
# Original solution
# Beginner 50 C
import copy

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

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

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


# Optimized solution
# Beginner 50 C
N, x = list(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))
# Original solution
def calc(ran, count, cans, X):
  for n in ran:
    if n == 0:
      while cans[n+1] + cans[n] > X:
        cans[n] -= 1
        count += 1  
      continue
    if n + 1 == N:
      while cans[n-1] + cans[n] > X:
        cans[n] -= 1
        count += 1  
      continue
    while cans[n-1] + cans[n] > X or cans[n+1] + cans[n] > X:
      cans[n] -= 1
      count += 1
  return count, cans

N, X = list(map(int, input().split()))
cans = list(map(int, input().split()))

count = 0

# odd_range = range(1, N, 2)
# even_range = range(0, N, 2)
# count, cans = calc(odd_range, count, cans, X)
# count, cans = calc(even_range, count, cans, X)

# even_count = count
# print(min(odd_count, even_count))

for i in range(0, N-1):
  while cans[i] + cans[i+1] > X:
    cans[i+1] -= 1
    count += 1
print(count)

# Optimized solution
# def calc(ran, count, cans, X):
#   for n in ran:
#     if n == 0:
#       while cans[n+1] + cans[n] > X:
#         cans[n] -= 1
#         count += 1  
#       continue
#     if n + 1 == N:
#       while cans[n-1] + cans[n] > X:
#         cans[n] -= 1
#         count += 1  
#       continue
#     while cans[n-1] + cans[n] > X or cans[n+1] + cans[n] > X:
#       cans[n] -= 1
#       count += 1
#   return count, cans

# N, X = map(int, input().split())
# cans = list(map(int, input().split()))

# count = 0

# # odd_range = range(1, N, 2)
# # even_range = range(0, N, 2)
# # count, cans = calc(odd_range, count, cans, X)
# # count, cans = calc(even_range, count, cans, X)

# # even_count = count
# # print(min(odd_count, even_count))

# for i in range(0, N-1):
#   if cans[i] + cans[i+1] > X:
#     cans[i+1] -= X - cans[i]
#     count += 1
# print(count)
n, x = list(map(int, input().split()))
l = list(map(int, input().split()))
 
y = 0
if l[0] > x:
    w = l[0] - x
    y += w
    l[0] -= w
 
for i in range(n-1):
    if l[i] + l[i+1] > x:
        z = l[i+1] + l[i] - x
        y += z
        l[i+1] -= z
 
print(y)
# Original solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))

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



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

res = 0
if a[0]>x:
    res = a[0]-x
    a[0] = x
for i in range(1,N):
    tmp = a[i]+a[i-1]-x
    if tmp > 0:
        a[i] -= tmp
        res += tmp
print(res)
# Original solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))

count = 0

for i, c in enumerate(a):
	try:
		j = a[i + 1]
	except IndexError:
		break

	while (a[i + 1] + c) > x:
		if (a[i + 1] + c) == x:
			break
		count += 1
		a[i + 1] -= 1
	else:
		continue

print(count)

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

count = 0

for i, c in enumerate(a):
	try:
		j = a[i + 1]
	except IndexError:
		break
	while (a[i + 1] + c) > x:
		if (a[i + 1] + c) == x:
			break
		count += abs(x - (a[i + 1] + c))
		a[i + 1] -= abs(x - (a[i + 1] + c))
		if a[i + 1] <= 0:
			a[i + 1] = 0
			break
	else:
		continue

print(count)
# Original solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy

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

print(ans)

# Optimized solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
candy = min(a[0], x)
ans = a[0] - candy
a[0] = candy

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

print(ans)
# Original solution
#coding: utf-8

N, X = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

diffs = []
for i in range(N-1):
    diffs.append(A[i]+A[i+1] - X)

ret = 0
for i in range(N-1):
    tmp = min(diffs[i], A[i+1])
    ret += tmp
    diffs[i]   -= tmp
    if i+1 < len(diffs):
        diffs[i+1] -= min(tmp, diffs[i+1]) 
    ret += diffs[i]

print((max(0, ret)))



# Optimized solution
#coding: utf-8

N, X = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

ret = 0
for i in range(N-1):
    if A[i] + A[i+1] > X:
        tmp = A[i] + A[i+1] - X
        ret += tmp
        A[i+1] -= min(A[i+1], tmp)


print(ret)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 0
for i in range(1, N):
    candy = A[i] + A[i - 1]

    # Kより少ないならそのまま
    if candy < K:
        continue

    # 右にあるやつをたべる
    r = min(A[i], candy - K)
    candy -= r
    A[i] -= r
    ans += r
    if candy < K:
        continue

    # 左にあるやつを食べる
    l = min(A[i - 1], candy - K)
    candy -= l
    A[i - 1] -= l
    ans += l
    if candy < K:
        continue

print(ans)


# Optimized solution
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    L = A[i]
    R = A[i + 1]
    eat = max(0, L + R - x)
    ans += eat
    A[i + 1] = max(0, R - eat)

print(ans)
# Original solution
import bisect
n, d, a = list(map(int, input().split()))
fox = [None]*n
for i in range(n):
  x, h = list(map(int, input().split()))
  fox[i] = (x, h)

fox.sort()
x = [int(fox[i][0]) for i in range(n)]
h = [int(fox[i][1]) for i in range(n)]

ans = 0
bit = [0]*n
for i in range(n):
  if i != 0:
    bit[i] += bit[i-1]
  if bit[i] >= h[i]:
    continue
  sub = (h[i]-bit[i]-1)//a+1
  ans += sub
  bit[i] += sub*a
  index = bisect.bisect_right(x, x[i]+2*d)
  if index == n:
    continue
  bit[index] -= sub*a
print(ans)

# Optimized solution
import bisect
import sys

def main():
  input = sys.stdin.readline
  n, d, a = list(map(int, input().split()))
  fox = [None]*n
  for i in range(n):
    x, h = list(map(int, input().split()))
    fox[i] = (x, h)

  fox.sort()
  x = [int(fox[i][0]) for i in range(n)]
  h = [int(fox[i][1]) for i in range(n)]

  ans = 0
  bit = [0]*n
  for i in range(n):
    if i != 0:
      bit[i] += bit[i-1]
    sub = max([(h[i]-bit[i]-1)//a+1, 0])
    ans += sub
    bit[i] += sub*a
    index = bisect.bisect_right(x, x[i]+2*d)
    if index != n:
      bit[index] -= sub*a
  print(ans)

if __name__ == "__main__":
  main()
# Original solution
import bisect
n, d, a = list(map(int, input().split()))
fox = [None]*n
for i in range(n):
  x, h = list(map(int, input().split()))
  fox[i] = (x, h)

fox.sort()
x = [int(fox[i][0]) for i in range(n)]
h = [int(fox[i][1]) for i in range(n)]

ans = 0
bit = [0]*n
for i in range(n):
  if i != 0:
    bit[i] += bit[i-1]
  if bit[i] >= h[i]:
    continue
  sub = (h[i]-bit[i]-1)//a+1
  ans += sub
  bit[i] += sub*a
  index = bisect.bisect_right(x, x[i]+2*d)
  if index == n:
    continue
  bit[index] -= sub*a
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline


n, d, a = list(map(int, input().split()))
fox = [list(map(int, input().split())) for _ in range(n)]

fox.sort()

sub = [0]*(n+1)

def bisect(x):
    l, r = 0, n
    while r-l > 1:
        k = (r+l)//2
        if fox[k][0] <= x:
            l = k
        else:
            r = k
    if fox[l][0] <= x:
        return l
    return r


def main():
    ans = 0
    
    for i in range(n):
        if i != 0:
            sub[i] += sub[i-1]
        if fox[i][1]-a*sub[i] <= 0:
            continue
        count = (fox[i][1]-sub[i]*a-1)//a+1
        ans += count
        sub[i] += count
        sub[bisect(fox[i][0]+2*d)+1] -= count

    print(ans)

    
if __name__ == "__main__":
    main()
# Original solution
import heapq as hq

N, D, A = list(map(int,input().split()))
m = []
for i in range(N):
    hq.heappush(m, tuple(map(int,input().split())))
ans = 0
dmg = 0; d = []
while m:
    X, H = m[0] # 
    if not d or (X <= d[0][0]):
        if dmg >= H:
            hq.heappop(m)
        else:
            k = (H - dmg + A - 1) // A
            ans += k
            dmg += k * A
            hq.heappush(d, (X + 2 * D, - k * A))
    else:
        dmg += d[0][1]
        hq.heappop(d)
    # print(dmg, m, d) #DB

print(ans)

# Optimized solution
import heapq as hq

N, D, A = list(map(int,input().split()))
m = []
for i in range(N):
    hq.heappush(m, tuple(map(int,input().split())))
ans = 0
dmg = 0; d = []
while m:
    X, H = m[0]
    if not d or (X <= d[0][0]):
        if dmg < H:
            k = (H - dmg + A - 1) // A
            ans += k
            dmg += k * A
            hq.heappush(d, (X + 2 * D, - k * A))
        hq.heappop(m)
    else:
        dmg += d[0][1]
        hq.heappop(d)
    # print(dmg, m, d) #DB

print(ans)
# Original solution
from bisect import bisect_right

N, D, A = list(map(int, input().split()))
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+1)
b = 0
for i, (x, h) in enumerate(xh):
  d = ds[i]
  if d>=h:
    continue
  h -= d
  times = h//A if h%A==0 else h//A+1
  for j in range(i, (bisect_right(xh, [x+2*D, float('inf')]))):
  	ds[j] += times*A
  b += times
print(b)

# Optimized solution
from bisect import bisect_right

N, D, A = list(map(int, input().split()))
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
  ds[i] += ds[i-1]
  d = ds[i]
  if d>=h:
    continue
  h -= d
  times = h//A if h%A==0 else h//A+1
  ds[i] += times*A
  ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
  b += times
print(b)
# Original solution
import bisect

N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]


class BIT:
    def __init__(self, n):
        # 1-index
        self.n = n
        self.dat = [[0] * self.n for _ in range(2)]
        
    def _add_body(self, p, i, x):
        while i < self.n:
            self.dat[p][i] += x
            i += i & -i

    def add(self, a, b, x):
        # Add x to [a, b)
        self._add_body(0, a, x * -(a - 1))
        self._add_body(1, a, x)
        self._add_body(0, b, x * (b - 1))
        self._add_body(1, b, x * -1)

    def _query_body(self, p, i):
        res = 0
        while i > 0:
            res += self.dat[p][i]
            i -= i & -i
        return res
        
    def query(self, a, b):
        # Return sum of [a, b)
        res = (self._query_body(0, b - 1)
               + self._query_body(1, b - 1) * (b - 1)
               - self._query_body(0, a - 1)
               - self._query_body(1, a - 1) * (a - 1))
        return res

    def __repr__(self):
        return ", ".join([str(self.query(i, i + 1)) for i in range(self.n)])


X, H = list(zip(*sorted(XH)))
bit = BIT(N + 10)

# 初期化
for i, h in enumerate(H):
    bit.add(i + 1, i + 2, h)
    
# 処理
res = 0
for i in range(N):
    cur = bit.query(i + 1, i + 2)
    if cur <= 0:
        continue

    need = -(-cur // A)
    idx = bisect.bisect_right(X, X[i] + 2 * D)
    bit.add(i + 1, idx + 1, -need * A)
    res += need
    
print(res)


# Optimized solution
from bisect import bisect_right

N, D, A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]

x = []
h = []
for d, i in sorted(X):
    x.append(d)
    h.append(i)

ans = 0
k = [-(-v // A) for v in h]
y = [0] * (N + 2)
for i in range(N):
    y[i + 1] += y[i]
    s = max(0, k[i] - y[i + 1])
    ans += s
    y[i + 1] += s
    y[bisect_right(x, x[i] + 2 * D) + 1] -= s
    
print(ans)
# Original solution
from bisect import bisect_right

N, D, A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]

x = []
h = []
for d, i in sorted(X):
    x.append(d)
    h.append(i)

ans = 0
k = [-(-v // A) for v in h]
y = [0] * (N + 2)
for i in range(N):
    y[i + 1] += y[i]
    s = max(0, k[i] - y[i + 1])
    ans += s
    y[i + 1] += s
    y[bisect_right(x, x[i] + 2 * D) + 1] -= s
    
print(ans)


# Optimized solution

from bisect import bisect_right

N, D, A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
place = []
hps = []
for x, h in X:
    place.append(x)
    hps.append(h)

buf = [0] * (N + 2)
ans = 0
for i in range(N):
    # Update
    buf[i + 1] += buf[i]

    # Calc count
    tmp = -(-max(0, hps[i] - buf[i + 1] * A) // A)
    ans += tmp

    # Calc range
    j = bisect_right(place, place[i] + D * 2)
    buf[i + 1] += tmp
    buf[min(j + 1, N + 1)] -= tmp

print(ans)
# Original solution
import sys
input = sys.stdin.readline
n, d, a = [int(i) for i in input().split()]
chk = []
for i in range(n):
  x, h = [int(i) for i in input().split()]
  chk.append((x, 0, h))
  
from heapq import heapify, heappop, heappush
heapify(chk)
atk_cnt = 0
ans = 0
while chk:
  x, t, h = heappop(chk)
  if t == 0:
    if atk_cnt * a >= h:
        continue
    remain = h - atk_cnt * a
    new_atk = (remain - 1) // a + 1
    heappush(chk, (x + 2 * d, 1, new_atk))
    ans += new_atk
    atk_cnt += new_atk
  else:
    atk_cnt -= h
print(ans)

# Optimized solution
def main():  
  import sys
  input = sys.stdin.readline
  n, d, a = [int(i) for i in input().split()]
  chk = []
  for i in range(n):
    x, h = [int(i) for i in input().split()]
    chk.append((x, 0, h))

  from heapq import heapify, heappop, heappush
  heapify(chk)
  atk_cnt = 0; ans = 0
  while chk:
    x, t, h = heappop(chk)
    if t == 0:
      if atk_cnt * a >= h:
          continue
      remain = h - atk_cnt * a
      new_atk = (remain - 1) // a + 1
      heappush(chk, (x + 2 * d, 1, new_atk))
      ans += new_atk
      atk_cnt += new_atk
    else:
      atk_cnt -= h
  print(ans)
if __name__ == '__main__':
    main()
# Original solution
import bisect
def main():
    N,D,A=list(map(int,input().split()))
    XH=[list(map(int,input().split())) for _ in range(N)]
    XH.sort()
    for i in range(N):
        XH[i][1]=-(-XH[i][1]//A)
    X=[x for x,a in XH]
    far=[0]*N
    for i in range(N):
        far[i]=bisect.bisect_right(X,X[i]+2*D)-1

    ans=0
    for i in range(N):
        x=XH[i][0]
        hp=XH[i][1]
        if hp<=0:
            continue
        #XH=[[xx,hh-hp] for xx,hh in XH[:far[i]+1]]+XH[far[i]+1:]
        for j in range(i,far[i]+1):
            XH[j][1]-=hp
        ans+=hp
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
import bisect
def main():
    N,D,A=list(map(int,input().split()))
    XH=[list(map(int,input().split())) for _ in range(N)]
    XH.sort()
    for i in range(N):
        XH[i][1]=-(-XH[i][1]//A)
    X=[x for x,a in XH]
    far=[0]*N
    for i in range(N):
        far[i]=bisect.bisect_right(X,X[i]+2*D)-1

    ans=0
    carry=0
    outrange=[0]*(N+1)
    for i in range(N):
        x=XH[i][0]
        hp=XH[i][1]
        carry-=outrange[i]
        if carry>=hp:
            continue
        outrange[bisect.bisect_right(X,X[i]+2*D)]+=hp-carry
        ans+=hp-carry
        carry+=hp-carry
    print(ans)

if __name__ == '__main__':
    main()