Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
bc=[]
for i in range(M):
  bc.append(list(map(int,input().split())))

bc.sort(key=lambda x:x[1],reverse=True)
nbc=[0]*N
inde=0
for i in range(M):
  for j in range(bc[i][0]):
    if inde<N-1:
      nbc[inde]=bc[i][1]
      inde+=1
    elif inde==N-1:
      nbc[inde]=bc[i][1]
      break
      
    
    

      
for i in range(N):
  if A[i]>=nbc[i]:
    ind=i
    break

print(sum(nbc[:ind])+sum(A[ind:]))

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
bc=[]
for i in range(M):
  bc.append(list(map(int,input().split())))

bc.sort(key=lambda x:x[1],reverse=True)
nbc=[0]*N
inde=0
for i in range(M):
  for j in range(bc[i][0]):
    if inde<=N-1:
      nbc[inde]=bc[i][1]
      inde+=1
      if inde==N:
        break
  if inde==N:
    break
  
ind=N
for i in range(N):
  if A[i]>=nbc[i]:
    ind=i
    break

print(sum(nbc[:ind])+sum(A[ind:]))

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
bc=[]
for i in range(M):
  bc.append(list(map(int,input().split())))

bc.sort(key=lambda x:x[1],reverse=True)
nbc=[]
for i in range(M):
  for j in range(bc[i][0]):
    if len(nbc)<=N:
      nbc.append(bc[i][1])

while len(nbc)<=N:
  nbc.append(0)
      
for i in range(N):
  if A[i]>=nbc[i]:
    ind=i
    break

print(sum(nbc[:ind]+A[ind:]))

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
bc=[]
for i in range(M):
  bc.append(list(map(int,input().split())))

bc.sort(key=lambda x:x[1],reverse=True)
nbc=[0]*N
inde=0
for i in range(M):
  for j in range(bc[i][0]):
    if inde<=N-1:
      nbc[inde]=bc[i][1]
      inde+=1
      if inde==N:
        break
  if inde==N:
    break
  
ind=N
for i in range(N):
  if A[i]>=nbc[i]:
    ind=i
    break

print(sum(nbc[:ind])+sum(A[ind:]))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N,M=map(int,input().split())
A=list(map(int,input().split()))
heapq.heapify(A)
bc=[]
for i in range(M):
  bc.append(list(map(int,input().split())))

for i in range(M):
  for j in range(bc[i][0]):
    if A[0]<bc[i][1]:
      heapq.heappop(A)
      heapq.heappush(A,bc[i][1])
    else:
      break

print(sum(A))

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
bc=[]
for i in range(M):
  bc.append(list(map(int,input().split())))

bc.sort(key=lambda x:x[1],reverse=True)
nbc=[0]*N
inde=0
for i in range(M):
  for j in range(bc[i][0]):
    if inde<=N-1:
      nbc[inde]=bc[i][1]
      inde+=1
      if inde==N:
        break
  if inde==N:
    break
  
ind=N
for i in range(N):
  if A[i]>=nbc[i]:
    ind=i
    break

