Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def ma():return map(int,input().split())
def nli(x):return [int(input()) for _ in range(x)]
def hukusuu():
  listA=[] #appendのために宣言が必要
  while True:
    try:listA.append(list(map(int,input().split())))
    except:break #または、quit(),os.exit()をして止める。
  return listA

def ifif(s):
  if s:print("Yes")
  else:print("No")

n,k,q=ma()

b=[0]*q
for i in range(q):
  ai=int(input())-1
  b[ai]+=1 

for i in range(q):
  ifif(k-b[i]>0)

Fixed submission:
def ma():return map(int,input().split())
def nli(x):return [int(input()) for _ in range(x)]
def hukusuu():
  listA=[] #appendのために宣言が必要
  while True:
    try:listA.append(list(map(int,input().split())))
    except:break #または、quit(),os.exit()をして止める。
  return listA

def ifif(s):
  if s:print("Yes")
  else:print("No")

n,k,q=ma()

b=[0]*n
for i in range(q):
  ai=int(input())-1
  b[ai]+=1 

for i in range(n):
  ifif(k-q+b[i]>0)
Buggy python submission (verdict: Runtime Error):
import heapq
def main():
    n,m=map(int, input().split()) 
    a = [map(lambda x: int(x)*(-1), input().split())] 
    heapq.heapify(a)

    for i in range(m):
        tmp_min = heapq.heappop(a)
        heapq.heappush(a, -1*(-tmp_min//2))
    print(-sum(a))

if __name__ == '__main__':
    main()

Fixed submission:
import heapq
def main():
    n,m=map(int, input().split()) 
    a = list(map(lambda x: int(x)*(-1), input().split())) 
    heapq.heapify(a)

    for i in range(m):
        tmp_min = heapq.heappop(a)
        heapq.heappush(a, -1*(-tmp_min//2))
    print(-sum(a))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
def lima():
    return list(map(int,input().split()))

a=lima()
b=lima()
c=lima()

sum=0
for i in range(n-1):
    sum+=b[a[i]-1]+c[a[i]-1]*(a[i]+1==a[i+1])

print(sum)

Fixed submission:
n=int(input())
def lima():
    return list(map(int,input().split()))

a=lima()
b=lima()
c=lima()

sum=sum(b)
for i in range(n-1):
    if a[i]+1==a[i+1]:
        sum+=c[a[i]-1]        
print(sum)
Buggy python submission (verdict: Runtime Error):
a=int(input())
d=[]
t=0
g=0
h=map(int,input().split())
for i in range(a-1):
  if h[i]>=h[i+1]:
    g+=1
  else:
    d.append(g)
    g=0
d.append(g)
print(max(d))

Fixed submission:
a=int(input())
d=[]
t=0
g=0
h=list(map(int,input().split()))
for i in range(a-1):
  if h[i]>=h[i+1]:
    g+=1
  else:
    d.append(g)
    g=0
d.append(g)
print(max(d))
Buggy python submission (verdict: Runtime Error):
import numpy as np
N=int(input())
A=list(map(int,input().split())
B=np.array(A)
C=B**-1
print((C.sum())**-1)

Fixed submission:
import numpy as np
N=int(input())
A=np.array(list(map(float,input().split())))

C=A**-1
#print(C)
print((C.sum())**-1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
v=list(map(float,input().split())) 
v.sort()
for i in range(N):
    v/=2**(N-i)

print(sum(v)+v[0])

Fixed submission:
N=int(input())
v=list(map(float,input().split())) 
v.sort()
for i in range(N):
    v[i]/=2**(N-i)

print(sum(v)+v[0])
Buggy python submission (verdict: Runtime Error):
n=int(input())
from collections import defaultdict
d=defaultdict(str)
for _ in range(n):
    s=list(input())
    s.sort()
    n=''.join(s)
    d[n]+=1 
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2

print(ans)
    

Fixed submission:
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
from collections import defaultdict
d=defaultdict(int)
for _ in range(n):
    s=list(input())
    s.sort()
    d[*s]+=1 
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2

print(ans)

Fixed submission:
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
from collections import defaultdict
d=defaultdict(int)
for _ in range(n):
    s=list(input())
    s.sort()
    d[s]+=1 
ans=0
for i in d:
    ans+=d[i]*(d[i]-1)//2

print(ans)

Fixed submission:
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()
Buggy python submission (verdict: Runtime Error):
import math
n,d=map(int,input().split())
cnt=0
dlist=[list(map(int,input().split())) for _ in range(n)]
for i in range(n-1):
    for j in range(i+1:n):
        ans=0
        for k in range(d):
            ans+=(dlist[i][k]-dlist[j][k])**2
        cnt+=math.floor(ans**0.5)==math.ceil(ans**0.5):

print(cnt)    


Fixed submission:
import math
n,d=map(int,input().split())
cnt=0
dlist=[list(map(int,input().split())) for _ in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ans=0
        for k in range(d):
            ans+=(dlist[i][k]-dlist[j][k])**2
        cnt+=math.floor(ans**0.5)==math.ceil(ans**0.5)

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
MOD= 2019 
if l-r>=2018:
    print(0)
    exit()
else:
    ltemp=l%MOD
    rtemp=r-l+ltemp
    ans=2019 
    for i in range(ltemp,rtemp):
        for j in range(i+1,rtemp+1):
            ans=min(ans,i*j%MOD)
    print(ans)

Fixed submission:
l,r=map(int,input().split())
MOD= 2019 
if r-l>=2018:
    print(0)
    exit()
else:
    ltemp=l%MOD
    rtemp=r-l+ltemp
    ans=2019 
    for i in range(ltemp,rtemp):
        for j in range(i+1,rtemp+1):
            ans=min(ans,i*j%MOD)
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
a-=1;b-=1;c-=1;d-=1 
from collections import deque 

queueA=deque([a])
queueB=deque([b])
S=input()
JinA=JinB=[0]*n 
if c<b or c<d:
    for i in range(a,d):
        if S[i]=="#" and S[i+1]=="#":
            print("No")
            exit() 
    else:
        print("Yes")
        exit()
    
else:
    for j in range(min(a,c),max(a,c)):
        if S[i]=="#" and S[i+1]=="#":
            print("No")
            exit() 
    for j in range(min(b,d),max(b,d)):
        if S[i]=="#" and S[i+1]=="#":
            print("No")
            exit() 
    for i in range(n-2):
        if S[i]==S[i+1]==S[i+2]==".":
            print("Yes")
            exit()
    else:
        print('No')

Fixed submission:
int1 = lambda x: int(x) - 1
N, A, B, C, D = map(int1, input().split())
S = input()

if "##" not in S[A:B+1] and "##" not in S[C:D+1]:
    if C > D and "..." not in S[B-1:D+2]:
        print("No")
    else:
        print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
a-=1;b-=1;c-=1;d-=1 
from collections import deque 

queueA=deque([a])
queueB=deque([b])
S=input()
JinA=JinB=[0]*n 
if c<b or c<d:
    for i in range(a,d):
        if S[i]=="#" and S[i+1]=="#":
            print("No")
            exit() 
    else:
        print("Yes")
        exit()
    
else:
    for j in range(a,max(c,d)):
        if S[i]=="#" and S[i+1]=="#":
            print("No")
            exit() 
    for i in range(n-2):
        if S[i]==S[i+1]==S[i+2]==".":
            print("Yes")
            exit()
    else:
        print('No')


Fixed submission:
int1 = lambda x: int(x) - 1
N, A, B, C, D = map(int1, input().split())
S = input()

if "##" not in S[A:B+1] and "##" not in S[C:D+1]:
    if C > D and "..." not in S[B-1:D+2]:
        print("No")
    else:
        print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
ks=[list(map(int,input())) for _ in range(M)]
p=list(map(int,input().split()))
ans=0
for s in range(1<<M):
    for j in range(M):
        cnt=0
        for h in ks[j][1:]:
            h-=1
            if (s>>h)&1:
                cnt+=1
                cnt%=2
        if cnt!=ks[j][0]:
            break
    else:
        ans+=1
print(ans)

Fixed submission:
N,M=map(int,input().split())
ks=[list(map(int,input().split())) for _ in range(M)]
p=list(map(int,input().split()))
ans=0
for s in range(1<<N):
    for j in range(M):
        cnt=0
        for h in ks[j][1:]:
            h-=1
            if (s>>h)&1:
                cnt+=1
                cnt%=2
        if cnt!=p[j]:
            break
    else:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import bisect
N,M=map(int,input().split())
A=np.array(list(map(int,input().split())))
JinA=[]
for i in range(M):
    b,c=map(int,input().split())
    JinA.append((c,b))

JinA.sort(reverse=True)

A.sort()
len_b=0
new_list=[]
for c,b in JinA:
    add_b=min(b,N-len_b)
    new_list+=[c]*add_b
    if add_b==0:
        break
new_list+=[0]*(N-len(new_list))
now=np.array(new_list)    
Ans=np.maximum(A,now)
print(Ans.sum())

Fixed submission:
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[1, a] for a in list(map(int, input().split()))]
BC = [list(map(int, input().split())) for i in range(M)]

q = sorted(A+BC, key=itemgetter(1), reverse=True)

ans = 0
i = 0

while N:
    n = min(q[i][0], N)
    ans += q[i][1] * n
    N -= n
    i += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import bisect
N,M=map(int,input().split())
A=np.array(list(map(int,input().split())))
JinA=[]
for i in range(M):
    b,c=map(int,input().split())
    JinA.append((c,b))

JinA.sort(reverse=True)

A.sort()
len_b=0
new_list=[]
for c,b in JinA:
    add_b=min(b,N-len_b)
    new_list+=[c]*add_b
    
now=np.array(new_list)    
Ans=np.maximum(A,now)
print(Ans.sum())

Fixed submission:
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[1, a] for a in list(map(int, input().split()))]
BC = [list(map(int, input().split())) for i in range(M)]

q = sorted(A+BC, key=itemgetter(1), reverse=True)

ans = 0
i = 0

while N:
    n = min(q[i][0], N)
    ans += q[i][1] * n
    N -= n
    i += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import bisect
N,M=map(int,input().split())
A=np.array(list(map(int,input().split())))
JinA=[]
for i in range(M):
    b,c=map(int,input().split())
    JinA.append((c,b))

JinA.sort(reverse=True)

A.sort()
len_b=0
new_list=[]
for c,b in JinA:
    add_b=min(b,N-len_b)
    new_list+=[c]*add_b
    
now=np.array(new_list)    
Ans=np.minimum(A,now)
print(Ans.sum())

Fixed submission:
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[1, a] for a in list(map(int, input().split()))]
BC = [list(map(int, input().split())) for i in range(M)]

q = sorted(A+BC, key=itemgetter(1), reverse=True)

ans = 0
i = 0

while N:
    n = min(q[i][0], N)
    ans += q[i][1] * n
    N -= n
    i += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import bisect
N,M=map(int,input().split())
A=np.array(list(map(int,input().split())))
BC=[list(map(int,input().split())) for _ in range(M)]
A.sort()
for i in range(M):
    b,c=BC[i][0],BC[i][1]
    v=np.array([c]*b+[0]*(N-b))
    A=np.maximum(A,v)
    A.sort()

print(A.sum())

Fixed submission:
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[1, a] for a in list(map(int, input().split()))]
BC = [list(map(int, input().split())) for i in range(M)]

q = sorted(A+BC, key=itemgetter(1), reverse=True)

ans = 0
i = 0

while N:
    n = min(q[i][0], N)
    ans += q[i][1] * n
    N -= n
    i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
s[k-1]=s[k-1].lower()
print(s)


Fixed submission:
n,k= map(int,input().split())
s=input()
print(s[:k-1] + s.lower()[k-1] + s[k:n])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
s[k-1]=s[k-1].lower
print(s)

Fixed submission:
n,k= map(int,input().split())
s=input()
print(s[:k-1] + s.lower()[k-1] + s[k:n])
Buggy python submission (verdict: Runtime Error):
import math
n,k=map(int,input().split())
temp=0
for i in range(1,n+1):
  temp+=2**(-math.ceil(log(k/i,2)))
  
print(temp/n)  

Fixed submission:
import math
n,k=map(int,input().split())
temp=0
for i in range(1,n+1):
  if k<i:temp+=1
  else:temp+=2**(-math.ceil(math.log(k/i,2)))
  
print(temp/n)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
    
root=[int(i) for i in range(n)] 
rank=[0]*n    
def find(x):
    if root[x]==x:
        return x 
    else:
        return find(root[x])

for i in range(m):
    x,y,z=map(int,input().split())
    fx=find(x-1)
    fy=find(y-1)
    if rank[fx]>=rank[fy]:
        root[fy]=fx
        if rank[fx]==rank[fy]:
            rank[fx]+=1
    else:
        root[fx]=fy 
a=()
for i in range(n):
    a.add(find(i)) 
print(len(a))

Fixed submission:
n,m=map(int,input().split())
    
root=[int(i) for i in range(n)] 
rank=[0]*n    
def find(x):
    if root[x]==x:
        return x 
    else:
        return find(root[x])

for i in range(m):
    x,y,z=map(int,input().split())
    fx=find(x-1)
    fy=find(y-1)
    if rank[fx]>=rank[fy]:
        root[fy]=fx
        if rank[fx]==rank[fy]:
            rank[fx]+=1
    else:
        root[fx]=fy 
a=[]
for i in range(n):
    a.append(find(i)) 
print(len(set(a)))
Buggy python submission (verdict: Runtime Error):
def main():
    import sys 
    from fractions import gcd 
    input = sys.stdin.readline 

    def init(init_val):
        for i in range(n):
            seg[i+num-1] = init_val[i]
        for i in range(num-2,-1,-1):
            seg[i] = gcd(seg[2*i+1], seg[2*i+2])

    def update(k, x):
        k += num - 1
        seg[k] = x 
        while k:
            k = (k-1)//2
            seg[k] = gcd(seg[2*k+1], seg[2*k+2])

    def query(p, q):
        if q <= p:
            return ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = gcd(res, seg[p])
            if q & 1 == 1:
                res = gcd(res, seg[q])
                q -= 1
            p //= 2
            q = (q - 1)//2

        if p==q:
            res = gcd(res, seg[p])
        else:
            res = gcd(gcd(res, seg[p]), seg[q])
        return res
         
    n= int(input())
    a = tuple(map(int, input().split())
    ide_ele = 0
    num = 2**(n-1).bit_length()
    seg = [ide_ele]*2*num
    init(a)    
                
    ans = -1
    for i in range(n):
        ans = max(ans, gcd(query(0,i), query(i+1,n)))
    print(ans) 

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys 
    from fractions import gcd 
    input = sys.stdin.readline 

    def init(init_val):
        for i in range(n):
            seg[i+num-1] = init_val[i]
        for i in range(num-2,-1,-1):
            seg[i] = gcd(seg[2*i+1], seg[2*i+2])

    def update(k, x):
        k += num - 1
        seg[k] = x 
        while k:
            k = (k-1)//2
            seg[k] = gcd(seg[2*k+1], seg[2*k+2])

    def query(p, q):
        if q <= p:
            return 0
        p += num - 1
        q += num - 2
        res = 0
        while q - p > 1:
            if p & 1 == 0:
                res = gcd(res, seg[p])
            if q & 1 == 1:
                res = gcd(res, seg[q])
                q -= 1
            p //= 2
            q = (q - 1)//2

        if p==q:
            res = gcd(res, seg[p])
        else:
            res = gcd(gcd(res, seg[p]), seg[q])
        return res
         
    n= int(input())
    a = tuple(map(int, input().split()))
    num = 2**(n-1).bit_length()
    seg = [0]*2*num
    init(a)    
                
    ans = -1
    for i in range(n):
        ans = max(ans, gcd(query(0,i), query(i+1,n)))
    print(ans) 

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
AB=[]
for i in range(n):
    a,b=map(int,input().split())
    AB.append((b,a))

AB.sort()

cnt=0
ans=0
for b,a in AB:
    if cnt==k:
        print(ans)
        break
    temp=min(k-cnt,a)
    ans+=b*temp
    cnt+=temp

Fixed submission:
n,m=map(int,input().split())
AB=[]
for i in range(n):
    a,b=map(int,input().split())
    AB.append((a,b))

AB.sort()

cnt=0
ans=0
for a,b in AB:

    temp=min(m-cnt,b)
    ans+=a*temp
    cnt+=temp
    if cnt==m:
        print(ans)
        break
Buggy python submission (verdict: Runtime Error):
import bisect,sys 
input=sys.stdin.readline 
a,b,Q=map(int,input().split())
INF=10**18
s=[-INF]+[int(input()) for _ in range(a)]+[INF]
t=[-INF]+[int(input()) for _ in range(b)]+[INF]
for q in range(Q):
    x=int(input())
    b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)
    res=INF 
    for S in [s(b-1),s(b)]:
        for T in [t(d-1),t(d)]:
            d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(T-S)
            res=min(res,d1,d2)
    print(res)

Fixed submission:
import bisect,sys 
input=sys.stdin.readline 
a,b,Q=map(int,input().split())
INF=10**18
s=[-INF]+[int(input()) for _ in range(a)]+[INF]
t=[-INF]+[int(input()) for _ in range(b)]+[INF]
for q in range(Q):
    x=int(input())
    b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)
    res=INF 
    for S in [s[b-1],s[b]]:
        for T in [t[d-1],t[d]]:
            d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(T-S)
            res=min(res,d1,d2)
    print(res)

Buggy python submission (verdict: Runtime Error):
import bisect,sys 
input=sys.stdin.readline 
a,b,Q=map(int,input().split())
INF=10**18
s=[-INF]+[int(input()) for _ in range(A)]+[INF]
t=[-INF]+[int(input()) for _ in range(B)]+[INF]
for q in range(Q):
    x=int(input())
    b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)
    res=INF 
    for S in [s(b-1),s(b)]:
        for T in [t(d-1),t(d)]:
            d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(T-S)
            res=min(res,d1,d2)
    print(res)

Fixed submission:
import bisect,sys 
input=sys.stdin.readline 
a,b,Q=map(int,input().split())
INF=10**18
s=[-INF]+[int(input()) for _ in range(a)]+[INF]
t=[-INF]+[int(input()) for _ in range(b)]+[INF]
for q in range(Q):
    x=int(input())
    b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)
    res=INF 
    for S in [s[b-1],s[b]]:
        for T in [t[d-1],t[d]]:
            d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(T-S)
            res=min(res,d1,d2)
    print(res)
