Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
_ = int(input())
a = 1
for Ai in input().split(' '):
    a *= int(Ai)

if a > 10**18:
    print('-1')
else:
    print(a)

Fixed submission:
_ = int(input())
A = [ int(i) for i in input().strip().split(' ')]
a = 1
if min(A) == 0:
    print(0)
else:
    for Ai in A:
        a *= Ai
        if a > 10**18:
            print('-1')
            break
    else:
        print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = 1
for Ai in input().split(' '):
    a *= int(Ai)
    if a == 0:
        break

if a > 10**18:
    print('-1')
else:
    print(a)


Fixed submission:
_ = int(input())
A = [ int(i) for i in input().strip().split(' ')]
a = 1
if min(A) == 0:
    print(0)
else:
    for Ai in A:
        a *= Ai
        if a > 10**18:
            print('-1')
            break
    else:
        print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = 1
for Ai in input().strip().split(' '):
    a *= int(Ai)
if a > 10**18:
    print('-1')
else:
    print(a)

Fixed submission:
_ = int(input())
A = [ int(i) for i in input().strip().split(' ')]
a = 1
if min(A) == 0:
    print(0)
else:
    for Ai in A:
        a *= Ai
        if a > 10**18:
            print('-1')
            break
    else:
        print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [ int(i) for i in input().strip().split(' ')]
a = 1
for Ai in A:
    a *= Ai
if a > 10**18:
    print('-1')
else:
    print(a)

Fixed submission:
_ = int(input())
A = [ int(i) for i in input().strip().split(' ')]
a = 1
if min(A) == 0:
    print(0)
else:
    for Ai in A:
        a *= Ai
        if a > 10**18:
            print('-1')
            break
    else:
        print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().strip())
A = [ int(i) for i in input().strip().split(' ')]
#unique_supervisor = list(set(A))

for i in range(1, N+1):
    print(list.count(A, i)) 

Fixed submission:
N = int(input().strip())
data = [0 for _ in range(N)]
for i in input().strip().split(' '):
    data[int(i)-1] += 1

for d in data:
    print(d)
Buggy python submission (verdict: Runtime Error):
a = input()

if a.isUpper():
    print("A")
else:
    print("a")

Fixed submission:
a = input()

if a.isupper():
    print("A")
else:
    print("a")
Buggy python submission (verdict: Time Limit Exceeded):
import collections


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
cnt = collections.Counter(A)

s = -1
for i in range(Q):
    BC = list(map(int, input().split()))

    if BC[0] in cnt:
        if BC[1] in cnt:
            cnt[BC[1]] += cnt[BC[0]]
            del cnt[BC[0]]
        else:
            cnt[BC[1]] = cnt[BC[0]]
            del cnt[BC[0]]
        s = 0
        for k, v in cnt.items():
            s += int(k) * v
    else:
        if s == -1:
            s = 0
            for k, v in cnt.items():
                s += int(k) * v
    print(s)


Fixed submission:
import collections


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
cnt = collections.Counter(A)

s = 0
for k, v in cnt.items():
    s += int(k) * v
for i in range(Q):
    BC = list(map(int, input().split()))

    if BC[0] in cnt:
        if BC[1] in cnt:
            cnt[BC[1]] += cnt[BC[0]]
            s += int(BC[1]) * cnt[BC[0]]
            s -= int(BC[0]) * cnt[BC[0]]
            del cnt[BC[0]]
        else:
            cnt[BC[1]] = cnt[BC[0]]
            s += int(BC[1]) * cnt[BC[0]]
            s -= int(BC[0]) * cnt[BC[0]]
            del cnt[BC[0]]
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import collections


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
cnt = collections.Counter(A)
for i in range(Q):
    BC = list(map(int, input().split()))

    if BC[0] in cnt:
        if BC[1] in cnt:
            cnt[BC[1]] += cnt[BC[0]]
            del cnt[BC[0]]
        else:
            cnt[BC[1]] = cnt[BC[0]]
            del cnt[BC[0]]

    s = 0
    for k, v in cnt.items():
        s += int(k) * v
    print(s)


