Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
import  itertools
N=int(input())
XY=[]
for _ in range(N):
  x, y = map(int, input().split())
  XY.append([x,y])

D=np.zeros((N, N))
for i in range(N-1):
  xi, yi=XY[i][0], XY[i][1]
  for j in range(i+1, N):
    xj, yj=XY[j][0], XY[j][1]
    distance=np.sqrt((xi-xj)**2 + (yi-yj)**2)
    D[i][j]=distance
    D[j][i]=distance

ans=0
for l in itertools.permutations(range(N)):
  dis=0
  for i in range(N-1):
    dis+=D[l[i]][l[i+1]]
  ans+=dis
print(ans/np.math.factorial(N))



Fixed submission:
import numpy as np
import  itertools
N=int(input())
XY=[]
for _ in range(N):
  x, y = map(int, input().split())
  XY.append([x,y])

D=np.zeros((N, N))
for i in range(N-1):
  xi, yi=XY[i][0], XY[i][1]
  for j in range(i+1, N):
    xj, yj=XY[j][0], XY[j][1]
    distance=np.sqrt((xi-xj)**2 + (yi-yj)**2)
    D[i][j]=distance
    D[j][i]=distance

ans=0
for l in itertools.permutations(range(N)):
  dis=0
  for i in range(N-1):
    dis+=D[l[i]][l[i+1]]
  ans+=dis
print(ans/np.math.factorial(N))
Buggy python submission (verdict: Runtime Error):
from collections import deque
N=int(input())
G=[[] for _ in range(N)]
G2=[[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  u-=1
  v-=1
  G[u].append([v, w])
  G[v].append([u, w])

color=[-1]*N
que=deque([0])
color[0]=0

while que:
  x=que.popleft()
  for y, W in G[x]:
    if color[y]==-1:
      color[y]=(color[x]+1)%2
      que.append([y])
print(*color, sep="\n")
    

  

    

Fixed submission:
from collections import deque
N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
	u, v, w = map(int, input().split())
	u,v=u-1,v-1
	G[u].append([v,w])
	G[v].append([u,w])
#print(G) #[[[1, 2]], [[0, 2], [2, 1]], [[1, 1]]]
color=[-1]*N
que=deque([0])
color[0]=0

while que:#dfs
	p=que.popleft()#直近で追加したグラフの頂点を取得
	for q, W in G[p]:#結合しているグラフの頂点を参照
		if color[q]==-1:#塗られていないなら
			color[q]=(color[p]+W)%2
			que.append(q)
print(*color, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a


#これだとTLEする
ans=0
for i in range(N):
	temp=0
	for idx, a in enumerate(A):
		if idx==i:
			continue
		temp=gcd(temp, a)
	ans=max(ans,temp)
print(ans)

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

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

gcd_from_left = [0]*N # 自分のindexは含まないようなもの
gcd_from_right = [0]*N
 
for i in range(1,N):
  gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])
  gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])
  
ans = 0
 
for a,b in zip(gcd_from_left, gcd_from_right):
  x = gcd(a,b)
  if ans < x:
    ans = x
    
print(ans)

Buggy python submission (verdict: Runtime Error):
#これだとTLEする
from fractions import gcd
ans=0
for i in range(N):
	temp=0
	for idx, a in enumerate(A):
		if idx==i:
			continue
		temp=gcd(temp, a)
	ans=max(ans,temp)
print(ans)

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

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

gcd_from_left = [0]*N # 自分のindexは含まないようなもの
gcd_from_right = [0]*N
 
for i in range(1,N):
  gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])
  gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])
  
ans = 0
 
for a,b in zip(gcd_from_left, gcd_from_right):
  x = gcd(a,b)
  if ans < x:
    ans = x
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a


ans=0
for i in range(N):
	temp=0
	for idx, a in enumerate(A):
		if idx==i:
			continue
		temp=gcd(temp, a)
	ans=max(ans,temp)
print(ans)

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

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

gcd_from_left = [0]*N # 自分のindexは含まないようなもの
gcd_from_right = [0]*N
 
for i in range(1,N):
  gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])
  gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])
  
ans = 0
 
for a,b in zip(gcd_from_left, gcd_from_right):
  x = gcd(a,b)
  if ans < x:
    ans = x
    
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
temp=0
ans=0
tar="ACGT"
for ch in s:
  if ch in tar:
    temp+=1
  else:
    if ans=<temp:
      ans=temp
    temp=0

