Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = []
    for _ in range(N):
        X, H = map(int, readline().split())
        XH.append((X, (H + A - 1) // A))

    D *= 2
    XH.sort()
    X = [x for x, h in XH]
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        result += h
        bit_add(bit, i, h)

        t = x + D
        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if X[m] <= t:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -h)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = []
    for _ in range(N):
        X, H = map(int, readline().split())
        H = (H + A - 1) // A
        XH.append((X, H))

    XH.sort()
    X = [x for x, h in XH]
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        result += h
        bit_add(bit, i, h)

        t = x + 2 * D
        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if X[m] <= t:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -h)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = []
    for _ in range(N):
        X, H = map(int, readline().split())
        H = (H + A - 1) // A
        XH.append((X, H))

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        result += h
        bit_add(bit, i, h)

        t = x + 2 * D
        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= t:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -h)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = [tuple(map(int, readline().split())) for _ in range(N)]

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        t = x + 2 * D
        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= t:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = [tuple(map(int, readline().split())) for _ in range(N)]

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= x + 2 * D:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = [list(map(int, readline().split())) for _ in range(N)]

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= x + 2 * D:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    while i <= len(bit):
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = [list(map(int, readline().split())) for _ in range(N)]

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= x + 2 * D:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    while i <= len(bit):
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = [list(map(int, readline().split())) for _ in range(N)]

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= x + 2 * D:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    while i <= len(bit):
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


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

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= x + 2 * D:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def bit_add(bit, i, x):
    i += 1
    while i <= len(bit):
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


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

XH.sort()
result = 0
bit = [0] * (N + 1)
for i in range(N):
    x, h = XH[i]
    h -= bit_sum(bit, i)
    if h <= 0:
        continue
    c = (h + A - 1) // A
    result += c
    bit_add(bit, i, c * A)

    ok = i
    ng = N
    while ng - ok != 1:
        m = ok + (ng - ok) // 2
        if XH[m][0] <= x + 2 * D:
            ok = m
        else:
            ng = m
    bit_add(bit, ng, -c * A)
print(result)


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while q:
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h <= 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while q:
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h <= 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, D, A = map(int, input().split())
    XH = []
    for i in range(N):
        x, h = map(int, input().split())
        h = (h + (A - 1)) // A
        XH.append([x, h])

    XH.sort()
    result = 0
    for i in range(N):
        x, h = XH[i]
        if h < 0:
            continue
        result += h
        for j in range(i + 1, N):
            if XH[j][0] > x + 2 * D:
                break
            XH[j][1] -= h
    print(result)
main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, D, A = map(int, input().split())
    XH = []
    for i in range(N):
        x, h = map(int, input().split())
        h = (h + (A - 1)) // A
        XH.append([x, h])

    XH.sort()
    result = 0
    for i in range(N):
        x, h = XH[i]
        if h < 0:
            continue
        result += h
        for j in range(i + 1, N):
            if XH[j][0] > x + 2 * D:
                break
            XH[j][1] -= h
    print(result)
main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, D, A = map(int, input().split())
    XH = [list(map(int, input().split())) for _ in range(N)]

    XH.sort()
    result = 0
    for i in range(N):
        x, h = XH[i]
        if h < 0:
            continue
        c = (h + (A - 1)) // A
        result += c
        for j in range(i + 1, N):
            if XH[j][0] > x + 2 * D:
                break
            XH[j][1] -= c * A
    print(result)
main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, D, A = map(int, input().split())
    XH = [list(map(int, input().split())) for _ in range(N)]

    XH.sort()
    result = 0
    for i in range(N):
        x, h = XH[i]
        if h < 0:
            continue
        c = (h + (A - 1)) // A
        result += c
        for j in range(i + 1, N):
            if XH[j][0] > x + 2 * D:
                break
            XH[j][1] -= c * A
    print(result)
main()


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
result = 0
for i in range(N):
    if XH[i][1] < 0:
        continue
    c = (XH[i][1] + (A - 1)) // A
    result += c
    for j in range(i + 1, N):
        if XH[j][0] > XH[i][0] + 2 * D:
            break
        XH[j][1] -= c * A
print(result)


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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)