print(sum(nbc[:ind])+sum(A[ind:]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W=map(int,input().split())
field=[]
spos=deque([])
for i in range(H):
  s=list(input())
  for j in range(W):
    if s[j]=="#":
      spos.append((j,i))
  field.append(s)
  
dx=[1,0,-1,0]
dy=[0,1,0,-1]

ans=-1
while spos:
  for _ in range(len(spos)):
    x,y=spos.popleft()
    for i in range(4):
      nx=x+dx[i]
      ny=y+dy[i]
      if nx<0 or nx>=W or ny<0 or ny>=H:
        pass
      elif field[ny][nx]==".":
        field[ny][nx]="#"
        spos.append((nx,ny))
  ans+=1

print(ans)


Fixed submission:
from collections import deque

H,W=map(int,input().split())
field=[]
spos=deque([])
for i in range(H):
  s=list(input())
  for j in range(W):
    if s[j]=="#":
      spos.append((j,i))
  field.append(s)
  

dx=[1,0,-1,0]
dy=[0,1,0,-1]

ans=-1
while spos:
  for _ in range(len(spos)):
    x,y=spos.popleft()
    for i in range(4):
      nx=x+dx[i]
      ny=y+dy[i]
      if nx<0 or nx>=W or ny<0 or ny>=H:
        pass
      elif field[ny][nx]==".":
        field[ny][nx]="#"
        spos.append((nx,ny))
  ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
field=[]
spos=[]
for i in range(H):
  s=list(input())
  for j in range(W):
    if s[j]=="#":
      spos.append((j,i))
  field.append(s)

dx=[1,0,-1,0]
dy=[0,1,0,-1]

ans=0
while field.count(["#"]*W)<H:
  for _ in range(len(spos)):
    x,y=spos.pop(0)
    for i in range(4):
      nx=x+dx[i]
      ny=y+dy[i]
      if nx<0 or nx>=W or ny<0 or ny>=H:
        pass
      elif field[ny][nx]==".":
        field[ny][nx]="#"
        spos.append((nx,ny))
  ans+=1

print(ans)

Fixed submission:
from collections import deque

H,W=map(int,input().split())
field=[]
spos=deque([])
for i in range(H):
  s=list(input())
  for j in range(W):
    if s[j]=="#":
      spos.append((j,i))
  field.append(s)
  

dx=[1,0,-1,0]
dy=[0,1,0,-1]

ans=-1
while spos:
  for _ in range(len(spos)):
    x,y=spos.popleft()
    for i in range(4):
      nx=x+dx[i]
      ny=y+dy[i]
      if nx<0 or nx>=W or ny<0 or ny>=H:
        pass
      elif field[ny][nx]==".":
        field[ny][nx]="#"
        spos.append((nx,ny))
  ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)


dp=[0]*N
dp[1]=max(A[0],A[1])
dp[2]=max(gcd(A[0],A[1]),gcd(A[1],A[2]),gcd(A[2],A[0]))
for i in range(3,N):
  dp[i]=gcd(dp[i-1],A[i])

print(dp[N-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N=int(input())
A=list(map(int,input().split()))

def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)

L=[0]*(N+2)
R=[0]*(N+2)

for i in range(1,N+1):
  L[i]=gcd(L[i-1],A[i-1])

for i in reversed(range(1,N+1)):
  R[i]=gcd(R[i+1],A[i-1])

M=[gcd(L[i-1],R[i+1]) for i in range(1,N+1)]

print(max(M))
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()))

AB=[]
for i in range(X):
  for j in range(Y):
    AB.append(A[i]+B[j])
AB.sort(reverse=True)
AB=AB[:K]

ABC=[]
for i in range(len(AB)):
  for j in range(Z):
    ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
ABC=ABC[:K]
for i in ABC:
  print(i)

Fixed submission:
import heapq
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)

seen=[(0,0,0)]
Q=[]
heapq.heappush(Q,[-(A[0]+B[0]+C[0]),0,0,0])
for _ in range(K):
  h=heapq.heappop(Q)
  i,j,k=h[1],h[2],h[3]
  print(-h[0])
  if i+1<X:
    if (i+1,j,k) not in seen:
      heapq.heappush(Q,[-(A[i+1]+B[j]+C[k]),i+1,j,k])
      seen.append((i+1,j,k))
  if j+1<Y:
    if (i,j+1,k) not in seen:
      heapq.heappush(Q,[-(A[i]+B[j+1]+C[k]),i,j+1,k])
      seen.append((i,j+1,k))
  if k+1<Z:
    if (i,j,k+1) not in seen:
      heapq.heappush(Q,[-(A[i]+B[j]+C[k+1]),i,j,k+1])
      seen.append((i,j,k+1))
Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=0
for _ in range(N):
  x,u=map(int,input().split())
  if u=="JPY":
    ans+=x
  else:
    ans+=x*380000
print(ans)

Fixed submission:
N=int(input())
ans=0
for _ in range(N):
  x,u=input().split()
  if u=="JPY":
    ans+=int(x)
  else:
    ans+=float(x)*380000
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
lk=len(bin(K))-2
C=[0]*lk
for j in range(N):
  a=A[j]
  for i in range(lk):
    if a%2==1:
      C[i]+=1
    a=(a-a%2)//2

X="0b"
for i in reversed(range(lk)):
  if C[i]>=N-C[i]:
    X+="0"
  else:
    X+="1"
    
if int(X,0)<=K:
  X=int(X,0)
  ans=0
  for i in range(N):
    ans+=X^A[i]
  print(ans)
else:
  ans=-1
  for i in range(2,lk+2):
    x=int(bin(K)[:i]+"0"+X[i+1:],0)
    if x<=K:
      a=0
      for i in range(N):
        a+=x^A[i]
      ans=max(ans,a)
  print(ans)