Buggy python submission (verdict: Runtime Error):
n=int(input())
H=list(map(int,input().split()))
dp=[10**9]*(n)
dp[0]=0
for i in range(n):
    if i==1:
        dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1]))
    elif i>1:
        dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))

print(dp[n]) 

Fixed submission:
n=int(input())
H=list(map(int,input().split()))
dp=[10**9]*(n)
dp[0]=0
for i in range(n):
    if i==1:
        dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1]))
    elif i>1:
        dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
H=list(map(int,input().split()))
dp=[10**9]*(n)
dp[0]=0
for i in range(n):
    for j in range(1,k+1):
        if i-j>=0:
            dp[i]=min(dp[i],dp[i-j]+abs(H[i]-H[i-j]))
            
print(dp[-1])        


Fixed submission:
import sys
input=sys.stdin.readline
def main():
    n,k=map(int,input().split())
    H=list(map(int,input().split()))
    dp=[10**9]*(n)
    dp[0]=0
    for i in range(n):
        for j in range(1,k+1):
            if i-j>=0:
                dp[i]=min(dp[i],dp[i-j]+abs(H[i]-H[i-j]))
            
    print(dp[-1])        

main()
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
def main():
    n=int(input())
    #H=[list(map(int,input().split())) for _ in range(n)]
    dp=[[-10**9]*3 for _ in range(n)]
    
    for i in range(n):
        a,b,c=map(int,input().split())
        t=[a,b,c]
        if i==0:
            dp[0][0],dp[0][1],dp[0][2]=a,b,c 
        else:
            for j in range(3):
                dp[i][j]=max(dp[i-1][j-1]+t[j-1],dp[i-2]+t[j-2])

        print(max(dp[-1]))