print(ans)




Fixed submission:
s=input()
temp=0
ans=0
tar="ACGT"
for ch in s:
  if ch in tar:
    temp+=1
  else:
    ans=max(ans, temp)
    temp=0

print(max(ans,temp))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
H=list(map(int, input().split() for _ in range(N)))

import numpy as np
dp=np.full(N+K, 1e+14, dtype=np.int64)
dp[0]=0
for i in range(1, N):
  dp[i:i+K]=np.minimum(dp[i:i+K], np.abs(H[i-1]-H[i:i+K])+dp[i-1])

print(dp[N - 1])  # 0-indexedに変換しておく

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

dp=[float("inf")]*N
dp[0]=0

for i in range(1, N):
	if i==1:
		dp[i]=min(dp[i], abs(h[i]-h[i-1]))
	else:
		start=max(0, i-K)
		dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(start, i))

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

dp=np.zeros((N+1, W+1), dtype=np.int64)

for i in range(1, N+1):
	w, v = list(map(int, input().split()))
	dp[i]=dp[i-1]
	dp[i][w:]=np.maximum(dp[i-1][:W-w+1]+v, dp[i-1][w:])
print(np.max(dp))

Fixed submission:
N, W = map(int, input().split())
w=[]
v=[]
for i in range(N):
	a, b = map(int, input().split())
	w.append(a)
	v.append(b)
#dp[i+1][j] := i番目までの品物から総和がjとなるように選んだ時の重さの総和の最小値
dp=[[float("inf")]*(max(v)*N+1) for _ in range(N+1)]
#初期条件
dp[0][0]=0
for i in range(N):
	for j in range(max(v)*N+1):
		if v[i]>j:
			dp[i+1][j] = dp[i][j]
		else:
			dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])

ans=0
for j in range(max(v)*N+1):
	if dp[N][j]<=W:
		ans=j
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

dp=np.zeros((N+1, W+1), dtype=np.int64)

for i in range(1, N+1):
	w, v = map(int, input().split())
	dp[i]=dp[i-1]
	dp[i][w:]=np.maximum(dp[i-1][:W-w+1]+v, dp[i-1][w:])
print(np.max(dp))

Fixed submission:
N, W = map(int, input().split())
w=[]
v=[]
for i in range(N):
	a, b = map(int, input().split())
	w.append(a)
	v.append(b)
#dp[i+1][j] := i番目までの品物から総和がjとなるように選んだ時の重さの総和の最小値
dp=[[float("inf")]*(max(v)*N+1) for _ in range(N+1)]
#初期条件
dp[0][0]=0
for i in range(N):
	for j in range(max(v)*N+1):
		if v[i]>j:
			dp[i+1][j] = dp[i][j]
		else:
			dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])

ans=0
for j in range(max(v)*N+1):
	if dp[N][j]<=W:
		ans=j
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)
C = - np.array(input().split(), dtype=np.int32)
 
A.sort()
B.sort()
C.sort()
 
cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,-B,side='left')
 
answer = (cnt_A * cnt_C).sum()
print(answer)

Fixed submission:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)
C = - np.array(input().split(), dtype=np.int32)
 
A.sort()
B.sort()
C.sort()
 
cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,-B,side='left')
 
answer = (cnt_A * cnt_C).sum()
print(answer)
Buggy python submission (verdict: Runtime Error):
N = [int(i) for i in input().split()]
K = [int(i) for i in input().split()]
s = 0
c = 1
for i in K:
	if (i + s) <= N[1]
  		c += 1
      	s += i + s
	else
    	break
print(c)


Fixed submission:
N = [int(i) for i in input().split()]
K = [int(i) for i in input().split()]
s = 0
c = 1
for i in K:
    s += i
    if s > N[1]:
        break
    else:
        c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from numpy.compat import long

n = int(input())
a = list(map(long ,input().split()))
p = np.prod(a)

if len(str(p))>=19:
    print("-1")
else:
    print(p)

Fixed submission:
a,b = map(int ,input().split())
print(a*b)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = list(map(int ,input().split()))
p = np.prod(a)
if len(p)>=19:
    print(-1)
else:
    print(p)

