Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
a=b=c=0
L=[[0,0,0]]
for k in range(K):
    maximum=0
    index=-1
    for i,l in enumerate(L):
        if A[l[0]]+B[l[1]]+C[l[2]]>maximum:
            maximum=A[l[0]]+B[l[1]]+C[l[2]]
            index=i
    if len(A)>L[index][0]+1 and [L[index][0]+1,L[index][1],L[index][2]] not in L: 
        L.append([L[index][0]+1,L[index][1],L[index][2]])
    if len(B)>L[index][1]+1 and [L[index][0],L[index][1]+1,L[index][2]] not in L:
        L.append([L[index][0],L[index][1]+1,L[index][2]])
    if len(C)>L[index][2]+1 and [L[index][0],L[index][1],L[index][2]+1] not in L:
        L.append([L[index][0],L[index][1],L[index][2]+1])
    print(A[L[index][0]]+B[L[index][1]]+C[L[index][2]])
    del L[index]

Fixed submission:
x,y,z,k=map(int, input().split())
a=sorted(list(map(int, input().split())),reverse=True)
b=sorted(list(map(int, input().split())),reverse=True)
c=sorted(list(map(int, input().split())),reverse=True)

from heapq import heapify,heappop,heappush
q=[]
heappush(q,(-a[0]-b[0]-c[0],(0,0,0)))
used={(0,0,0):True}
for i in range(k):
    if q[0][1][0]+1<x and (q[0][1][0]+1,q[0][1][1],q[0][1][2]) not in used:
        heappush(q,(-a[q[0][1][0]+1]-b[q[0][1][1]]-c[q[0][1][2]],(q[0][1][0]+1,q[0][1][1],q[0][1][2])))
        used[(q[0][1][0]+1,q[0][1][1],q[0][1][2])]=True
    if q[0][1][1]+1<y and (q[0][1][0],q[0][1][1]+1,q[0][1][2]) not in used:
        heappush(q,(-a[q[0][1][0]]-b[q[0][1][1]+1]-c[q[0][1][2]],(q[0][1][0],q[0][1][1]+1,q[0][1][2])))
        used[(q[0][1][0],q[0][1][1]+1,q[0][1][2])]=True
    if q[0][1][2]+1<z and (q[0][1][0],q[0][1][1],q[0][1][2]+1) not in used:
        heappush(q,(-a[q[0][1][0]]-b[q[0][1][1]]-c[q[0][1][2]+1],(q[0][1][0],q[0][1][1],q[0][1][2]+1)))
        used[(q[0][1][0],q[0][1][1],q[0][1][2]+1)]=True
    print(-heappop(q)[0])
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int, input().split())
S=input()
Qs=[list(map(int,input().split())) for i in range(Q)]
for q in range(Q):
    print(S.count('AC',Qs[q][0]-1,Qs[q][1]))

Fixed submission:
N,Q=map(int, input().split())
S=input()
lr=[list(map(int,input().split())) for i in range(Q)]
a=[0]*(N+1)
for i in range(2,N+1):
    if S[i-2:i]=='AC':
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]
for q in range(Q):
    print(a[lr[q][1]]-a[lr[q][0]])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int, input().split())
S=input()
for q in range(Q):
    l,r=map(int, input().split())
    print(S.count('AC',l-1,r))

Fixed submission:
N,Q=map(int, input().split())
S=input()
lr=[list(map(int,input().split())) for i in range(Q)]
a=[0]*(N+1)
for i in range(2,N+1):
    if S[i-2:i]=='AC':
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]
for q in range(Q):
    print(a[lr[q][1]]-a[lr[q][0]])
Buggy python submission (verdict: Time Limit Exceeded):
def xxx(l,n,a,b,c):
  X=10000
  for i in range(n):
    for j in range(n):
      if j==i: continue
      for k in range(n):
        if k==j or k==i: continue
        x=abs(a-l[i])+abs(b-l[j])+abs(c-l[k])
        if x<X:
          X=x
  return X
import copy
def xx(l,n,a,b,c):
  X=10000
  if n<3:
    return 10000
  else:
    for p in range(n):
      for q in range(n):
        if p!=q:
          ll=copy.deepcopy(l) 
          ll[p]+=ll[q]
          ll.pop(q)
          x=10+xxx(ll,n-1,a,b,c)
          x2=10+xx(ll,n-1,a,b,c)
          if x<X:
            X=x
          if x2<X:
            X=x2
  return X

n,a,b,c=map(int,input().split())
l=[]
for i in range(n):
  l.append(int(input()))