Fixed submission:
T,X=map(int,input().split())
print(T/X)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))
lk=len(bin(K))-2
C=[0]*lk
for j in range(N):
  a=A[j]
  for i in range(lk):
    if a%2==1:
      C[i]+=1
    a=(a-a%2)//2

X="0b"
for i in reversed(range(lk)):
  if C[i]>=N-C[i]:
    X+="0"
  else:
    X+="1"
    
if int(X,0)<=K:
  X=int(X,0)
  ans=0
  for i in range(N):
    ans+=X^A[i]
  print(ans)
else:
  ans=-1
  for i in range(2,lk+2):
    x=int(bin(K)[:i]+"0"+X[i+1:],0)
    if x<=K:
      a=0
      for i in range(N):
        a+=x^A[i]
      ans=max(ans,a)
  print(ans)


Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
lk=len(bin(K))-2
C=[0]*lk
for j in range(N):
  a=A[j]
  for i in range(lk):
    if a%2==1:
      C[i]+=1
    a=(a-a%2)//2

X="0b"
for i in reversed(range(lk)):
  if C[i]>=N-C[i]:
    X+="0"
  else:
    X+="1"
    
if int(X,0)<=K:
  X=int(X,0)
  ans=0
  for i in range(N):
    ans+=X^A[i]
  print(ans)
else:
  ans=-1
  for i in range(2,lk+2):
    x=int(bin(K)[:i]+"0"+X[i+1:],0)
    if x<=K:
      a=0
      for i in range(N):
        a+=x^A[i]
      ans=max(ans,a)
  print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
par=[[] for _ in range(N)]
for _ in range(N-1+M):
  a,b=map(int,input().split())
  par[b-1].append(a)

dep=[-1]*N
def depth(n):
  if dep[n-1]!=-1:
    return dep[n-1]
  else:
    if len(par[n-1])==0:
      dep[n-1]=0
      return 0
    else:
      dep[n-1]=max([depth(i) for i in par[n-1]])+1
      return dep[n-1]

for i in range(N):
  if len(par[i])==0:
    print(0)
  elif len(par[i])==1:
    print(par[i][0])
  else:
    m=-1
    a=par[i][0]
    for j in par[i]:
      d=depth(j)
      if m<d:
        m=d
        a=j
    print(a)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N,M=map(int,input().split())
par=[[] for _ in range(N)]
for _ in range(N-1+M):
  a,b=map(int,input().split())
  par[b-1].append(a)

dep=[-1]*N
def depth(n):
  if dep[n-1]!=-1:
    return dep[n-1]
  else:
    if len(par[n-1])==0:
      dep[n-1]=0
      return 0
    else:
      dep[n-1]=max([depth(i) for i in par[n-1]])+1
      return dep[n-1]

for i in range(N):
  if len(par[i])==0:
    print(0)
  elif len(par[i])==1:
    print(par[i][0])
  else:
    m=-1
    a=par[i][0]
    for j in par[i]:
      d=depth(j)
      if m<d:
        m=d
        a=j
    print(a)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000000)
N,M=map(int,input().split())
S=list(input())
T=list(input())

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