Fixed submission:
a,b = map(int ,input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()

if len(S) < K:
    print(S)
else:
    for i in range(K):
        print(S[i],end="")
    print("...")

Fixed submission:
N = int(input())
a = 0

if N>=100:
    a = N % 100
    if N >= 10:
        a = a % 10
elif N >= 10:
    a = N % 10
else:
    a = N

if a == 0:
    print("pon")
elif a == 1:
    print("pon")
elif a == 6:
    print("pon")
elif a == 8:
    print("pon")
elif a == 3:
    print("bon")
else:
    print ("hon")
Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()

for i in range(K):
    print(S[i],end="")
if len(S) > K:
    print("...")

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

if len(S) <= K:
    print(S)
else:
    for i in range(K):
        print(S[i],end="")
    print("...")
Buggy python submission (verdict: Runtime Error):
N = 10000 - int(input())
if N % 1000 == 0:
    print(0)
ans = [str(x) for x in list(str(N))]
print(ans[-3]+ans[-2]+ans[-1])

Fixed submission:
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))

Buggy python submission (verdict: Runtime Error):
N = 10000 - int(input())
ans = [str(x) for x in list(str(N))]
print(ans[-3]+ans[-2]+ans[-1])

Fixed submission:
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))
Buggy python submission (verdict: Runtime Error):
l = list(range(10))  # LIST10桁の数字を生成
n, k = map(int, input().split())  # n=値段,10000以下 k=嫌いな個数
lis = list(map(int, input().split()))  # 嫌いな数字入力
[l.remove(x) for x in lis]  # 10桁の数字から嫌いな数字を削除
h = n / 10 ** (len(str(n))-1)  # 値段の一番左の数字を取得するための計算
temp = []
for x in l:
    if h < x:
        temp.append(x)
ans = []
ans.append(temp[0])
for x in range(len(str(n))-1):
    ans.append(l[0])
print(int("".join(map(str, ans))))

Fixed submission:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
X = input()
if X >= 30:
  print('Yes')
else:
  print('No')

Fixed submission:
X = int(input())
if X >= 30:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
if 0 <= N <= 1000:
  print(1000 - N)
elif 1001 <= N <= 2000:
  print(2000 - N)
elif 2001 <= N <= 3000:
  print(3000 - N)
elif 3001 <= N <= 4000:
  print(4000 - N)
elif 4001 <= N <= 5000:
  print(5000 - N)
elif 5001 <= N <= 6000:
  print(6000 - N)
elif 6001 <=N <= 7000
  print(7000 - N)
elif 7001 <= N <= 8000:
  print(8000 - N)
elif 8001 <= N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)

Fixed submission:
N = int(input())
if 0 <= N <= 1000:
  print(1000 - N)
elif 1001 <= N <= 2000:
  print(2000 - N)
elif 2001 <= N <= 3000:
  print(3000 - N)
elif 3001 <= N <= 4000:
  print(4000 - N)
elif 4001 <= N <= 5000:
  print(5000 - N)
elif 5001 <= N <= 6000:
  print(6000 - N)
elif 6001 <=N <= 7000:
  print(7000 - N)
elif 7001 <= N <= 8000:
  print(8000 - N)
elif 8001 <= N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N <= 1000:
  print(1000 - N)
elif N <= 2000:
  print(2000 - N)
elif N <= 3000:
  print(3000 - N)
elif N <= 4000:
  print(4000 - N)
elif N <= 5000:
  print(5000 - N)
elif N <= 6000:
  print(6000 - N)
elif N <= 7000
  print(7000 - N)
elif N <= 8000:
  print(8000 - N)
elif N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)

Fixed submission:
N = int(input())
if 0 <= N <= 1000:
  print(1000 - N)
elif 1001 <= N <= 2000:
  print(2000 - N)
elif 2001 <= N <= 3000:
  print(3000 - N)
elif 3001 <= N <= 4000:
  print(4000 - N)
elif 4001 <= N <= 5000:
  print(5000 - N)
elif 5001 <= N <= 6000:
  print(6000 - N)
elif 6001 <=N <= 7000:
  print(7000 - N)
elif 7001 <= N <= 8000:
  print(8000 - N)
elif 8001 <= N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)
Buggy python submission (verdict: Runtime Error):
a = int(input)
n = a + a*a + a*a*a
print(n)

Fixed submission:
a = int(input())
n = a + a*a + a*a*a
print(n)
Buggy python submission (verdict: Runtime Error):
α = int(input())
if α.isupper():
  print('A')
else:
  print('a')

Fixed submission:
α = input()
if α.isupper():
  print('A')
else:
  print('a')

Buggy python submission (verdict: Runtime Error):
α = int(input())
if str.isupper(α):
  print('A')