X=xxx(l,n,a,b,c)
if xx(l,n,a,b,c)<X:
  X=xx(l,n,a,b,c)
print(X)  

Fixed submission:
N,A,B,C=map(int, input().split())
L=[int(input()) for i in range(N)]
from itertools import product
ans=10**9
for p in product(range(4),repeat=N):
    l=[0]*3
    cost=0
    for i,t in enumerate(p):
        if t<3:
            if l[t]>0:
                cost+=10
            l[t]+=L[i]
    if min(l)>0:
        ans=min(ans,cost+abs(A-l[0])+abs(B-l[1])+abs(C-l[2]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
a=list(map(int, input().split()))
x=0
len_bin=len(bin(K))-2

def bin_l(n,i):
    return n%(2**(len_bin-i))>>(len_bin-i-1)

for i in range(len_bin):
    zero=0
    one=0
    for j in range(N):
        if bin_l(a[j],i)==0:
            zero+=1
        else:
            one+=1
    x=x<<1
    if zero>one and x<(K>>(len_bin-i-1)):
        x+=1

ans=0
for i in range(N):
    ans+=x^a[i]
print(ans)

Fixed submission:
N,K=map(int, input().split())
a=list(map(int, input().split()))
x=0
len_bin=len(bin(K))-2

def bin_l(n,i):
    return (n>>(len_bin-i-1))%2

for i in range(len_bin):
    zero=0
    one=0
    for j in range(N):
        if bin_l(a[j],i)==0:
            zero+=1
        else:
            one+=1
    x=x<<1
    if zero>one and x<(K>>(len_bin-i-1)):
        x+=1

ans=0
for i in range(N):
    ans+=x^a[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[0]*n
b=[0]*n
c=[0]
d=[0]
for i in range(n):
	a[i],b[i]=map(int,input().split())
	for j in range(len(c)):
		if a[i]+b[i]>=c[j]:
			c.insert(j,a[i]+b[i])
			d.insert(j,i)
			break
ta=0
ao=0
turn=0
for i in range(n):
	if turn==0:
		ta+=a[d[i]]
		turn=1
	else:
		ao+=b[d[i]]
		turn=0
print(ta-ao)

Fixed submission:
n=int(input())
a=[0]*n
b=[0]*n
c=[]
for i in range(n):
	a[i],b[i]=map(int,input().split())
	c.append((a[i]+b[i],i))
d=sorted(c,reverse=True)
ta=0
ao=0
turn=0
for i in range(n):
	if turn==0:
		ta+=a[d[i][1]]
		turn=1
	else:
		ao+=b[d[i][1]]
		turn=0
print(ta-ao)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
td=[list(map(int,input().split())) for i in range(N)]
best=[0]*(N+1)
other=[]
from heapq import heappop,heappush
td.sort(key=lambda x: x[1],reverse=True)
shurui=0
for i in range(K):
    if best[td[i][0]]==0:
        best[td[i][0]]=td[i][1]
        shurui+=1
    elif best[td[i][0]]<td[i][1]:
        heappush(other,best[td[i][0]])
        best[td[i][0]]=td[i][1]
    else:
        heappush(other,td[i][1])

ans=sum(best)+sum(other)+shurui**2

for i in range(K,N):
    if best[td[i][0]]==0 and len(other)>0:
        best[td[i][0]]=td[i][1]
        shurui+=1
        heappop(other)
        ans=max(ans,sum(best)+sum(other)+shurui**2)

print(ans)


Fixed submission:
N,K=map(int, input().split())
td=[list(map(int,input().split())) for i in range(N)]
best=[0]*(N+1)
other=[]
from heapq import heappop,heappush
td.sort(key=lambda x: x[1],reverse=True)
shurui=0
for i in range(K):
    if best[td[i][0]]==0:
        best[td[i][0]]=td[i][1]
        shurui+=1
    elif best[td[i][0]]<td[i][1]:
        heappush(other,best[td[i][0]])
        best[td[i][0]]=td[i][1]
    else:
        heappush(other,td[i][1])

sumbest=sum(best)
sumother=sum(other)
ans=sumbest+sumother+shurui**2

for i in range(K,N):
    if best[td[i][0]]==0 and len(other)>0:
        best[td[i][0]]=td[i][1]
        shurui+=1
        sumbest+=td[i][1]
        sumother-=heappop(other)
        ans=max(ans,sumbest+sumother+shurui**2)

print(ans)

Buggy python submission (verdict: Runtime Error):
N,K=map(int, input().split())
td=[list(map(int,input().split())) for i in range(N)]
best=[0]*(N+1)
other=[]
from heapq import heappop,heappush
td.sort(key=lambda x: x[1],reverse=True)
shurui=0
for i in range(K):
    if best[td[i][0]]==0:
        best[td[i][0]]=td[i][1]
        shurui+=1
    elif best[td[i][0]]<td[i][1]:
        heappush(other,best[td[i][0]])
        best[td[i][0]]=td[i][1]
    else:
        heappush(other,td[i][1])

ans=sum(best)+sum(other)+shurui**2

for i in range(K,N):
    if best[td[i][0]]==0:
        best[td[i][0]]=td[i][1]
        shurui+=1
        heappop(other)
        ans=max(ans,sum(best)+sum(other)+shurui**2)

print(ans)


Fixed submission:
N,K=map(int, input().split())
td=[list(map(int,input().split())) for i in range(N)]
best=[0]*(N+1)
other=[]
from heapq import heappop,heappush
td.sort(key=lambda x: x[1],reverse=True)
shurui=0
for i in range(K):
    if best[td[i][0]]==0:
        best[td[i][0]]=td[i][1]
        shurui+=1
    elif best[td[i][0]]<td[i][1]:
        heappush(other,best[td[i][0]])
        best[td[i][0]]=td[i][1]
    else:
        heappush(other,td[i][1])

sumbest=sum(best)
sumother=sum(other)
ans=sumbest+sumother+shurui**2

for i in range(K,N):
    if best[td[i][0]]==0 and len(other)>0:
        best[td[i][0]]=td[i][1]
        shurui+=1
        sumbest+=td[i][1]
        sumother-=heappop(other)
        ans=max(ans,sumbest+sumother+shurui**2)

print(ans)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[[int(c=='#') for c in input()] for i in range(H)]
v=[[0]*W for i in range(H)]
r=0
def bfs(p,x,y,c,b):
    global r
    c^=1
    q=set()
    for h,w in p:
        v[h][w]=1
        if h>0 and not v[h-1][w] and S[h-1][w]==c:
            q.add((h-1,w))
        if w>0 and not v[h][w-1] and S[h][w-1]==c:
            q.add((h,w-1))
        if h<H-1 and not v[h+1][w] and S[h+1][w]==c:
            q.add((h+1,w))
        if w<W-1 and not v[h][w+1] and S[h][w+1]==c:
            q.add((h,w+1))
    if not q:
        r+=x*y
    else:
        if b:
            x+=len(q)
        else:
            y+=len(q)
        bfs(q,x,y,c,b^1)
for h in range(H):
    for w in range(W):
        if v[h][w]==0:
            bfs([(h,w)],1,0,S[h][w],0)
print(r)

Fixed submission:
H,W=map(int,input().split())
S=[[int(c=='#') for c in input()] for i in range(H)]
v=[[0]*W for i in range(H)]
r=0
def bfs(p,x,y,c,b):
    while 1:
        c^=1
        q=set()
        for h,w in p:
            v[h][w]=1
            if h>0 and not v[h-1][w] and S[h-1][w]==c:
                q.add((h-1,w))
            if w>0 and not v[h][w-1] and S[h][w-1]==c:
                q.add((h,w-1))
            if h<H-1 and not v[h+1][w] and S[h+1][w]==c:
                q.add((h+1,w))
            if w<W-1 and not v[h][w+1] and S[h][w+1]==c:
                q.add((h,w+1))
        if not q:
            return x*y
        if b:
            x+=len(q)
        else:
            y+=len(q)
        b^=1
        p=q
for h in range(H):
    for w in range(W):
        if v[h][w]==0:
            r+=bfs([(h,w)],1,0,S[h][w],0)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
d={1:0,2:0,3:0}
for a in A:
    d[a]+=1
dp={(0,0,0):0}
from collections import defaultdict
while (d[3],d[2],d[1]) not in dp:
    dp2=defaultdict(float)
    for i,j,k in dp:
        if j>0 and i<d[3]:
            dp2[(i+1,j-1,k)]+=dp[(i,j,k)]*(i+1)/(i+j+k)
        if k>0 and i+j<d[2]+d[3]:
            dp2[(i,j+1,k-1)]+=dp[(i,j,k)]*(j+1)/(i+j+k)
        if i+j+k<N:
            dp2[(i,j,k+1)]+=dp[(i,j,k)]*(k+1)/(i+j+k+1)
    for i,j,k in dp2:
        dp2[(i,j,k)]+=N/(i+j+k)
    dp=dp2
print(dp[(d[3],d[2],d[1])])

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
d={1:0,2:0,3:0}
for a in A:
    d[a]+=1
dp=[[[0]*(N+1) for j in range(d[2]+d[3]+1)] for i in range(d[3]+1)]
for i in range(d[3]+1):
    for j in range(d[2]+d[3]-i+1):
        for k in range(N-i-j+1):
            if i+j+k==0:continue
            dp[i][j][k]=N
            if i>0:
                dp[i][j][k]+=dp[i-1][j+1][k]*i
            if j>0:
                dp[i][j][k]+=dp[i][j-1][k+1]*j
            if k>0:
                dp[i][j][k]+=dp[i][j][k-1]*k
            dp[i][j][k]/=i+j+k
print(dp[d[3]][d[2]][d[1]])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
d={1:0,2:0,3:0}
for a in A:
    d[a]+=1
dp={(0,0,0):0}
import sys
sys.setrecursionlimit(10**9)
def f(i,j,k):
    if (i,j,k) in dp:
        return dp[(i,j,k)]
    dp[(i,j,k)]=N
    if i>0:
        dp[(i,j,k)]+=f(i-1,j+1,k)*i
    if j>0:
        dp[(i,j,k)]+=f(i,j-1,k+1)*j
    if k>0:
        dp[(i,j,k)]+=f(i,j,k-1)*k
    dp[(i,j,k)]/=i+j+k
    return dp[(i,j,k)]
print(f(d[3],d[2],d[1]))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
d={1:0,2:0,3:0}
for a in A:
    d[a]+=1
dp=[[[0]*(N+1) for j in range(d[2]+d[3]+1)] for i in range(d[3]+1)]
for i in range(d[3]+1):
    for j in range(d[2]+d[3]-i+1):
        for k in range(N-i-j+1):
            if i+j+k==0:continue
            dp[i][j][k]=N
            if i>0:
                dp[i][j][k]+=dp[i-1][j+1][k]*i
            if j>0:
                dp[i][j][k]+=dp[i][j-1][k+1]*j
            if k>0:
                dp[i][j][k]+=dp[i][j][k-1]*k
            dp[i][j][k]/=i+j+k
print(dp[d[3]][d[2]][d[1]])
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=set(map(int,input().split()))
import numpy as np
a=np.array([1 if i in A else 0 for i in range(1,K+1)])
d=np.zeros(K+1)
for i in range(K):
    if d[i]==0:
        d[i+1:]+=a[:K-i]
print(['Second','First'][d[K]>0])

Fixed submission:
N,K=map(int,input().split())
A=sorted(map(int,input().split()))
d=[0]*(K+1)
for i in range(K):
    x=d[i]^1
    if x:
        for a in A:
            if i+a<K+1:
                d[i+a]=x
print(['Second','First'][d[-1]])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
d=[[0]*(N+1) for i in range(N+1)]
for w in range(1,N+1):
    if w%2==N%2:
        for l in range(N+1-w):
            d[l][l+w]=max(d[l][l+w-1]+A[l+w-1],d[l+1][l+w]+A[l])
    else:
        for l in range(N+1-w):
            d[l][l+w]=min(d[l][l+w-1]-A[l+w-1],d[l+1][l+w]-A[l])
print(d[0][N])

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
d=[[0]*(N+1) for i in range(N+1)]
for w in range(1,N+1):
    if w%2==N%2:
        for l in range(N+1-w):
            d[l][l+w]=max(d[l][l+w-1]+A[l+w-1],d[l+1][l+w]+A[l])
    else:
        for l in range(N+1-w):
            d[l][l+w]=min(d[l][l+w-1]-A[l+w-1],d[l+1][l+w]-A[l])
print(d[0][N])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
H=tuple(map(int,input().split()))
A=tuple(map(int,input().split()))
class SegTreeMax:
    def __init__(self,N):
        self.N0=2**(N-1).bit_length()
        self.INF=2**63-1
        self.data=[-self.INF]*(2*self.N0)
        self.d=[0]*N
    def update(self,i,x):
        self.d[i]=x
        i+=self.N0-1
        self.data[i]=x
        while i>0:
            i=(i-1)//2
            self.data[i]=max(self.data[i*2+1],self.data[i*2+2])
    def max(self,l,r):
        L = self.N0 + l; R = self.N0 + r
        s = -self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, self.data[R-1])
            if L & 1:
                s = max(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s
s=SegTreeMax(N+1)
s.update(0,0)
for i,h in enumerate(H):
    m=s.max(0,h)
    s.update(h,m+A[i])
print(s.max(0,N+1))

Fixed submission:
N=int(input())
H=tuple(map(int,input().split()))
A=tuple(map(int,input().split()))
class SegTreeMax:
    def __init__(self,N):
        self.N0=2**(N-1).bit_length()
        self.INF=2**63-1
        self.data=[-self.INF]*(2*self.N0)
        self.d=[0]*N
    def update(self,i,x):
        self.d[i]=x
        i+=self.N0-1
        self.data[i]=x
        while i>0:
            i=(i-1)//2
            self.data[i]=max(self.data[i*2+1],self.data[i*2+2])
    def max(self,l,r):
        L = self.N0 + l; R = self.N0 + r
        s = -self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, self.data[R-1])
            if L & 1:
                s = max(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s
s=SegTreeMax(N+1)
s.update(0,0)
for i,h in enumerate(H):
    m=s.max(0,h)
    s.update(h,m+A[i])
print(s.max(0,N+1))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=[0]*(N+1)
for i in range(N):
    a[i+1]=a[i]+A[i]
from itertools import combinations
S=[a[r]-a[l] for l,r in combinations(range(N+1),2)]
x,y=0,1<<39
for i in range(40):
    n=0
    for s in S:
        if (x+y)&s==x+y:
            n+=1
    if n>=K:
        x+=y
    y>>=1
print(x)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=[0]*(N+1)
for i in range(N):
    a[i+1]=a[i]+A[i]
from itertools import combinations
S=[a[r]-a[l] for l,r in combinations(range(N+1),2)]
x,y=0,1<<39
for i in range(40):
    n=0
    for s in S:
        if (x+y)&s==x+y:
            n+=1
    if n>=K:
        x+=y
    y>>=1
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
D,M,C=map(ord,'DMC')
S=[ord(c) for c in input()]
input()
K=map(int,input().split())
for k in K:
    d,m,c,dm=0,0,0,0
    a=0
    for i,s in enumerate(S):
        if i>=k:
            if S[i-k]==D:
                d-=1
                dm-=m
            elif S[i-k]==M:
                m-=1
            elif S[i-k]==C:
                c-=1
        if s==D:
            d+=1
        elif s==M:
            m+=1
            dm+=d
        elif s==C:
            c+=1
            a+=dm
    print(a)

Fixed submission:
N=int(input())
D,M,C=map(ord,'DMC')
import numpy as np
S=np.array([ord(c) for c in input()])
input()
K=map(int,input().split())
iD=S==D
iM=S==M
iC=S==C
cD=np.cumsum(iD,dtype=np.int64)
cM=np.cumsum(iM,dtype=np.int64)
for k in K:
    cD2=cD-np.concatenate((np.zeros(k,dtype=np.int64),cD[:-k]))
    cM2=cM-np.concatenate((np.zeros(k,dtype=np.int64),cM[:-k]))
    DM=np.cumsum(cD2*iM-np.concatenate((np.zeros(k,dtype=np.int64),cM2[k-1:-1]*iD[:-k])))
    print(np.sum(iC*DM))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
D,M,C,A=map(ord,'DMCA')
S=[ord(c)-A for c in input()]
Q=int(input())
K=list(map(int,input().split()))
DMC=[D-A,M-A,C-A]
for k in K:
    dmc=[0,0,0]
    dm=0
    a=0
    for i,s in enumerate(S):
        if i>=k:
            if S[i-k] in DMC:
                m=DMC.index(S[i-k])
                dmc[m]-=1
                if m==0:
                    dm-=dmc[1]
        if s in DMC:
            p=DMC.index(s)
            dmc[p]+=1
            if p==1:
                dm+=dmc[0]
            if p==2:
                a+=dm
    print(a)

Fixed submission:
N=int(input())
D,M,C=map(ord,'DMC')
import numpy as np
S=np.array([ord(c) for c in input()])
input()
K=map(int,input().split())
iD=S==D
iM=S==M
iC=S==C
cD=np.cumsum(iD,dtype=np.int64)
cM=np.cumsum(iM,dtype=np.int64)
for k in K:
    cD2=cD-np.concatenate((np.zeros(k,dtype=np.int64),cD[:-k]))
    cM2=cM-np.concatenate((np.zeros(k,dtype=np.int64),cM[:-k]))
    DM=np.cumsum(cD2*iM-np.concatenate((np.zeros(k,dtype=np.int64),cM2[k-1:-1]*iD[:-k])))
    print(np.sum(iC*DM))
Buggy python submission (verdict: Runtime Error):
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**9 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
            elif -k<k0:
                del H[i,j]
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[i,j])

Fixed submission:
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**10 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
            elif -k<k0:
                del H[i,j]
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[i,j])

Buggy python submission (verdict: Runtime Error):
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**9 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[(i,j)])