Fixed submission:
import collections


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
cnt = collections.Counter(A)

s = 0
for k, v in cnt.items():
    s += int(k) * v
for i in range(Q):
    BC = list(map(int, input().split()))

    if BC[0] in cnt:
        if BC[1] in cnt:
            cnt[BC[1]] += cnt[BC[0]]
            s += int(BC[1]) * cnt[BC[0]]
            s -= int(BC[0]) * cnt[BC[0]]
            del cnt[BC[0]]
        else:
            cnt[BC[1]] = cnt[BC[0]]
            s += int(BC[1]) * cnt[BC[0]]
            s -= int(BC[0]) * cnt[BC[0]]
            del cnt[BC[0]]
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10 ** 18:
    ans = -1
print(ans)

Fixed submission:
N = int(input())

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

ans = 1

if 0 in A:
    print(0)
else:
    for i in range(N):
        ans *= A[i]
        if ans > 10 ** 18:
            ans = -1
            break
    print(ans)
Buggy python submission (verdict: Runtime Error):
import collections


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())

primes = prime_factorize(N)


num = 0
hist = []
c = primes[0]
for p in primes:
    if c not in hist:
        hist.append(c)
        num += 1
        c = 1
    c *= p

print(num)


Fixed submission:
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())

primes = prime_factorize(N)

num = 0
hist = [1]
c = 1

tmp = 1
for p in primes:
    # 前回と異なる場合
    if tmp != p:
        c = 1
    tmp = p
    c *= p
    if c not in hist:
        hist.append(c)
        num += 1
        c = 1
print(num)
Buggy python submission (verdict: Runtime Error):
K = int(input())

A, B = map(int, input())

if A // K <= B // K and B % K == 0:
    print("OK")
else:
    print("NG")


Fixed submission:
K = int(input())

A, B = map(int, input().split())

if A // K == B // K:
    if A % K == 0 or B % K == 0:
        print("OK")
    else:
        print("NG")
elif A // K < B // K:
    print("OK")
else:
    print("NG")
Buggy python submission (verdict: Runtime Error):
S = input()

result = []

for i in range(len(S) - 3):
    for j in range(i + 3, len(S)):
        if int(S[i:j+1]) % 2019 == 0:
            result.append([i + 1, j + 1])

print(len(result))


Fixed submission:
S, W = map(int, input().split())

if S > W:
    print("safe")
else:
    print("unsafe")

Buggy python submission (verdict: Runtime Error):
S = input()

result = []

for i in range(len(S) - 3):
    for j in range(i + 3, len(S)):
        if int(S[i:j+1]) % 2019 == 0:
            result.append([i + 1, j + 1])

print(len(result))


Fixed submission:
S, W = map(int, input().split())

if S > W:
    print("safe")
else:
    print("unsafe")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

kind = []
for i in range(N):
    S = input()

    if S not in kind:
        kind.append(S)

print(len(kind))


Fixed submission:
N = int(input())

kind = {}
for i in range(N):
    S = input()

    if S not in kind:
        kind[S] = 1

print(len(kind))
Buggy python submission (verdict: Time Limit Exceeded):
import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += f.gcd(f.gcd(i, j), k)

print(total)


Fixed submission:
import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        ij = f.gcd(i, j)
        if ij == 1:
            total += K
            continue
        for k in range(1, K + 1):
            total += f.gcd(ij, k)

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from functools import lru_cache


@lru_cache(maxsize=40000)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            if gcd(i, j) == 1 or gcd(j, k) == 1:
                total += 1
                continue
            total += gcd(gcd(i, j), k)

print(total)


Fixed submission:
import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        ij = f.gcd(i, j)
        if ij == 1:
            total += K
            continue
        for k in range(1, K + 1):
            total += f.gcd(ij, k)

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from functools import lru_cache


@lru_cache(maxsize=40000)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += gcd(gcd(i, j), k)

print(total)