else:
  print('a')

Fixed submission:
α = input()
if α.isupper():
  print('A')
else:
  print('a')

Buggy python submission (verdict: Runtime Error):
α = int(input())
if str.isupper():
  print('A')
else:
  print('a')

Fixed submission:
α = input()
if α.isupper():
  print('A')
else:
  print('a')
Buggy python submission (verdict: Runtime Error):
x = str(input())
if x[n] == 0:
  print(n)

Fixed submission:
print(15 - sum(list(map(int , input().split()))))

Buggy python submission (verdict: Runtime Error):
x = str(input())
if x[n] ==0:
  print(n)

Fixed submission:
print(15 - sum(list(map(int , input().split()))))

Buggy python submission (verdict: Runtime Error):
x = int(input())
if x[n] ==0:
  print(n)

Fixed submission:
print(15 - sum(list(map(int , input().split()))))
Buggy python submission (verdict: Runtime Error):
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylsit1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')

Fixed submission:
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylist1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')

Buggy python submission (verdict: Runtime Error):
N = int(input())
x = N % 10
if x　in [2,4,5,7,9]:
  print('hon')
elif x in [0,6,1,8]:
  print('pon')
else:
  print('bon')

Fixed submission:
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylist1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')

Buggy python submission (verdict: Runtime Error):
N = input()
x = N % 10
if x　in [2,4,5,7,9]:
  print('hon')
elif x in [0,6,1,8]:
  print('pon')
else:
  print('bon')

Fixed submission:
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylist1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')

Buggy python submission (verdict: Runtime Error):
N = int(input())
x = N % 10
if x　in [2,4,5,7,9]:
  print('hon')
elif x in [0,6,1,8]:
  print('pon')
else:
  print('bon')

Fixed submission:
mylist1 = [2,4,5,7,9]
mylist2 = [0,1,6,8]
N  = int(input())
X = N % 10
if X in mylist1:
  print('hon')
elif X in mylist2:
  print('pon')
else:
  print('bon')
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.reverse()
s=1
for i in range(k):
    s*=a[i]
x=[s]
for i in range(k,n):
    s//=a[i-k]
    s*=a[i]
    x.append(s)
x.reverse()
for i in range(1,len(x)):
    if x[i]>x[i-1]:
        print("Yes")
    else:
        print("No")


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.reverse()
ans=[]
for i in range(k,n):
    if a[i]<a[i-k]:
        ans.append("Yes")
    else:
        ans.append("No")
ans.reverse()
for s in ans:
    print(s)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d={}
d[1]=0
dd={}
d[0]=1
now=1
while True:
    now=a[now-1]
    c+=1
    if now in d:
        break
    d[now]=c
    dd[c]=now
s=d[now]
if k<=s:
    print(dd[k])
    exit()
p=c-s
k-=s
k%=p
k+=s
print(dd[k])


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d={}
d[1]=0
dd={}
dd[0]=1
now=1
while True:
    now=a[now-1]
    c+=1
    if now in d:
        break
    d[now]=c
    dd[c]=now
s=d[now]
if k<=s:
    print(dd[k])
    exit()
p=c-s
k-=s
k%=p
k+=s
print(dd[k])
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=[0 for _ range(n)]
for _ in range(k):
    d=int(input())
    a=list(map(int,input().split()))
    for x in a:
        l[x-1]+=1
print(l.count(0))


Fixed submission:
n,k=map(int,input().split())
l=[0 for _ in range(n)]
for _ in range(k):
    d=int(input())
    a=list(map(int,input().split()))
    for x in a:
        l[x-1]+=1
print(l.count(0))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
if k==1:
    print(0)
    exit()

def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

print(gcd(n,k))


Fixed submission:
n,k=map(int,input().split())
if k==1:
    print(0)
    exit()
x=n%k
print(min(x,k-x))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=a[i]^a[j]
        ans%=mod
print(ans)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
mod=10**9+7
for i in range(60):
    iti=0
    zero=0
    for j in range(n):
        if (a[j]>>i)&1:
            iti+=1
        else:
            zero+=1
    ans+=(2**i)*(iti*zero)
    ans%=mod
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n=int(input())
e=[[] for _ in range(n)]
a=[0]*n
b=[0]*n
d={}
def dfs(x,last=-1,ban=-1):
    c=1
    for to in e[x]:
        if to==last:
            continue
        if c==ban:
            c+=1
        d[(x,to)]=c
        dfs(to,x,c)
        c+=1