Fixed submission:
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
from itertools import product
H={(i,j):-10**10 for i,j in product(range(101),repeat=2)}
for n in range(N):
    x,y,h=xyh[n]
    K=[e for e in H.keys()]
    for i,j in K:
        k0=H[i,j]
        k=abs(i-x)+abs(j-y)+h if h else -(abs(i-x)+abs(j-y))
        if k<0:
            if k0<k:
                H[i,j]=k
            elif -k<k0:
                del H[i,j]
        elif k0<0:
            if k<=-k0:
                H[i,j]=k
            else:
                del H[i,j]
        elif k!=k0:
            del H[i,j]
i,j=list(H.keys())[0]
print(i,j,H[i,j])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
for i in range(m//n,0,-1):
    if m%i==0:
        print(i)
        break

Fixed submission:
n,m=map(int, input().split())
from math import sqrt
d0=[]
for i in range(1,int(sqrt(m)+1)):
    if m%i==0:
        d0.append(i)
d=d0[:]
for di in reversed(d0):
    d.append(m//di)
for i in reversed(d):
    if i<=m//n:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()
d=[[] for i in range(26)]
for i,c in enumerate(S):
    d[ord(c)-ord('a')].append(i)
d2=[[] for i in range(26)]
for i,c in enumerate(T):
    d2[ord(c)-ord('a')].append(i)
d=sorted([x for x in d if x],key=lambda x:x[0])
d2=sorted([x for x in d2 if x],key=lambda x:x[0])
f=0
if len(d)==len(d2):
    f=1
    for i in range(len(d)):
        if len(d[i])!=len(d2[i]):
            f=0
        else:
            for j in range(len(d[i])):
                if d[i]!=d2[i]:
                    f=0
print(['No','Yes'][f])

Fixed submission:
S=input()
T=input()
d=[[] for i in range(26)]
for i,c in enumerate(S):
    d[ord(c)-ord('a')].append(i)
d2=[[]for i in range(26)]
for i,c in enumerate(T):
    d2[ord(c)-ord('a')].append(i)
print(['No','Yes'][set((tuple(x) for x in d))==set((tuple(x) for x in d2))])

Buggy python submission (verdict: Runtime Error):
S=input()
T=input()
d=[[] for i in range(26)]
for i,c in enumerate(S):
    d[ord(c)-ord('a')].append(i)
d2=[[] for i in range(26)]
for i,c in enumerate(T):
    d2[ord(c)-ord('a')].append(i)
d.sort(key=lambda x:x[0])
d2.sort(key=lambda x:x[0])
f=1
for i in range(26):
    if len(d[i])!=len(d2[i]):
        f=0
    else:
        for j in range(len(d[i])):
            if d[i]!=d2[i]:
                f=0
print(['No','Yes'][f])

Fixed submission:
S=input()
T=input()
d=[[] for i in range(26)]
for i,c in enumerate(S):
    d[ord(c)-ord('a')].append(i)
d2=[[]for i in range(26)]
for i,c in enumerate(T):
    d2[ord(c)-ord('a')].append(i)
print(['No','Yes'][set((tuple(x) for x in d))==set((tuple(x) for x in d2))])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()
d=[[] for i in range(26)]
for i,c in enumerate(S):
    d[ord(c)-ord('a')].append(i)
d2=[[] for i in range(26)]
for i,c in enumerate(T):
    d2[ord(c)-ord('a')].append(i)
d.sort()
d2.sort()
f=1
for i in range(26):
    if len(d[i])!=len(d2[i]):
        f=0
    else:
        for j in range(len(d[i])):
            if d[i]!=d2[i]:
                f=0
print(['No','Yes'][f])

Fixed submission:
S=input()
T=input()
d=[[] for i in range(26)]
for i,c in enumerate(S):
    d[ord(c)-ord('a')].append(i)
d2=[[]for i in range(26)]
for i,c in enumerate(T):
    d2[ord(c)-ord('a')].append(i)
print(['No','Yes'][set((tuple(x) for x in d))==set((tuple(x) for x in d2))])