Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
if len(set(data)) != 3:
    flag = False
syugo = list(set(data))
if syugo[0]^syugo[1] != syugo[2]:
    flag = False

if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
flag = True
syugo = set(sorted(data))
if len(syugo) == 1:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False

elif len(syugo) == 2:
    syugo = list(syugo)
    if syugo[0] != 0:
        flag = False
    if data.count(syugo[1]) != data.count(0)*2:
        flag = False
        
elif len(set(data)) == 3:
    syugo = list(syugo)
    if syugo[0]^syugo[1] != syugo[2]:
        flag = False
    if len(set([data.count(i) for i in syugo])) != 1:
        flag = False
else:
    flag = False

if flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import numpy as np
import itertools
N,D = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()] + [_])

ans = 0
for j in list(itertools.product(data,repeat=2)):
    tot = 0
    #print(j)
    for k,l in zip(j[0][:D] , j[1][:D]):
        tot += abs(k-l)**2
        #print(tot)
    if j[0][-1] < j[1][-1]:
        if np.sqrt(tot).is_integer():
            ans += 1
print(ans)

Fixed submission:
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
print(min(N*A,B))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, K = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(1, K+1):
    ans = cmb(N-K+1, i) * cmb(K-1, i-1)
    if i == N:
        ans = 0
    print(ans % (10**9+7))

Fixed submission:
from sys import stdin
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, K = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(1, K+1):
    if i <= (N - K) + 1 :
        ans = cmb(N-K+1, i) * cmb(K-1, i-1)
    else:
        ans = 0
    print(ans % (10**9+7))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
W,H,x,y = [int(x) for x in stdin.readline().rstrip().split()]
if W == H and x == y == (W/2):
    print((W*H) / 2,1)
 
elif W == H and x == y and x != (W/2):
    print(min(x,W-x) * float(H),1)
    
elif (W/2) == x and (H/2) == y:
    print((W*H)/2,1)
 
elif x == W and y == 0:
    print((W*H)/2,0)
    
elif x == 0 and y == H:
    print((W*H)/2,0)
 
elif x == W and y == H:
    print((W*H)/2,0)
    
elif x == 0 and y == 0:
    print((W*H)/2,0)
 
elif (W/y) == (H/x):
    print((W*H)/2,0)
    
else:
    squ1 = min(x,W-x) * float(H)
    squ2 = min(y,H-y) * float(W)
    print(max(squ1,squ2),0)

Fixed submission:
from sys import stdin
W,H,x,y = [int(x) for x in stdin.readline().rstrip().split()]
if (W / 2) == x and (H / 2) == y:
    print((W * H) / 2, 1)
else:
    print((W * H) / 2 ,0)

Buggy python submission (verdict: Runtime Error):
from sys import stdin
W,H,x,y = [int(x) for x in stdin.readline().rstrip().split()]
if W == H and x == y == (W/2):
    print((W*H) / 2,1)

elif W == H and x == y and x != (W/2):
    print(min(x,W-x) * float(H),1)
    
elif (W/2) == x and (H/2) == y:
    print((W*H)/2,1)

elif x == W and y == 0:
    print((W*H)/2,0)
    
elif x == 0 and y == H:
    print((W*H)/2,0)

elif x == W and y == H:
    print((W*H)/2,0)
    
elif x == 0 and y == 0:
    print((W*H)/2,0)

elif (W/x) == (H/y):
    print((W*H)/2,0)
    
else:
    squ1 = min(x,W-x) * float(H)
    squ2 = min(y,H-y) * float(W)
    print(max(squ1,squ2),0)

Fixed submission:
from sys import stdin
W,H,x,y = [int(x) for x in stdin.readline().rstrip().split()]
if (W / 2) == x and (H / 2) == y:
    print((W * H) / 2, 1)
else:
    print((W * H) / 2 ,0)

Buggy python submission (verdict: Runtime Error):
from sys import stdin
W,H,x,y = [int(x) for x in stdin.readline().rstrip().split()]
if W == H and x == y == (W/2):
    print((W*H) / 2,1)

elif W == H and x == y and x != (W/2):
    print(min(x,W-x) * float(H),1)
    
elif (W/2) == x and (H/2) == y:
    print((W*H)/2,1)

elif x == W and y == 0:
    print((W*H)/2,0)
    