main()

Fixed submission:
import sys
input=sys.stdin.readline
def main():
    n=int(input())
    #H=[list(map(int,input().split())) for _ in range(n)]
    dp=[[-10**9]*3 for _ in range(n)]
    
    for i in range(n):
        a,b,c=map(int,input().split())
        t=[a,b,c]
        if i==0:
            dp[0][0],dp[0][1],dp[0][2]=a,b,c 
        else:
            for j in range(3):
                dp[i][j]=max(dp[i-1][j-1]+t[j],dp[i-1][j-2]+t[j])
    #print(dp)

    print(max(dp[-1]))
main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    items = [tuple(map(int, input().split())) for _ in range(N)]
    dd = defaultdict(int)
    dd[0] = 0
    for w, v in items:
        for tw, tv in list(dd.items()):
            if tw + w <= W:
                dd[tw + w] = max(tv + v, dd[tw + w])
    print(max(dd.values()))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import numpy as np
    N, W = map(int, input().split())
    ndp = np.zeros(W+1, dtype= np.int64)
    for _ in range(N):
        w, v = map(int,input().split())
        np.maximum(ndp[:-w] + v, ndp[w:], out = ndp[w:])
    else:print(ndp[-1])

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
if n==1:
    print(p)
    exit()
import math 
use=math.ceil(p**(1/n))
while True :
    if p%(use**n)==0:
        print(use)
        break
    use-=1  

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