Fixed submission:
import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        ij = f.gcd(i, j)
        if ij == 1:
            total += K
            continue
        for k in range(1, K + 1):
            total += f.gcd(ij, k)

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += gcd(gcd(i, j), k)

print(total)


Fixed submission:
import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        ij = f.gcd(i, j)
        if ij == 1:
            total += K
            continue
        for k in range(1, K + 1):
            total += f.gcd(ij, k)

print(total)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))

sumA = sum(A)

filteredA = list(filter(lambda x: x < (sumA / (4*M)), A))

if M <= len(filteredA):
    print('Yes')
else:
    print("No")


Fixed submission:
X, Y, Z = map(int, input().split())

X, Y = Y, X
X, Z = Z, X

print(X, Y, Z)
Buggy python submission (verdict: Runtime Error):
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

A = A1 + A2 + A3
N = int(input())

index = []
for i in range(N):
    inp = int(input())
    if inp in A:
        index.append(A.index(inp))

if (0 in index and 3 in index and 6 in index) or \
   (1 in index and 4 in index and 7 in index) or \
   (2 in index and 5 in index and 8 in index) or \
   (0 in index and 4 in index and 8 in index) or \
   (2 in index and 4 in index and 6 in index) or \
   (0 in index and 1 in index and 2 in index) or \
   (3 in index and 4 in index and 5 in index) or \
   (6 in index and 7 in index and 8 in index):
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())

print( (N + 1) // 2)

Buggy python submission (verdict: Runtime Error):
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

A = A1 + A2 + A3
N = int(input())

index = []
for i in range(N):
    index.append(A.index(int(input())))

if (0 in index and 3 in index and 6 in index) or \
   (1 in index and 4 in index and 7 in index) or \
   (2 in index and 5 in index and 8 in index) or \
   (0 in index and 4 in index and 8 in index) or \
   (2 in index and 4 in index and 6 in index) or \
   (0 in index and 1 in index and 2 in index) or \
   (3 in index and 4 in index and 5 in index) or \
   (6 in index and 7 in index and 8 in index):
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())

print( (N + 1) // 2)
Buggy python submission (verdict: Runtime Error):
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

A = A1 + A2 + A3
N = int(input())

index = []
for i in range(N):
    index.append(A.index(int(input())))

if (0 in index and 3 in index and 6 in index) or \
   (1 in index and 4 in index and 7 in index) or \
   (2 in index and 5 in index and 8 in index) or \
   (0 in index and 4 in index and 8 in index) or \
   (2 in index and 4 in index and 6 in index) or \
   (3 in index and 4 in index and 5 in index) or \
   (6 in index and 7 in index and 8 in index):
    print("Yes")
else:
    print("No")

Fixed submission:
# 途中
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

A = A1 + A2 + A3
N = int(input())

index = []
for i in range(N):
    inp = int(input())
    if inp in A:
        index.append(A.index(inp))

if \
   (0 in index and 3 in index and 6 in index) or \
   (1 in index and 4 in index and 7 in index) or \
   (2 in index and 5 in index and 8 in index) or \
   (0 in index and 4 in index and 8 in index) or \
   (2 in index and 4 in index and 6 in index) or \
   (0 in index and 1 in index and 2 in index) or \
   (3 in index and 4 in index and 5 in index) or \
   (6 in index and 7 in index and 8 in index):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

mmod = 10**9 + 7


def comb_mod(n, r, mod=mmod):
    nume = 1
    deno = 1

    r = min(r, r - 1)

    for i in range(1, r + 1):
        nume = (nume * (n - i)) % mod
        deno = (deno * (i + 1)) % mod

    return (nume * pow(deno, mod - 2, mod)) % mod


if n == 2:
    print(0)
    exit

total = (pow(2, n, mmod) - comb_mod(n, a) - comb_mod(n, b) - 1) % mmod

print(total)


Fixed submission:
N, R = map(int, input().split())

if N >= 10:
    rate = R
else:
    rate = R + (100 * (10 - N))

print(rate)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

result = 0
for i in range(N):
    flag = True
    for j in range(i,-1,-1):
        if P[i] > P[j]:
            flag = False
            break
    if flag:
        result += 1

print(result)

Fixed submission:
N = int(input())

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

result = 0
current_min = 10**6
for i in range(N):
    current_min = min(current_min, P[i])
    if P[i] <= current_min:
        result += 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

result = 0
for i in range(N):
    flag = True
    for j in range(i,-1,-1):
        if P[i] > P[j]:
            flag = False
    if flag:
        result += 1

print(result)

Fixed submission:
N = int(input())

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

result = 0
current_min = 10**6
for i in range(N):
    current_min = min(current_min, P[i])
    if P[i] <= current_min:
        result += 1

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q =map(int, input().split())

point = [K] * N
A = []
for i in range(Q):
    point = list(map(lambda x: x -1 , point))
    point[int(input()) - 1] += 1

for p in point:
    if p > 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
N, K, Q =map(int, input().split())

A = {}
for i in range(Q):
    a = int(input())
    if a in A:
        A[a] += 1
    else:
        A[a] = 1

for i in range(N):
    if K - Q > 0:
        print("Yes")
    elif (i + 1) in A:
        if (K - (Q -A[i + 1])) > 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())