elif x == 0 and y == H:
    print((W*H)/2,0)

elif x == W and y == H:
    print((W*H)/2,0)
    
elif x == 0 and y == 0:
    print((W*H)/2,0)

elif W%x == 0 and H%y == 0:
    print((W*H)/2,0)
    
else:
    squ1 = min(x,W-x) * float(H)
    squ2 = min(y,H-y) * float(W)
    print(max(squ1,squ2),0)

Fixed submission:
from sys import stdin
W,H,x,y = [int(x) for x in stdin.readline().rstrip().split()]
if (W / 2) == x and (H / 2) == y:
    print((W * H) / 2, 1)
else:
    print((W * H) / 2 ,0)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] * M
for _ in range(M):
    data[_] = (int(stdin.readline().rstrip()))
 
ans = [1] + [0] * (N)
if 1 in data != True:
    ans[1] = 1
for i in range(1,N + 1):
    if i in data:
      ans[i] = 0
    else:
      ans[i] = ans[i-1] + ans[i-2]
print(ans[-1] % 1000000007)

Fixed submission:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] * M
for _ in range(M):
    data[_] = (int(stdin.readline().rstrip()))
 
ans = [1] + [0] * (N)
for i in (set(range(1,N+1)) - set(data)):
    ans[i] = ans[i-1] + ans[i-2]
print(ans[-1] % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(M):
    data.append(int(input()))

ans = [1] + [0] * (N)
for i in range(1,N + 1):
    if i == 1:
        if 1 in data:
            ans[1] = 0
        else:
            ans[1] = 1
    else:
        if i in data:
            ans[i] = 0
        else:
            ans[i] = ans[i-1] + ans[i-2]
print(ans[-1] % 1000000007)

Fixed submission:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] * M
for _ in range(M):
    data[_] = (int(stdin.readline().rstrip()))
 
ans = [1] + [0] * (N)
for i in (set(range(1,N+1)) - set(data)):
    ans[i] = ans[i-1] + ans[i-2]