k=N*M//gcd(N,M)
X=[0]*k
for i,s in enumerate(S):
  X[i*k//N]=s
  
for i,t in enumerate(T):
  if X[i*k//M]==t or X[i*k//M]==0:
    pass
  else:
    print(-1)
    exit()
    
print(k)

Fixed submission:
import sys
sys.setrecursionlimit(10000)
N,M=map(int,input().split())
S=list(input())
T=list(input())

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

k=N*M//gcd(N,M)
X=[0]*N
for i,s in enumerate(S):
  X[i]=s
  
for i,t in enumerate(T):
  if (i*k//M)%(k//N)!=0:
    pass
  elif (i*k//M)%(k//N)==0 and X[(i*k//M)//(k//N)]==t:
    pass
  else:
    print(-1)
    exit()
    
print(k)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
N,M=map(int,input().split())
S=list(input())
T=list(input())

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

k=N*M//gcd(N,M)
X=[0]*k
for i,s in enumerate(S):
  X[i*k//N]=s
  
for i,t in enumerate(T):
  if X[i*k//M]==t or X[i*k//M]==0:
    pass
  else:
    print(-1)
    exit()
    
print(k)

Fixed submission:
import sys
sys.setrecursionlimit(10000)
N,M=map(int,input().split())
S=list(input())
T=list(input())

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

k=N*M//gcd(N,M)
X=[0]*N
for i,s in enumerate(S):
  X[i]=s
  
for i,t in enumerate(T):
  if (i*k//M)%(k//N)!=0:
    pass
  elif (i*k//M)%(k//N)==0 and X[(i*k//M)//(k//N)]==t:
    pass
  else:
    print(-1)
    exit()
    
print(k)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
S=list(input())
T=list(input())

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

k=N*M//gcd(N,M)
X=[0]*k
for i,s in enumerate(S):
  X[i*k//N]=s
  
for i,t in enumerate(T):
  if X[i*k//M]==t or X[i*k//M]==0:
    pass
  else:
    print(-1)
    exit()
    
print(k)

Fixed submission:
import sys
sys.setrecursionlimit(10000)
N,M=map(int,input().split())
S=list(input())
T=list(input())

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

k=N*M//gcd(N,M)
X=[0]*N
for i,s in enumerate(S):
  X[i]=s
  
for i,t in enumerate(T):
  if (i*k//M)%(k//N)!=0:
    pass
  elif (i*k//M)%(k//N)==0 and X[(i*k//M)//(k//N)]==t:
    pass
  else:
    print(-1)
    exit()
    
print(k)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N,M,Q=map(int,input().split())
Rli=[[] for _ in range(N)]
for i in range(M):
  l,r=map(int,input().split())
  Rli[l-1].append(r)
for i in range(N):
  Rli[i].sort()
  
for i in range(Q):
  ans=0
  p,q=map(int,input().split())
  for j in range(p-1,N):
    ans+=bisect.bisect_right(Rli[j],q)
  print(ans)

Fixed submission:
import bisect
N,M,Q=map(int,input().split())
LR=[[0]*(N+1) for _ in range(N)]
for i in range(M):
  l,r=map(int,input().split())
  LR[l-1][r]+=1
for i in range(N):
  for j in range(1,N+1):
    LR[i][j]+=LR[i][j-1]
  
for _ in range(Q):
  ans=0
  p,q=map(int,input().split())
  for i in range(p-1,q):
    ans+=LR[i][q]-LR[i][p-1]
  print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.sort()

ans=0
while AB:
  a=AB[-1][0]
  AB=list(filter(lambda x:x[1]<=a,AB))
  ans+=1
  
print(ans)

Fixed submission:
A=list(map(int,input().split()))
print(max(A)-min(A))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.sort()

ans=0
while AB:
  a=AB[-1][0]
  AB=list(filter(lambda x:x[1]<=a,AB))
  ans+=1
  
print(ans)

Fixed submission:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.sort()

ar=N+1
ans=0
for i in reversed(range(M)):
  a,b=AB[i]
  if b<=ar:
    ans+=1
    ar=a
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.sort()

ans=0
while AB:
  a=AB[-1][0]
  AB=list(filter(lambda x:x[1]<=a,AB))
  ans+=1
  
print(ans)

Fixed submission:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.sort()

ar=N+1
ans=0
for i in reversed(range(M)):
  a,b=AB[i]
  if b<=ar:
    ans+=1
    ar=a
  
print(ans)
Buggy python submission (verdict: Runtime Error):
S=list(input())
K=int(input())

if K==1:
  print(sorted(S)[0])
  exit()

ans=[]
if K<len(S):
  s0=sorted(S[:-K+1])[0]
  for j,e in enumerate(S[:-K+1]):
    if e==s0:
      for i in range(1,K+1):
        a="".join(S[j:j+i])
        if a not in ans:
          ans.append(a)
      
sl=S[-K+1:]
for i in range(K-1):
  for j in range(i+1,K):
    a="".join(sl[i:j])
    if a not in ans:
      ans.append(a)

ans.sort()
print(ans[K-1])

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

if K==1:
  print(sorted(S)[0])
  exit()

ans=[]
if K<=len(S):
  s0=sorted(S[:-K+1])[0]
  for j,e in enumerate(S[:-K+1]):
    if e==s0:
      for i in range(1,K+1):
        a="".join(S[j:j+i])
        if a not in ans:
          ans.append(a)
      
sl=S[-K+1:]
for i in range(K-1):
  for j in range(i+1,K):
    a="".join(sl[i:j])
    if a not in ans:
      ans.append(a)

ans.sort()
print(ans[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[list(input()) for _ in range(N)]

ans=0
for k in range(N):
  ju=1
  for i in range(N):
    for j in range(N):
      if S[i][(k+j)%N]!=S[j][(k+i)%N]:
        ju=0
        
  if ju==1:
    ans+=1

print(N*ans)

Fixed submission:
N=int(input())
S=[list(input()) for _ in range(N)]

ans=0
for k in range(N):
  ju=1
  for i in range(N):
    for j in range(N):
      if S[i][(k+j)%N]!=S[j][(k+i)%N]:
        ju=0
        
  if ju==1:
    ans+=1

print(N*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(N)]
w1=wv[0][0]
wm=max([i[0] for i in wv])

Wlist=[0]+[j*(w1+i) for j in range(1,N+1) for i in range(4)]
dp=[[0]*(4*N+1) for _ in range(N+1)]
#dp[i][j]:N個の物に対して強度(Wlist[j])のバッグ

for i in range(1,N+1):
  w,v=wv[i-1]
  for j in range(4*N+1):
    if w<=Wlist[j]:
      
      ind=0
      d=float("inf")
      for k in range(4*N+1):
        if (Wlist[j]-w)>=Wlist[k] and (Wlist[j]-w)-Wlist[k]<d:
          d=(Wlist[j]-w)-Wlist[k]
          ind=k
      
      dp[i][j]=max(dp[i-1][j],dp[i-1][ind]+v)
    else:
      dp[i][j]=dp[i-1][j]

ind=0
d=float("inf")
for k in range(4*N+1):
  if W>=Wlist[k] and W-Wlist[k]<d:
    d=W-Wlist[k]
    ind=k
print(dp[N][ind])

Fixed submission:
import bisect
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(N)]
w1=wv[0][0]

Wlist=[0]+[j*w1+i for j in range(1,N+1) for i in range(3*j+1)]
Wlist=sorted(set(Wlist))
LW=len(Wlist)
dp=[[0]*LW for _ in range(N+1)]
#dp[i][j]:N個の物に対して強度(Wlist[j])のバッグ

for i in range(1,N+1):
  w,v=wv[i-1]
  for j in range(LW):
    if w<=Wlist[j]:      
      ind=bisect.bisect_right(Wlist,Wlist[j]-w)-1
      dp[i][j]=max(dp[i-1][j],dp[i-1][ind]+v)
    else:
      dp[i][j]=dp[i-1][j]

ind=bisect.bisect_right(Wlist,W)-1
print(dp[N][ind])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
S=Counter(list(input()))

for i in range(1,N):
  S_=Counter(list(input()))
  for s in S:
    if S_[s]<S[s]:
      S[s]=S_[s]

ans=[]
for s in S:
  for _ in range(S[s]):
    ans.append(s)
print("".join(sorted(ans))

Fixed submission:
from collections import Counter
N=int(input())
S=Counter(list(input()))

for i in range(1,N):
  S_=Counter(list(input()))
  for s in S:
    if S_[s]<S[s]:
      S[s]=S_[s]

ans=[]
for s in S:
  for _ in range(S[s]):
    ans.append(s)
print("".join(sorted(ans)))
Buggy python submission (verdict: Runtime Error):
N = input()
xx= 0
for i in range(1,N+1):
    if((i%3!=0)&(i%5!=0)):
        xx += i
print(xx)

Fixed submission:
N = int(input())
xx= 0
for i in range(1,N+1):
    if((i%3!=0)&(i%5!=0)):
        xx += i
print(xx)
Buggy python submission (verdict: Runtime Error):
x=[]
for i in range(3):
  x[i]=int(input())
print((x[0]+x[1])*x[2]/2)

Fixed submission:
x=[]
for i in range(3):
  x.append(int(input()))
print(int((x[0]+x[1])*x[2]/2))

Buggy python submission (verdict: Runtime Error):
x=[]
for i in range(3):
  x[i]=int(input())
 print((x[0]+x[1])*x[2]/2)

Fixed submission:
x=[]
for i in range(3):
  x.append(int(input()))
print(int((x[0]+x[1])*x[2]/2))
Buggy python submission (verdict: Runtime Error):
n = input()
ans = 0
for i in range(len(n)):
  if n[i] == "7":
	ans += 1
print("Yes" if ans > 0 else "No")

Fixed submission:
n = list(input())
ans = 0
for i in range(len(n)):
  if n[i] == "7":
    ans += 1
print("Yes" if ans > 0 else "No")
Buggy python submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
a = N//(A+B)
ans = a*A
ans2 = min(N-(A+B)*a,A)
print(ans+ans2)

Fixed submission:
s = input()
if s[0] == s[1] and s[1] == s[2]:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
i = a + b
for i in range(n):
  sum += sum + 1

sum = sum + a
print(sum)

Fixed submission:
N,A,B = map(int,input().split())
a = N//(A+B)
ans = a*A
ans2 = min(N-(A+B)*a,A)
print(ans+ans2)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
cnt=0
while n!=0:
    n=n//k
    cnt+=1
print(cnt)

Fixed submission:
N, R = map(int, input().split())
if N > 10:
  print(R)
else :
  print(100 * (10 - N) + R)

Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
sum = 0
while N!=0:
    N = N//K
    sum+=1
print(sum)





Fixed submission:
N, R = map(int, input().split())
if N > 10:
  print(R)
else :
  print(100 * (10 - N) + R)
Buggy python submission (verdict: Runtime Error):
N,R = map(int, input().split())
sum = 0
while(n != 0):
  n = n // k
  sum += 1;
print(sum)
  

Fixed submission:
n,k = map(int, input().split())
cnt=0
while n!=0:
    n=n//k
    cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
for a in A:
    if a%2 == 0 and ( a%3 != 0 and a%5 != 0 ):
        print('DENIED')
        exit()
print('APPROVED')

Fixed submission:
A, B, C = map(int, input().split())
if len(set({A, B, C})) == 2:
       print("Yes")
else:
       print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split())
for a in A:
  if a % 2 == 0 and (a % 3 != and a % 5 != 0):
    print("DENIED")
    exit()
print("APPROVED")

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
for a in A:
    if a%2 == 0 and ( a%3 != 0 and a%5 != 0 ):
        print('DENIED')
        exit()
print('APPROVED')
Buggy python submission (verdict: Runtime Error):
N = input()
S = input()

print(S.count("ABC"))

Fixed submission:
K, X = map(int, input().split())
print("No" if 500*K < X else "Yes")
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
count = 0
for i in range(N):
  if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
    count = count + 1

print(count)

Fixed submission:
N = input()
S = input()

print(S.count("ABC"))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
a="abcdefghijklmnopqrstuvwxyz"
ans=''
for i in S:
  num = a.index(i) + N
  if(num > 25):
    num -= 26
  ans += a[num]
print(ans)

Fixed submission:
N=int(input())
S=input()
a=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
ans=''
for i in (S):
  num=a.index(i)+N
  if(num>25):
    num-=26
  ans+=a[num]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
oh = N//100
ot = (N-oh*100)//10
oo = N-oh*100-ot*10
if oh==7 or ot==7 or oo==7:
    print('Yes')
else:
    print('No')


Fixed submission:
N = int(input())
oh = N//100
ot = (N-oh*100)//10
oo = N-oh*100-ot*10
if oh==7 or ot==7 or oo==7:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M = map(int, input().split())
    A, B = [], []
    for i in range(N):
        a,b = map(int, input().split())
        A.append(a)
        B.append(b)
    # print(A, B)
    # 最小のコスト順に買っていけばよい
    # 同じコストのときはどうするか
    sum = 0
    count = 0
    flg = False
    for i in range(N):
        l = A.index(min(A)) # 最安値となっている要素
        for j in range(B[l]): # 買い占め
            count = count + 1
            sum = sum + A[l]
            if count == M:
                flg = True
                break
        A[l] = max(A) + 1 # 配列Aを書き換え
        if flg:
            break

    print(sum)
    # print(count)

main()

Fixed submission:
def main():
    N, M = map(int, input().split())
    lis = []
    for i in range(N):
        lis.append(list(map(int, input().split())))
    # 最小のコスト順に買っていけばよい
    # 同じコストのときはどうするか
    lis.sort() # 一列目をソート，二列目を対応してくれる，同じ値のときは二列目が低い方を優先
    sum = 0
    count = 0
    flg = False
    for i in range(N):
        if (count+lis[i][1]<M) :
            sum = sum + lis[i][0]*lis[i][1]
            count = count + lis[i][1] # Bi全部
        elif (count+lis[i][1]==M):
            sum = sum + lis[i][0]*lis[i][1]
            count = count + lis[i][1] # Bi全部
            break
        else:
            for j in range(lis[i][1]):
                sum = sum + lis[i][0]
                count = count + 1
                if count==M:
                    flg = True
                    break
        if flg:
            break

    print(sum)
    # print(count)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())

s = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            s += math.gcd(math.gcd(i,j),k)
print(s)

Fixed submission:
import math
n = int(input())

s = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        tmp = math.gcd(i,j)
        for k in range(1,n+1):
            s += math.gcd(tmp,k)

print(s)