A = [int(input()) for i in range(N)]

for i in range(N):
    B = copy.copy(A)
    B[i] = 0
    print(max(B))

Fixed submission:
import copy

N = int(input())

A = [int(input()) for i in range(N)]

B = copy.copy(A)
B.sort()

for i in range(N):
    if A[i] == B[-1]:
        print(B[-2])
    else:
        print(B[-1])
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, K = map(int, input().split())

for i in range(K):
    tmpA = B + C
    tmpB = A + C
    tmpC = A + B
    A = tmpA
    B = tmpB
    C = tmpC

    if A == B and B == C:
        break

if (A - B) >= 10**18:
    print("Unfair")
else:
    print(A - B)

Fixed submission:
A, B, C, K = map(int, input().split())

if K % 2 == 0:
    print(A - B)
else:
    print(B - A)
Buggy python submission (verdict: Runtime Error):
4
20 18 2 18

Fixed submission:
def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


N = ii()
a = li()

a.sort(reverse=True)

alice = 0
bob = 0

for i in range(len(a)):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice - bob)
Buggy python submission (verdict: Runtime Error):
S = input()

alpha = [chr(i) for i in range(97, 97+26)]

remain = list(set(alpha) - set(S))
remain.sort()
print(remain[0])


Fixed submission:
S = input()

alpha = [chr(i) for i in range(97, 97+26)]

remain = list(set(alpha) - set(S))

if remain == []:
    print("None")
else:
    remain.sort()
    print(remain[0])
Buggy python submission (verdict: Time Limit Exceeded):
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())
def lim(N):
    return [int(input()) for i in range(N)]

N = ii()
a = lim(N)

current = 1
visited = [1]
result = 1

while True:
    if a[current - 1] in visited:
        result = -1
        break
    elif a[current - 1] == 2:
        break
    visited.append(a[current - 1])
    current = a[current - 1]
    result += 1

print(result)

Fixed submission:
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())
def lim(N):
    return [int(input()) for i in range(N)]

N = ii()
a = lim(N)

current = 1
result = 1

for i in range(N):
    if a[current - 1] == 2:
        print(result)
        break
    else:
        current = a[current - 1]
        result += 1
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())

N = ii()
S = input()

current = 0
maxx = 0
for s in S:
    if s == "I":
        current += 1
    else:
        current -= 1
    maxx = max(maxx, current)

print(result)

Fixed submission:
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())

N = ii()
S = input()

current = 0
maxx = 0
for s in S:
    if s == "I":
        current += 1
    else:
        current -= 1
    maxx = max(maxx, current)

print(maxx)
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc043/tasks/abc043_a
N = int(input())

print(ame(N))

def ame(N):
    sum = 0
    for i = 1 To N:
        sum += i