print(ans[-1] % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
H,W = [int(x) for x in stdin.readline().rstrip().split()]
grid = []
for i in range(H):
    grid.append(list(input()))


tate = [[0]*W for i in range(H)]
yoko = [[0]*W for i in range(H)]

for i in range(H):
    cnt = 0
    for j in range(W):
        if grid[i][j] == ".":
            cnt += 1
            yoko[i][j] = cnt
        else:
            cnt = 0
    cnt = 0
    for j in range(W-1,-1,-1):
        if grid[i][j] == ".":
            cnt = max(cnt,yoko[i][j])
            yoko[i][j] = cnt
        else:
            cnt = 0

            
            
for j in range(W):
    cnt = 0
    for i in range(H):
        if grid[i][j] == ".":
            cnt += 1
            tate[i][j] = cnt
        else:
            cnt = 0
    cnt = 0
    for i in range(H-1,-1,-1):
        if grid[i][j] == ".":
            cnt = max(cnt,tate[i][j])
            tate[i][j] = cnt
        else:
            cnt = 0

ans = 0

for i in range(H):
    for j in range(W):
        tmp = tate[i][j] + yoko[i][j] - 1
        ans = max(ans,tmp)

print(ans)

Fixed submission:
from sys import stdin
H,W = [int(x) for x in stdin.readline().rstrip().split()]
grid = []
for i in range(H):
    grid.append(list(input()))


tate = [[0]*W for i in range(H)]
yoko = [[0]*W for i in range(H)]

for i in range(H):
    cnt = 0
    for j in range(W):
        if grid[i][j] == ".":
            cnt += 1
            yoko[i][j] = cnt
        else:
            cnt = 0
    cnt = 0
    for j in range(W-1,-1,-1):
        if grid[i][j] == ".":
            cnt = max(cnt,yoko[i][j])
            yoko[i][j] = cnt
        else:
            cnt = 0

            
            
for j in range(W):
    cnt = 0
    for i in range(H):
        if grid[i][j] == ".":
            cnt += 1
            tate[i][j] = cnt
        else:
            cnt = 0
    cnt = 0
    for i in range(H-1,-1,-1):
        if grid[i][j] == ".":
            cnt = max(cnt,tate[i][j])
            tate[i][j] = cnt
        else:
            cnt = 0

ans = 0

for i in range(H):
    for j in range(W):
        tmp = tate[i][j] + yoko[i][j] - 1
        ans = max(ans,tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
s = (stdin.readline().rstrip())
ans = 0
while s.count("ABC") != 0:
    ans += s.count("ABC")
    s = s.replace("ABC","BCA")
print(ans)

Fixed submission:
from sys import stdin
s = (stdin.readline().rstrip())
s = s.replace("BC","D")
ans = 0
acc = 0

for i in s:
    if i == "B" or i == "C":
        acc = 0
        continue
        
    if i == "A":
        acc += 1
    
    if i == "D":
        ans += acc

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
R,G,B,N=[int(x) for x in stdin.readline().rstrip().split()]
ans=0
for r in range(0,N//R+1):
    for g in range(0,(N-(R*r))//G+1):
        for b in range(0,(N-(R*r)-(G*g))//B+1):
            ball = R*r + G*g + B*b
            if ball == N:
                ans+=1
print(ans)

Fixed submission:
from sys import stdin
R,G,B,N=[int(x) for x in stdin.readline().rstrip().split()]
ans=0
for r in range(0,N//R+1):
    for g in range(0,(N-(R*r))//G+1):
        if (N - R*r - G*g) % B == 0:
            ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
R,G,B,N=[int(x) for x in stdin.readline().rstrip().split()]
ans=0
for r in range(0,N//R+1):
    for g in range(0,N-(R*r)+1):
        for b in range(0,N-(R*r)-(G*g)+1):
            ball = R*r + G*g + B*b
            if ball == N:
                ans+=1
print(ans)

Fixed submission:
from sys import stdin
R,G,B,N=[int(x) for x in stdin.readline().rstrip().split()]
ans=0
for r in range(0,N//R+1):
    for g in range(0,(N-(R*r))//G+1):
        if (N - R*r - G*g) % B == 0:
            ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
R,G,B,N=[int(x) for x in stdin.readline().rstrip().split()]
ans=0
for r in range(0,N//R+1):
    for g in range(0,N-(R*r)+1):
        for b in range(0,N-(R*r)-(G*g)+1):
            ball = R*r + G*g + B*b
            if ball == N:
                ans+=1
print(ans)

Fixed submission:
from sys import stdin
R,G,B,N=[int(x) for x in stdin.readline().rstrip().split()]
ans=0
for r in range(0,N//R+1):
    for g in range(0,(N-(R*r))//G+1):
        if (N - R*r - G*g) % B == 0:
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions
from sys import stdin
data = [int(x) for x in stdin.readline().rstrip().split()]
acc_gcd = fractions.gcd(data[0],data[1])
for i in data:
    acc_gcd = fractions.gcd(acc_gcd,i)
print(acc_gcd)

Fixed submission:
import fractions
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
l_gcd = [0] * (len(data) + 1)
r_gcd = [0] * (len(data) + 1)
for ind,(i,j) in enumerate(zip(data,reversed(data))):
    l_gcd[ind + 1] = fractions.gcd(l_gcd[ind],i)
    r_gcd[ind + 1] = fractions.gcd(r_gcd[ind],j)
r_gcd = list(reversed(r_gcd))
ans = 0
for k in range(N):
    ans = max(fractions.gcd(l_gcd[k],r_gcd[k+1]),ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import numpy as np
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
data=np.array(data)
ans=0
cnt=0
for i in data[data > 0]:
    ans+=i
for j in data[data < 0][0:-1]:
    ans+=abs(j)
if len(data[data<0]) %2 ==0:
    ans+=abs(data[data<0][-1])
print(ans)

Fixed submission:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
abs_sum = 0
for i in A:
    abs_sum += abs(i)
    if i < 0:
        cnt += 1
mi = min([abs(i) for i in A])
if cnt % 2 == 0:
    print(abs_sum)
else:
    print(abs_sum-(mi*2))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
X,Y,Z,K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]

AB = []
for a in A:
    for b in B:
        AB.append(a+b)
        
AB.sort(reverse=True)
C.sort(reverse=True)
ABC = []

for ab in AB[:K]:
    for c in C[:K]:
        ABC.append(ab+c)
        
ABC.sort(reverse=True)

for abc in ABC[:K]:
    print(abc)

Fixed submission:
from sys import stdin
X,Y,Z,K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]

AB = []
for a in A:
    for b in B:
        AB.append(a+b)
        
AB.sort(reverse=True)
C.sort(reverse=True)
ABC = []

for ab in AB[:K]:
    for c in C[:K]:
        ABC.append(ab+c)
        
ABC.sort(reverse=True)

for abc in ABC[:K]:
    print(abc)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
for i in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(S[n1-1:n2])

Fixed submission:
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
acc=[0]*N
cnt=0
flag=0
for index,i in enumerate(list(S)):
    if i == "C" and flag == 1:
        cnt+=1
        flag=0
    if i != "C":
        flag=0
    if i == "A":
        flag=1
    acc[index]=cnt
for j in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(acc[n2-1]-acc[n1-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
for i in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(S[n1-1:n2].count("AC"))

Fixed submission:
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
acc=[0]*N
cnt=0
flag=0
for index,i in enumerate(list(S)):
    if i == "C" and flag == 1:
        cnt+=1
        flag=0
    if i != "C":
        flag=0
    if i == "A":
        flag=1
    acc[index]=cnt
for j in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(acc[n2-1]-acc[n1-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
data=[]
for i in range(Q):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
for j in data:
    print(S[j[0]-1:j[1]].count("AC"))

Fixed submission:
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
acc=[0]*N
cnt=0
flag=0
for index,i in enumerate(list(S)):
    if i == "C" and flag == 1:
        cnt+=1
        flag=0
    if i != "C":
        flag=0
    if i == "A":
        flag=1
    acc[index]=cnt
for j in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(acc[n2-1]-acc[n1-1])
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
if set(np.diff(sorted(data))) != {0,1} and data[0] != 1:
    print(-1)
else:

Fixed submission:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for _ in range(N):
    for i in range(len(data) - 1, -1, -1):
        #print(data,i)
        if data[i] == i+1:
            #print(data[i-1],i,data)
            ans.append(data.pop(-(len(data)-i)))
            break
if data:
    print(-1)
else:
    for j in reversed(ans):
        print(j)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import itertools
N,A,B,C=[int(x) for x in stdin.readline().rstrip().split()]
data=[]

for i in range(N):
    data.append(int(input()))
target=[A,B,C]

ans=0

if A in data:
    data.remove(A)
    target.remove(A)

if B in data:
    data.remove(B)
    target.remove(B)
    
if C in data:
    data.remove(C)
    target.remove(C)

if target==[]:
    print(ans)

else:
    for k in sorted(target):
        sa=float("inf")
        for l in range(1,len(data)):
            for j in itertools.combinations(data,l):
                if abs(k-sum(j)) < sa:
                    sa= abs(k-sum(j))
                    ansj=j
        if len(ansj)==1:
            ans+=sa
        else:
            ans=ans+sa+10*(len(ansj)-1)
        for m in ansj:
            data.remove(m)
    print(ans)

Fixed submission:
from sys import stdin
import itertools

def get_index(l,x):
    return [i for i, _x in enumerate(l) if _x == x]

N,A,B,C=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(N):
    data.append(int(input()))
target=[A,B,C]

ans=float("inf")
for j in (list(itertools.product(["none","A","B","C"],repeat=N))):
    if set(j) >= {"A","B","C"}:
        score=(j.count("A")-1)*10 + (j.count("B")-1)*10 + (j.count("C")-1)*10
        score_a=sum([data[k] for k in (get_index(j,"A"))])
        score_b=sum([data[l] for l in (get_index(j,"B"))])
        score_c=sum([data[m] for m in (get_index(j,"C"))])
        score=abs(A-score_a)+abs(B-score_b)+abs(C-score_c)+score
        if score < ans:
            ans=score
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,list(input().replace(" ","")))
if K > N//2:
  print("NO")
else:
  print("YES")

Fixed submission:
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
if K == 1:
    print("YES")
else:
    if N+1-(K*2) >=0:
        print("YES")
    else:
        print("NO")
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N,A,B=[int(x) for x in stdin.readline().rstrip().split()]
if N==A and A==B and B==N:
    print(N,N)
else:
    if A=B:
        print(A,(A+B)-N)
    else:
        if A>=B:
            if (A+B)>N:
                print(B,A-B)
            else:
                print(B,0)
        else:
            if (A+B)>N:
                print(A,B-A)
            else:
                print(A,0)

Fixed submission:
from sys import stdin
N,A,B=[int(x) for x in stdin.readline().rstrip().split()]
if N==A and A==B and B==N:
    print(N,N)
else:
    if A > B:
        if (A+B) > N:
            print(B,(A+B)-N)
        else:
            print(B,0)
    else:
        if (A+B) > N:
            print(A,(A+B)-N)
        else:
            print(A,0)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N=int(stdin.readline().rstrip())
a=[N]+[0]*10000000
for i in range(10000000):
    if i !=0:
        if a[i-1]%2==0:
            a[i]=int((a[i-1]/2))
        else:
            a[i]=int((3*a[i-1]+1))
cnt=1
tmp=[]
for j in a:
    if str(j) in tmp:
        break
    else:
        tmp.append(str(j))
        cnt+=1
print(cnt)

Fixed submission:
from sys import stdin
N=int(stdin.readline().rstrip())
a=[N]+[0]*10000
for i in range(10000):
    if i !=0:
        if a[i-1]%2==0:
            a[i]=int((a[i-1]/2))
        else:
            a[i]=int((3*a[i-1]+1))
cnt=1
tmp=[]
for j in a:
    if str(j) in tmp:
        break
    else:
        tmp.append(str(j))
        cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
H = [int(x) for x in stdin.readline().rstrip().split()]
INF = float(inf)
dp = [INF]*N
dp[0] = 0
dp[1] = abs(H[0]-H[1])
for i in range(2,N):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i],dp[i-j]+abs(H[i]-H[i-j]))
print(dp[-1])

Fixed submission:
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
H = [int(x) for x in stdin.readline().rstrip().split()]
INF = float("inf")
dp = [INF]*N
dp[0] = 0
dp[1] = abs(H[0]-H[1])
for i in range(2,N):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i],dp[i-j]+abs(H[i]-H[i-j]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
N, W = [int(x) for x in stdin.readline().rstrip().split()]
dp = [[0]*(W+1) for i in range(N+1)]
cnt = [[0]*(W+1) for i in range(N+1)]
a = []
b = []

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    a.append(A)
    b.append(B)

for n in range(1,N+1):
    for w in range(1,W+1):
        if  w-a[n-1] >= 0:
            
            dp[n][w] = max(dp[n-1][w],dp[n-1][w-a[n-1]]+b[n-1])
            
            if dp[n-1][w] >= dp[n-1][w-a[n-1]]+b[n-1]:
                cnt[n][w] = cnt[n-1][w]
            else:
                cnt[n][w] = cnt[n-1][w-a[n-1]] + 1
                
        dp[n][w] = max(dp[n-1][w],dp[n][w])
        if dp[n][w] == dp[n-1][w]:
            cnt[n][w] = cnt[n-1][w]
        #cnt[n][w] = cnt[n-1][w]

print(dp[N][W])

Fixed submission:
from sys import stdin
N, W = [int(x) for x in stdin.readline().rstrip().split()]

baggage = [0]*N

for l in range(N):
    w, v = [int(x) for x in stdin.readline().rstrip().split()]
    baggage[l] = (w, v)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w >= baggage[i][0]:
            dp[i+1][w] = max(baggage[i][1]+dp[i][w-baggage[i][0]],dp[i][w])

        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
import math
from sys import stdin
N,P=[int(x) for x in stdin.readline().rstrip().split()]
for i in reversed(range(round(math.pow(P,(1/N)))):
    tmp=math.pow(i,N-1)
    if P==1:
        ans=1
        break
    if N==1:
        ans=P
        break
    if (P/i)%tmp==0:
        ans=i
        break
print(ans)

Fixed submission:
from sys import stdin
N=(stdin.readline().rstrip())
print(N.count("2"))

Buggy python submission (verdict: Runtime Error):
from sys import stdin
N,P=[int(x) for x in stdin.readline().rstrip().split()]
for i in reversed(range(int(pow(P,(1/N))))+1):
    tmp=i**N
    if P==1:
        ans=1
        break
    if N==1:
        ans=P
        break
    if P%tmp==0:
        ans=i
        break
print(ans)

Fixed submission:
from sys import stdin
N=(stdin.readline().rstrip())
print(N.count("2"))