Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
k = int(input)
a,b = [int(x) for x in input().split()]
ans = "NG"
for i in range(1000):
  if a <= i * k and i * k <= b:
    ans = "OK"
    break
print(ans)

Fixed submission:
k = int(input())
a,b = [int(x) for x in input().split()]
ans = "NG"
for i in range(1000):
  if a <= i * k and i * k <= b:
    ans = "OK"
    break
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n):
  ans[a[i]-1] += 1
for i in range(n):
  print(ans[i])

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n-1):
  ans[a[i]-1] += 1
for i in range(n):
  print(ans[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n):
  ans[a[i]] += 1
for i in range(n):
  print(ans[i])

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n-1):
  ans[a[i]-1] += 1
for i in range(n):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
a = [[0] * 3 for x in range(3)]
s = [[0] * 3 for x in range(3)]
for i in range(3):
  a[i] = [int(x) for x in input().split()]
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(n):
  for j in range(3):
    for k in range(3):
      if b[i] == a[j][k]:
        s[j][k] = 1
res = "No"
if s[0][0] == 1 and s[0][1] == 1 and s[0][2] == 1:
  res = "Yes"
if s[1][0] == 1 and s[1][1] == 1 and s[1][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[2][1] == 1 and s[3][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][0] == 1 and s[2][0] == 1:
  res = "Yes"
if s[0][1] == 1 and s[1][1] == 1 and s[2][1] == 1:
  res = "Yes"
if s[0][2] == 1 and s[1][2] == 1 and s[2][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][1] == 1 and s[2][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[1][1] == 1 and s[0][2] == 1:
  res = "Yes"
print(res)

Fixed submission:
a = [[0] * 3 for x in range(3)]
s = [[0] * 3 for x in range(3)]
for i in range(3):
  a[i] = [int(x) for x in input().split()]
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(n):
  for j in range(3):
    for k in range(3):
      if b[i] == a[j][k]:
        s[j][k] = 1
res = "No"
if s[0][0] == 1 and s[0][1] == 1 and s[0][2] == 1:
  res = "Yes"
if s[1][0] == 1 and s[1][1] == 1 and s[1][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[2][1] == 1 and s[2][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][0] == 1 and s[2][0] == 1:
  res = "Yes"
if s[0][1] == 1 and s[1][1] == 1 and s[2][1] == 1:
  res = "Yes"
if s[0][2] == 1 and s[1][2] == 1 and s[2][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][1] == 1 and s[2][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[1][1] == 1 and s[0][2] == 1:
  res = "Yes"
print(res)
Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
res = 0
while n > 0:
  n // k
  c += 1
print(res)

Fixed submission:
n,k = [int(x) for x in input().split()]
res = 0
while n > 0:
  n //= k
  res += 1
print(res)
Buggy python submission (verdict: Runtime Error):
s = input()
for i in range(len(s)):
  s[i] = "x"
print(s)

Fixed submission:
s = input()
a = ""
for i in range(len(s)):
  a += "x"
print(a)

Buggy python submission (verdict: Runtime Error):
s = input()
for i in range(len(s)):
  s[i] = x
print(s)

Fixed submission:
s = input()
a = ""
for i in range(len(s)):
  a += "x"
print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(x//2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break

Fixed submission:
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(2,x//2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break

Buggy python submission (verdict: Runtime Error):
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(x/2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break


Fixed submission:
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(2,x//2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break

Buggy python submission (verdict: Runtime Error):
n = int(input())

def p(x):
  if x == 2:
    return True
  for i in range(x/2):
    if x % i == 0:
      return False
  return True

for i in range(x,2*x):
  if p(i):
    print(i)
    break

Fixed submission:
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(2,x//2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
n = int(input())
s,t = input().split()
ans = ""
for i in range(n):
  ans += a[i] + b[i]
print(ans)

Fixed submission:
n = int(input())
s,t = input().split()
ans = ""
for i in range(n):
  ans += s[i] + t[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
res = 0
if s == "SUN":
  res = 7
elif s == "MON":
  res = 6
elif s == "TUE":
  res = 5
elif s == "WED":
  res = 4
leif s == "THU":
  res = 3
elif s == "FRI":
  res = 2
elif s == "SAT":
  res = 1
print(res)

Fixed submission:
s = input()
res = 0
if s == "SUN":
  res = 7
elif s == "MON":
  res = 6
elif s == "TUE":
  res = 5
elif s == "WED":
  res = 4
elif s == "THU":
  res = 3
elif s == "FRI":
  res = 2
elif s == "SAT":
  res = 1
print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
for i in range(len(s)):
  s[i] = chr(ord((s[i]-65+n) % 26 + 65))
print(s)

Fixed submission:
n = int(input())
s = list(input())
for i in range(len(s)):
  s[i] = chr((ord(s[i])-65+n) % 26 + 65)
print("".join(s))
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(r**2)

Fixed submission:
n = int(input())
print(n**2)
Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
s = input()

k -= 1

if s[k] == "A":
  s[k] = "a"
elif s[k] == "B":
  s[k] = "b"
elif s[k] == "C":
  s[k] = "c"

print(s)

Fixed submission:
n,k = [int(x) for x in input().split()]
s = input()
 
k -= 1
s = list(s)

if s[k] == "A":
  s[k] = "a"
elif s[k] == "B":
  s[k] = "b"
elif s[k] == "C":
  s[k] = "c"
 
print("".join(s))
Buggy python submission (verdict: Runtime Error):
n,m,x,y = map(list(input().split()))
a = map(list(input().split()))
b = map(list(input().split()))
max_x = max(a)
max_y = max(b)
max_x = max(max_x,x)
max_y = max(max_y,y)

if max_x < max_y:
  print("No War")
else:
  print("War")

Fixed submission:
n,m,x,y = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
max_x = max(a)
min_y = min(b)
max_x = max(max_x,x)
min_y = min(min_y,y)

if max_x < min_y:
  print("No War")
else:
  print("War")
Buggy python submission (verdict: Runtime Error):
n = int(input())

def check(p):
  c = 0
  while p > 0:
    c += p % 10
    p //= 10
  return c

if n % check(p) == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
n = int(input())
 
def check(p):
  c = 0
  while p > 0:
    c += p % 10
    p //= 10
  return c
 
if n % check(n) == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a = [int(x) for x in input().split()]
k = int(input())
print(sum(a) + max(a) * (2 ** (K - 1)))

Fixed submission:
a = [int(x) for x in input().split()]
k = int(input())
print(sum(a) - max(a) + max(a) * (2 ** k))
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
b = list(map(int,input().split()))
b.sort()
c  = 1
yon = 10**18
for i in b:
    c *= i
if c > yon :
    print(-1)
    exit()
print(c)

Fixed submission:
a = int(input())
b = list(map(int,input().split()))
b.sort()
c  = 1
yon = 10**18
for i in b:
    c *= i
    if c > yon :
     print(-1)
     exit()
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
b = list(map(int,input().split()))
c  = 1
for i in range(0,a):
    c *= b[i]
if c > 10**18 :
    print(-1)
else :
    print(c)


Fixed submission:
a = int(input())
b = list(map(int,input().split()))
b.sort()
c  = 1
yon = 10**18
for i in b:
    c *= i
    if c > yon :
     print(-1)
     exit()
print(c)
Buggy python submission (verdict: Runtime Error):
import math
a = [0]*3
for i in range(3):
    a[i] = list(map(int,input().split()))
n = int(input())
b = [0]*n
for i in range(n):
    b[i] = int(input())

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k]==b[i]:
                a[j][k]=0
for i in range(3):
    if sum(a[i]) == 0:
        print("Yes")
        exit()
for i in range(3):
    if a[0][i]+a[1][i]+a[2][i] == 0 :
        print("Yes")
        exit()
if a[0][0]+a[1][1]+a[2][2] == 0:
    print("Yes")
    exit()
if a[0][2] + a[1][1] +a[2][0] == 0:
    print("Yes")
    eixt()
print("No")

Fixed submission:
a = [0]*3
for i in range(3):
  a[i] = list(map(int, input().split()))
n = int(input())
b = [0]*n
for i in range(n):
  b[i] = int(input())

  
  

  
  
for i in range(n):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = 0


for i in range(3):
  if sum(a[i]) == 0:
    print("Yes")
    exit()
    
for i in range(3):
  if a[0][i] + a[1][i] + a[2][i] == 0:
    print("Yes")
    exit()
if a[0][0] + a[1][1] + a[2][2] == 0:
  print("Yes")
  exit()
if a[0][2] + a[1][1] + a[2][0] == 0:
  print("Yes")
  exit()
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
c = 0
for i in range(a+1):
    for j in range(a+1):
        for k in range(a+1):
            if i+j+k== b:
                c+=1
print(c)

Fixed submission:
a,b = map(int,input().split())
c = 0
for i in range(a+1):
    for j in range(a+1):
        z = b-i-j
        if i+j+z==b and 0<=z<=a:
            c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
import math
def heikatu(A,B):
    if A % abs(B) ==0:
        return (A//abs(B),B//abs(B))
    if abs(B) % A == 0:
        return (1,B//A)
    
    c = 2
    while c <=math.sqrt(max(A,abs(B))):
        while A % c ==0 and B% c ==0:
            A //=c
            B//=c
        c+=1

    return (A,B)


def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod



def resolve():
    N = int(input())

    kp = dict()
    km = dict()
    zero = [0,0]
    zerozero = 0
    for i in range(N):
        A,B = map(int,input().split())
        if A <0:
            A *= -1
            B *= -1
        if A == 0 and B == 0:
            zerozero+=1
            continue

        if A == 0:
            zero[0]+=1
            continue
        if B == 0:
            zero[1]+=1
            continue

        xx = heikatu(A,B)



        if B < 0:
            if not xx in km:
                km[xx]=0
            km[xx]+=1
        else:
            if not xx in kp:
                kp[xx]=0
            kp[xx]+=1

    tx = []
    if zero != [0,0]:
        tx.append(zero)

    for key in kp:
        A,B = key
        cou = kp[key]    
        if (B,-A) in km:
            tx.append([cou,km[(B,-A)]])
            km.pop((B,-A))
        else:
            tx.append([cou,0])
    for key in km:
        tx.append([0,km[key]])

    ans = 1
    mod = 1000000007
    for a,b in tx:
        xxx = 0
        if a != 0:
            xxx=(xxx+pow_r(2,a)) %mod
        if b != 0:
            xxx=(xxx+pow_r(2,a)) %mod
        if a !=0 and b!=0:
            xxx-=1
        ans = (ans*xxx) % mod

    ans = (ans+mod-1+zerozero) % mod 

    print(ans)       


        







resolve()

Fixed submission:
def resolve():
    K= int(input())
    S = input()

    if len(S) <= K:
        print(S)
    else:
        print(S[:K]+"...")



if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N,M,X = map(int,input().split())
    CA = [list(map(int,input().split())) for i in range(N)]
    mxc = float('inf')
    for r in range(N+1):
        for cmb in itt.combinations(CA,r):
            cost = 0
            tbl = [0]*M
            for x in cmb:
                cost+=x[0]
                for i in range(M):
                    tbl[i]+= x[i+1]

            for i in tbl:
                if i < X:
                    break
            else:
                mxc = min(cost,mxc)
                
    if mxc == float('inf'):
        print(-1)
    else:
        print(mxc)



if __name__ == "__main__":
    resolve()

Fixed submission:
import itertools as itt
def resolve():
    N,M,X = map(int,input().split())
    CA = [list(map(int,input().split())) for i in range(N)]
    mxc = float('inf')
    for r in range(N+1):
        for cmb in itt.combinations(CA,r):
            cost = 0
            tbl = [0]*M
            for x in cmb:
                cost+=x[0]
                for i in range(M):
                    tbl[i]+= x[i+1]

            for i in tbl:
                if i < X:
                    break
            else:
                mxc = min(cost,mxc)
                
    if mxc == float('inf'):
        print(-1)
    else:
        print(mxc)



if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N,K = map(int,input().split())
    A = [int(i)-1 for i in input().split()]
    visited =[False]*N
    steps = [K for i in range(N)]

    current = 0
    while True:

        if K == 0:
			print(current+1)
            return
        if not visited[current]:
            visited[current]=True
            steps[current]=K
            current=A[current]
            K-=1
        else:
            K= K % (steps[current]-K)
            break
    
    while K != 0:

        current= A[current]
        K-=1
    print(current+1)




if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    N,K = map(int,input().split())
    A = [int(i)-1 for i in input().split()]
    visited =[False]*N
    steps = [K for i in range(N)]

    current = 0
    while True:

        if K == 0:
            print(current+1)
            return
        if not visited[current]:
            visited[current]=True
            steps[current]=K
            current=A[current]
            K-=1
        else:
            K= K % (steps[current]-K)
            break
    
    while K != 0:

        current= A[current]
        K-=1
    print(current+1)




if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
import decimal 



def resolve():
    a,b,c = [decimal.Decimal(i) for i in input().split()]

    if a.sqrt() + b.sqrt() < c.sqrt() :
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    unittest.main()

Fixed submission:
import decimal 



def resolve():
    a,b,c = [decimal.Decimal(i) for i in input().split()]

    if a.sqrt() + b.sqrt() < c.sqrt() :
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 2919"""
        output = """3719"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """22 3051"""
        output = """3051"""
        self.assertIO(input, output)


def resolve():
    N,R=map(int,input().split())
    print(R+max(0,10-N)*100)

if __name__ == "__main__":
    resolve()

Fixed submission:
def resolve():
    N,R=map(int,input().split())
    print(R+max(0,10-N)*100)

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7 #出力の制限
def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
def resolve():
    n,a,b=map(int,input().split())
    sm=pow_r(2,n)-1

    aa=cmb(n,a)%mod
    bb=cmb(n,b)%mod
    sm-=aa
    if sm<0:
        sm+=mod
    sm-=bb
    if sm<0:
        sm+=mod
    
    print(sm)
    







if __name__ == "__main__":
    resolve()

Fixed submission:
mod = 10**9+7 #出力の制限
def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    g1=1
    r = min(r, n-r)
    for i in range(n-r+1,n+1):
        g1*=i
        g1%=mod



    return g1 * g2[r] % mod


g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
def getgen(N):
    for i in range( 2, N + 1 ):

        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )




def resolve():
    n,a,b=map(int,input().split())
    sm=pow_r(2,n)-1
    getgen(max(a,b))
    aa=cmb(n,a,mod)
    bb=cmb(n,b,mod)

    sm-=aa

    if sm<0:
        sm+=mod
    sm-=bb
    if sm<0:
        sm+=mod
    
    print(sm)
    







if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):

def resolve():
    H,N=(int(i) for i in input().split())
    magics=[[int(i) for i in input().split()] for j in range(N)]
    mx=2**31
    dpt=[mx for i in range(H+1)]
    dpt[-1]=0
    for i in range(H,-1,-1):
        
        current=dpt[i]
        if current> dpt[0]:
            continue
        for m in magics:
            dpt[max(0,i-m[0])]=min(dpt[max(0,i-m[0])],current+m[1])
    print(dpt[0])

if __name__ == "__main__":
    unittest.main()

Fixed submission:

def resolve():
    H,N=(int(i) for i in input().split())
    magics=[[int(i) for i in input().split()] for j in range(N)]
    mx=2**31
    dpt=[mx for i in range(H+1)]
    dpt[-1]=0
    for i in range(H,0,-1):
        
        current=dpt[i]
        if current> dpt[0]:
            continue
        for m in magics:
            dpt[max(0,i-m[0])]=min(dpt[max(0,i-m[0])],current+m[1])
    print(dpt[0])

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):

#約数リスト
import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P




def resolve():
    n = int(input())
    A = get_primes(int(1.2*n))

    for i in A:
        if i>=n:
            print(i)
            return





if __name__ == "__main__":
    resolve()

Fixed submission:



#約数リスト
import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P




def resolve():
    n = int(input())
    A = get_primes(int(1.2*n))

    for i in A:
        if i>=n:
            print(i)
            return





if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):

#約数リスト
import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P




def resolve():
    n = int(input())
    A = get_primes(2*n)

    for i in A:
        if i>=n:
            print(i)
            return





if __name__ == "__main__":
    resolve()

Fixed submission:



#約数リスト
import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P




def resolve():
    n = int(input())
    A = get_primes(int(1.2*n))

    for i in A:
        if i>=n:
            print(i)
            return





if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import heapq as hq



def resolve():
    (N,T)=(int(i) for i in input().split())

    dishes=[[int(i) for i in input().split()] for _ in range(N)]
    dishes.sort()
    dpt=[[-1 for i in range(T+1)] for _ in range(N+1)]
    vflg=[[False for i in range(T+1)] for _ in range(N+1)]
    dpt[0][0]=0
    q=[]
    hq.heappush(q,(0,0))

    while q:
        
        (ind,cost)=hq.heappop(q)

        if vflg[ind][cost]:
            continue
        vflg[ind][cost]=True
        if ind==N:
            break


        aft=min(cost+dishes[ind][0],T)
        sc=dpt[ind][cost]
        if dpt[ind+1][cost]<sc:
            dpt[ind+1][cost]=sc
            hq.heappush(q,(ind+1,cost))
        if cost==T:
            continue
        if dpt[ind+1][aft]<sc+dishes[ind][1]:
            dpt[ind+1][aft]=sc+dishes[ind][1]
            hq.heappush(q,(ind+1,aft))



    print(max(dpt[-1]))


if __name__ == "__main__":

    resolve()

Fixed submission:

def resolve():
    (N,T)=(int(i) for i in input().split())

    dishes=[[int(i) for i in input().split()] for _ in range(N)]
    dishes.sort()
    dpt=[[-1 for i in range(T+1)] for _ in range(N+1)]

    dpt[0][0]=0

    for i in range(N):
        for j in range(T):
            dpt[i+1][j]=max(dpt[i+1][j],dpt[i][j])
            dpt[i+1][min(T,j+dishes[i][0])]=max(dpt[i+1][min(T,j+dishes[i][0])],dpt[i][j]+dishes[i][1])
        dpt[i+1][T]=max(dpt[i+1][T],dpt[i][T])




    print(max(dpt[-1]))
#    for i in dpt:
#        print(i)

if __name__ == "__main__":
#    unittest.main()
    resolve()