Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from functools import cmp_to_key
def cmp(store1, store2):
    if store1 == store2:
        return 0
    a1, b1 = store1
    a2, b2 = store2
    return -1 if a2 * (b1 + 1) <= a1 * (b2 + 1) else 1

def resolve():
    n, T = map(int, input().split())
    assert n <= 3000
    AB = [tuple(map(int, input().split())) for _ in range(n)]
    AB.sort(key = cmp_to_key(cmp))

    # dp[i][j] : i まで見て j 個到達するまでに掛かる最短時間
    dp = [T + 1] * (n + 1)
    dp[0] = 0
    for a, b in AB:
        for i in range(n - 1, -1, -1):
            t = dp[i]
            dp[i + 1] = min(dp[i + 1], (a + 1) * (t + 1) + b)

    for i in range(n, -1, -1):
        if dp[i] <= T:
            print(i)
            return
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from bisect import bisect_right
from itertools import accumulate
from functools import cmp_to_key

def cmp(store1, store2):
    if store1 == store2:
        return 0
    a1, b1 = store1
    a2, b2 = store2
    return -1 if a2 * (b1 + 1) <= a1 * (b2 + 1) else 1

def resolve():
    n, T = map(int, input().split())
    AB = []
    zero = []
    for _ in range(n):
        a, b = map(int, input().split())
        if a != 0:
            AB.append((a, b))
        else:
            zero.append(b + 1)

    AB.sort(key = cmp_to_key(cmp))
    zero.sort()
    zero = list(accumulate(zero))

    max_store = 30
    dp = [T + 1] * max_store
    dp[0] = 0
    for a, b in AB:
        for i in range(max_store - 2, -1, -1):
            t = dp[i]
            dp[i + 1] = min(dp[i + 1], (a + 1) * (t + 1) + b)

    res = 0
    for i in range(max_store):
        t = dp[i]
        if t > T:
            break
        rest = T - t
        res = max(res, i + bisect_right(zero, rest))

    print(res)
resolve()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from functools import cmp_to_key
def cmp(store1, store2):
    if store1 == store2:
        return 0
    a1, b1 = store1
    a2, b2 = store2
    return -1 if a2 * b1 <= a1 * b2 else 1

def resolve():
    n, T = map(int, input().split())
    assert n <= 3000
    AB = [tuple(map(int, input().split())) for _ in range(n)]
    AB.sort(key = cmp_to_key(cmp))

    # dp[i][j] : i まで見て j 個到達するまでに掛かる最短時間
    dp = [T + 1] * (n + 1)
    dp[0] = 0
    for a, b in AB:
        for i in range(n - 1, -1, -1):
            t = dp[i]
            dp[i + 1] = min(dp[i + 1], (a + 1) * (t + 1) + b)
        # print(a, b, dp)

    for i in range(n, -1, -1):
        if dp[i] <= T:
            print(i)
            return
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from bisect import bisect_right
from itertools import accumulate
from functools import cmp_to_key

def cmp(store1, store2):
    if store1 == store2:
        return 0
    a1, b1 = store1
    a2, b2 = store2
    return -1 if a2 * (b1 + 1) <= a1 * (b2 + 1) else 1

def resolve():
    n, T = map(int, input().split())
    AB = []
    zero = []
    for _ in range(n):
        a, b = map(int, input().split())
        if a != 0:
            AB.append((a, b))
        else:
            zero.append(b + 1)

    AB.sort(key = cmp_to_key(cmp))
    zero.sort()
    zero = list(accumulate(zero))

    max_store = 30
    dp = [T + 1] * max_store
    dp[0] = 0
    for a, b in AB:
        for i in range(max_store - 2, -1, -1):
            t = dp[i]
            dp[i + 1] = min(dp[i + 1], (a + 1) * (t + 1) + b)

    res = 0
    for i in range(max_store):
        t = dp[i]
        if t > T:
            break
        rest = T - t
        res = max(res, i + bisect_right(zero, rest))

    print(res)
resolve()