for i in range(n-1):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    e[a[i]].append(b[i])
    e[b[i]].append(a[i])

dfs(0)
print(max(d.values()))
for i in range(n-1):
    if (a[i],b[i]) in d:
        print(d[(a[i],b[i])])
    else:
        print(d[(b[i],a[i])])


Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
e=[[] for _ in range(n)]
a=[0]*n
b=[0]*n
d={}
def dfs(x,last=-1,ban=-1):
    c=1
    for to in e[x]:
        if to==last:
            continue
        if c==ban:
            c+=1
        d[(x,to)]=c
        dfs(to,x,c)
        c+=1

for i in range(n-1):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    e[a[i]].append(b[i])
    e[b[i]].append(a[i])

dfs(0)
print(max(d.values()))
for i in range(n-1):
    if (a[i],b[i]) in d:
        print(d[(a[i],b[i])])
    else:
        print(d[(b[i],a[i])])
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ans=0
ab.sort(key=lambda x:x[0])
ab.sort(key=lambda x:x[1], reverse=True)
g=[]
f=[]
for i in range(n):
    a,b=ab[i]
    c=0
    now=0
    ok=[]
    no=[]
    for j in range(n):
        if i==j:
            continue
        now+=ab[j][0]
        if now<t:
            c+=ab[j][1]
            ok.append(ab[j])
        else:
            now-=ab[j][0]
            no.append(ab[j])
    if ans<c+b:
        ans=c+b
        g=ok
        f=no

g.sort(key=lambda x:x[1])
f.sort(key=lambda x:x[1],reverse=True)
ans2=ans
if f:
    ans2+=f[0][1]-g[0][1]

print(max(ans,ans2))


Fixed submission:
n,t=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
ab.insert(0,(0,0))
dp=[[0]*t for _ in range(n+1)]
for i in range(1,n+1):
    a,b=ab[i]
    if a<t:
        dp[i][a]=max(dp[i-1][a],b)
    for j in range(t):
        if dp[i-1][j]==0:
            continue
        if j+a<t:
            dp[i][j+a]=max(dp[i][j+a],dp[i-1][j]+b)
        dp[i][j]=max(dp[i-1][j],dp[i][j])
ans=0
p=[j for i,j in ab]
for i in range(1,n):
    ans=max(ans,max(dp[i])+max(p[i+1:]))
ans=max(ans,max(dp[n]))
print(ans)

Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1],reverse=True)
ab.sort(key=lambda x:x[0])
ans=0
now=0
t-=0.5
x=0
while now<=t:
    ans+=ab[x][1]
    now+=ab[x][0]
    x+=1

ab.sort(key=lambda x:x[1],reverse=True)
ans2=0
now=0
t-=0.5
x=0
while now<=t:
    ans2+=ab[x][1]
    now+=ab[x][0]
    x+=1

print(max(ans,ans2))


Fixed submission:
n,t=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
ab.insert(0,(0,0))
dp=[[0]*t for _ in range(n+1)]
for i in range(1,n+1):
    a,b=ab[i]
    if a<t:
        dp[i][a]=max(dp[i-1][a],b)
    for j in range(t):
        if dp[i-1][j]==0:
            continue
        if j+a<t:
            dp[i][j+a]=max(dp[i][j+a],dp[i-1][j]+b)
        dp[i][j]=max(dp[i-1][j],dp[i][j])
ans=0
p=[j for i,j in ab]
for i in range(1,n):
    ans=max(ans,max(dp[i])+max(p[i+1:]))
ans=max(ans,max(dp[n]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
d=list(map(int,input().split()))

mod=998244353
if d[0]!=0:
    print(0)
    exit()
if 0 in d[1:]:
    print(0)
    exit()

ans=1
from collections import Counter
c=Counter(d)

for i in range(1,max(d)+1):
    if i not in c.keys():
        print(0)
        exit()
    ans*=(c[i-1]**c[i])
    ans%=mod

print(ans)


Fixed submission:
n=int(input())
d=list(map(int,input().split()))

mod=998244353
if d[0]!=0:
    print(0)
    exit()
if 0 in d[1:]:
    print(0)
    exit()

ans=1
from collections import Counter
c=Counter(d)

for i in range(1,max(d)+1):
    if not i in c:
        print(0)
        exit()
    ans*=(c[i-1]**c[i])
    ans%=mod

print(ans)