if N == 1:
    ans = P
else:
    ans = 1
    p = 2
    while p * p <= P:
        e = 0
        while P % p == 0:
            P //= p
            e += 1  # 素数のカウント
        if e // N > 0:
            ans *= p ** (e // N)
        p += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
n,p=map(int,input().split())
if n==1:
    print(p)
    exit()
import math 
use=math.ceil(p**(1/n))
while True :
    if p%(use**n)==0:
        print(use)
        break
    use-=1  

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

if N == 1:
    ans = P
else:
    ans = 1
    p = 2
    while p * p <= P:
        e = 0
        while P % p == 0:
            P //= p
            e += 1  # 素数のカウント
        if e // N > 0:
            ans *= p ** (e // N)
        p += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t, a = map(int,input().split())
beta = 0.006
H = list(map(int,input().split()))
import numpy as np 
H = np.array(H) 
use = t - beta * H - a 
use = use**2 
pre_answer = min(use) 
ans = 1 + use.index(pre_answer) 
print(ans)

Fixed submission:
n = int(input())
t, a = map(int,input().split())
beta = 0.006
H = list(map(int,input().split()))
import numpy as np 
H = np.array(H) 
use = t - beta * H - a 
use = use**2 
pre_answer = min(use)
use = list(use) 
ans = 1 + use.index(pre_answer) 
print(ans)
Buggy python submission (verdict: Runtime Error):

def main():
  from collections import Counter
  N=int(input())
  A=list(ma())
  evens = Counter(A[::2])
  odds = Counter(A[1::2])
  evens[0]=0 #この部分は文字列が小さい時に必要
  odds[0]=0 #
  
  e1, e2=evens.most_common(2) #上位２つを実際の数字をⅠ番目に、出てきた回数を２こめ
  o1, o2=odds.most_common(2) #
  
  if e1[0]!=o1[0]:
    print(N - (e1[1] + o1[1]))
  else: 
    print(N - max(e1[1]+o2[1], e2[1]+o1[1]))
  
if __name__ == '__main__':
  main()


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

def main():
  from collections import Counter
  N=int(input())
  A=list(ma())
  evens = Counter(A[::2])
  odds = Counter(A[1::2])
  evens[0]=0 #この部分は文字列が小さい時に必要
  odds[0]=0 #
  
  e1, e2=evens.most_common(2) #上位２つを実際の数字をⅠ番目に、出てきた回数を２こめ
  o1, o2=odds.most_common(2) #
  
  if e1[0]!=o1[0]:
    print(N - (e1[1] + o1[1]))
  else: 
    print(N - max(e1[1]+o2[1], e2[1]+o1[1]))
  
if __name__ == '__main__':
  main()