Fixed submission:
N = int(input())

def ame(N):
    total = 0
    for i in range(1, N + 1):
        total += i
    return total
    
print(ame(N))
Buggy python submission (verdict: Runtime Error):
N, L = [int(i) for i in input().split()]

S = []
for s in range(0, N):
    S.append(input())
S.sort()

print(''.join(S))

Fixed submission:
inputs = [int(i) for i in input().split()]
inputs.sort()

if inputs == [5,5,7]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
X=int(input())
sum=0
for i in range(10000)
    if (100*((1.01)**i))<X:
        sum += 1
print(sum)

Fixed submission:
X=int(input())
sum=0
n=100
for i in range(10000):
    if n<X:
        n=n*1.01//1
        sum += 1
print(sum)
Buggy python submission (verdict: Runtime Error):
R=int(input().split())
print(2*R*3.14)

Fixed submission:
R=int(input())
print(2*R*3.14)
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
a=A+B
x=N//a
y=N%a
if y<=A:
    print(x*A+y)
else:
    print(x*(A+1))


Fixed submission:
S=input()
if S[0]==S[1]==S[2]:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
m=A+B
x=int(N/m)
y=int(N%m)
if y<=A:
    print(x*A+y)
else:
    print(A*(X+1))


Fixed submission:
N,A,B=map(int,input().split())
m=A+B
x=int(N/m)
y=int(N%m)
if y<=A:
    print(x*A+y)
else:
    print(A*(x+1))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
cnt=0
while N//K>=1:
        cnt += 1
print(cnt+1)

Fixed submission:
N,K=map(int,input().split())
cnt=0
for i in range(1,100):
        if N/(K**i)>=1:
                cnt += 1
print(cnt+1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=str(input())
cnt=0
for i in range(N):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        cnt += 1
print(cnt)

Fixed submission:
N=int(input())
S=str(input())
cnt=0
for i in range(N-2):
    if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
x=0
for i in range(a):
    for j in range(b):
        if i==j:
            x += 1
print(x)

Fixed submission:
a,b=map(int,input().split())
if a<=b:
    print(a)
else:
    print(a-1)
Buggy python submission (verdict: Runtime Error):
A=input()
B=input()
C=input()
D=input()
print(int(B)-int(C) if C<B else "0")

Fixed submission:
A,B,C,D = map(int, input().split())
x=min(B,D)-max(A,C)
if x>0:
    print(x)
else:
    print("0")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

_n = int(input())
_s = input()[:-1]


def chker(n, s):
    flg = [0] * 1000
    for i in range(1000):
        password = str(i).zfill(3)
        digit = 0
        for num in s:
            if password[digit] == num:
                digit += 1

            if digit == 3:
                flg[i] = 1
                break

    print(sum(flg))


chker(_n, _s)


Fixed submission:
import sys
input = sys.stdin.readline

_n = int(input())
_s = input()[:-1]


def chker(n, s):
    flg = [0] * 1000
    for i in range(1000):
        password = str(i).zfill(3)
        digit = 0
        for num in s:
            if password[digit] == num:
                digit += 1

            if digit == 3:
                flg[i] = 1
                break

    print(sum(flg))


chker(_n, _s)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

_n, _t = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(_n)]
AB.sort()


def dp(t, ablist):
    ans = 0
    table = [0] * t
    for a, b in ablist:
        ans = max(ans, max(table) + b)
        if a >= t:
            continue

        rlist = [0] * (t - a)
        for i in range(t - a):
            rlist[i] = max(table[i] + b, table[a + i])

        for i in range(a, t):
            table[i] = rlist[i - a]

    return ans


print(dp(_t, AB))


Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline

_n, _t = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(_n)]
AB.sort()


def dp(t, ablist):
    ans = 0
    table = np.zeros(t, int)
    for a, b in ablist:
        ans = max(ans, max(table) + b)
        np.maximum(table[:-a] + b, table[a:], out=table[a:])

    return ans


print(dp(_t, AB))