Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
L=[tuple(map(int,input().split())) for i in range(N)]
dp=[[-1]*(H+1) for i in range(N+1)]
for d in dp:
    d[0]=0
dp[0]=[10**9]*(H+1)
i=1
for a,b in L:
    for j in range(H+1):
        if j<a:
            dp[i][j]=min(dp[i-1][j],b)
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-a]+b)
    i+=1
print(dp[N][H-1])

Fixed submission:
H,N=map(int,input().split())
L=[tuple(map(int,input().split())) for i in range(N)]
dp=[[-1]*(H+1) for i in range(N+1)]
for d in dp:
    d[0]=0
dp[0]=[10**9]*(H+1)
i=1
for a,b in L:
    for j in range(H+1):
        if j<a:
            dp[i][j]=min(dp[i-1][j],b)
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-a]+b)
    i+=1
print(dp[N][H-1])
Buggy python submission (verdict: Runtime Error):
N,X=map(int, input(),split())
print("Yes" if 500*N >= X else "No")

Fixed submission:
N,X=map(int, input().split())
print("Yes" if 500*N >= X else "No")
Buggy python submission (verdict: Runtime Error):
S=list(map(int, input().split()))
if S[2] >= S[0]+S[1]:
  print(0,0)
else S[2] >= S[0]:
  print(0,S[1]+S[0]-S[2])
else:
  print(S[0]-S[2],S[1])

Fixed submission:
S=list(map(int, input().split()))
if S[2] >= S[0] + S[1]:
  print(0,0)
elif S[2] >= S[0]:
  print(0,S[1]+S[0]-S[2])
else:
  print(S[0]-S[2],S[1])
Buggy python submission (verdict: Runtime Error):
def is_prime(int x):
  if x <= 1: return false
  int i=2
  while i*i <= x:
    if x%i: return False
    i+=1
  return True

X=int(input())
while is_prime(X):
  X+=1
print(X)

Fixed submission:
def is_prime(x):
  if x <= 1: return false
  i=2
  while i*i <= x:
    if not x%i: return False
    i+=1
  return True
 
X=int(input())
while not is_prime(X):
  X+=1
print(X)

Buggy python submission (verdict: Time Limit Exceeded):
L=[i for i in range(2,10**5)]
X=int(input())
while X > L[0]:
  a=L[0]
  for l in L:
    if not l%a:
      L.remove(l)
print(L[0])

Fixed submission:
def is_prime(x):
  if x <= 1: return false
  i=2
  while i*i <= x:
    if not x%i: return False
    i+=1
  return True
 
X=int(input())
while not is_prime(X):
  X+=1
print(X)

Buggy python submission (verdict: Time Limit Exceeded):
L=[i for i in range(2,10**5)]
X=int(input())
while X > L[0]:
  L=list(filter(lambda x: x & L[0], L))
print(L[0])

Fixed submission:
def is_prime(x):
  if x <= 1: return false
  i=2
  while i*i <= x:
    if not x%i: return False
    i+=1
  return True
 
X=int(input())
while not is_prime(X):
  X+=1
print(X)
Buggy python submission (verdict: Runtime Error):
A=[int(input()),int(input())]
if not 1 in A:
  print(1)
elif not 2 in A:
  print(2)
else not 3 in A:
  print(3)

Fixed submission:
L=[int(input()),int(input())]
if not 1 in L:
  print(1)
elif not 2 in L:
  print(2)
else:
  print(3)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
T=input()
U=[]
for i in range(N):
  U.append(S[i])
  U.append(T[i])
print(U)

Fixed submission:
N=int(input())
S,T=input().split()
U=[]
for i in range(N):
  U.append(S[i])
  U.append(T[i])
print("".join(U))
Buggy python submission (verdict: Runtime Error):
S=input()
s=0
for i in range(len(S)//2)
	if S[i] != S[-i-1]: s+=1
print(s)

Fixed submission:
S=input()
s=0
for i in range(len(S)//2):
	if S[i] != S[-i-1]: s+=1
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
s=0
for i in range(N-1):
  s+=sum([A[i]^a for a in A[i+1:]])
print(s%(10**9+7))

Fixed submission:
mod=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
 
for i in range(60):
  x=0
  for j in range(N):
    if A[j]>>i&1: x+=1
  ans+=x*(N-x)*(2**i)
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

MOD = 10**9 + 7

X,Y = map(int, input().split())

if not (X+Y) % 3:
    m = (2*X - Y)//3
    n = (2*Y - X)//3
    if n >= 0 and m >= 0:
        print(comb(n+m,min(n,m)) % MOD)
    else:
        print(0)
else:
    print(0)


Fixed submission:
MOD = 10**9 + 7

def comb(n,r):
  if (r<0 and r>n):
    return 0
  r = min(r,n-r)
  return g1[n] * g2[r] * g2[n-r] % MOD

N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N+1):
  g1.append((g1[-1]*i)%MOD)
  inverse.append((-inverse[MOD%i]*(MOD//i))%MOD)
  g2.append((g2[-1]*inverse[-1])%MOD)
  
X,Y = map(int, input().split())


if not (X+Y) % 3:
    m = (2*X - Y)//3
    n = (2*Y - X)//3
    if n >= 0 and m >= 0:
        print(comb(n+m,n))
    else:
        print(0)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

MOD = 10**9 + 7

X,Y = map(int, input().split())

if not (X+Y) % 3:
    m = (2*X - Y)//3
    n = (2*Y - X)//3
    if n >= 0 and m >= 0:
        print(comb(n+m,min(n,m)) % MOD)
    else:
        print(0)
else:
    print(0)


Fixed submission:
MOD = 10**9 + 7

def comb(n,r):
  if (r<0 and r>n):
    return 0
  r = min(r,n-r)
  return g1[n] * g2[r] * g2[n-r] % MOD

N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N+1):
  g1.append((g1[-1]*i)%MOD)
  inverse.append((-inverse[MOD%i]*(MOD//i))%MOD)
  g2.append((g2[-1]*inverse[-1])%MOD)
  
X,Y = map(int, input().split())


if not (X+Y) % 3:
    m = (2*X - Y)//3
    n = (2*Y - X)//3
    if n >= 0 and m >= 0:
        print(comb(n+m,n))
    else:
        print(0)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
L=list(map(int, input().split()))
L.sort()
L.reverse()
a=L.pop(0)
count=0
while(L!=[]):
    for i in range(len(L)):
        for j in range(i+1,len(L)):
            if a < L[i]+L[j]:
                count+=1
    a=L.pop(0)
print(count)

Fixed submission:
A,B=map(int, input().split())
print(A-2*B if A > 2*B else 0)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int, input().split()))
L.sort()
L.reverse()
a=L.pop(0)
count=0
while(L!=[]):
    for i in range(len(L)):
        for j in range(i+1,len(L)):
            if a < L[i]+L[j]:
                count+=1
    a=L.pop(0)
print(count)

Fixed submission:
import bisect

N=int(input())
L=list(map(int, input().split()))
ll=len(L)
L.sort()

s=0
for i in range(ll):
    for j in range(i+1,ll):
        s+=bisect.bisect_right(L,L[i]+L[j]-1)-j-1

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int, input().split()))
L.sort()
L.reverse()
a=L.pop(0)
count=0
while(L!=[]):
    for i in range(len(L)):
        for j in range(i+1,len(L)):
            if a < L[i]+L[j]:
                count+=1
    a=L.pop(0)
print(count)


Fixed submission:
import bisect

N=int(input())
L=list(map(int, input().split()))
ll=len(L)
L.sort()

s=0
for i in range(ll):
    for j in range(i+1,ll):
        s+=bisect.bisect_right(L,L[i]+L[j]-1)-j-1

print(s)
Buggy python submission (verdict: Runtime Error):
S=input()

p=True
q=True
for i in S:
  if p:
    if not i=='L':
      p=False
	else:
      q=False
      break
  else:
    if not i=='R':
      p=True
    else:
      q=False
      break
      
print ("Yes" if q else "No")

Fixed submission:
S=input()

p=True
q=True
for i in S:
  if p:
    if not i=='L':
      p=False
    else:
      q=False
      break
  else:
    if not i=='R':
      p=True
    else:
      q=False
      break

print ("Yes" if q else "No")
Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int, input().split())

A = [K for _ in range(N)]

for _ in range(N):
    A[int(input())-1] += 1
for i in range(N):
    print("Yes" if A[i] > Q else "No")


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

A = [K for _ in range(N)]

for _ in range(Q):
    A[int(input())-1] += 1
for i in range(N):
    print("Yes" if A[i] > Q else "No")

Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int, input().split())
A = [K for _ in N]
for _ in N:
  a = int(input())
  A[a-1] += 1
for i in N:
  if A[i] > Q:
    print("Yes")
  else:
    print("No")

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

A = [K for _ in range(N)]

for _ in range(Q):
    A[int(input())-1] += 1
for i in range(N):
    print("Yes" if A[i] > Q else "No")
Buggy python submission (verdict: Runtime Error):
A,B = map(int, input().split())
if B==1:
  print(0)
else if B<A:
  print(1)
else:
  print(B//(A-1))

Fixed submission:
import math
A,B = map(int, input().split())
print(math.ceil((B-1)/(A-1)))
Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
tree=[[] for _ in range(N)]
counter=[0]*N
for _ in range(N-1):
    a,b=map(int, input().split())
    tree[a-1].append(b-1)
for _ in range(Q):
    p,x=map(int, input().split())
    counter[p-1]+=x
def f(t,x):
    for i in t:
        counter[i]+=x
        f(tree[i],counter[i])
f(tree[0],counter[0])
counter=list(map(str, counter))
print(' '.join(counter))


Fixed submission:
from collections import deque

N,Q=map(int,input().split())
to=[[] for _ in range(N)]
count=[0]*N
for _ in range(N-1):
    a,b=map(int, input().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
for _ in range(Q):
    p,x=map(int, input().split())
    count[p-1]+=x
q = deque()
q.append(0)
p=[True]*N
while q:
    i = q.pop()
    if p[i]:
        p[i]=False
        for j in to[i]:
            if p[j]:
                count[j]+=count[i]
                q.append(j)
print(*count)

Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
s=[0]*N
tree=[[] for _ in range(N)]
counter=[0]*N
def pl(t,x):
    if t:
        for i in t:
            s[i]+=x
            pl(tree[i],x)
for _ in range(N-1):
    a,b=map(int, input().split())
    tree[a-1].append(b-1)
for _ in range(Q):
    p,x=map(int, input().split())
    s[p-1]+=x
    pl(tree[p-1],x)
s=list(map(str, s))
print(' '.join(s))


Fixed submission:
from collections import deque

N,Q=map(int,input().split())
to=[[] for _ in range(N)]
count=[0]*N
for _ in range(N-1):
    a,b=map(int, input().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
for _ in range(Q):
    p,x=map(int, input().split())
    count[p-1]+=x
q = deque()
q.append(0)
p=[True]*N
while q:
    i = q.pop()
    if p[i]:
        p[i]=False
        for j in to[i]:
            if p[j]:
                count[j]+=count[i]
                q.append(j)
print(*count)

Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
s=[0]*N
tree=[[] for _ in range(N)]
counter=[0]*N
def pl(t,x):
    if t:
        for i in t:
            s[i]+=x
            pl(tree[i],x)
for _ in range(N-1):
    a,b=map(int, input().split())
    tree[a-1].append(b-1)
for _ in range(Q):
    p,x=map(int, input().split())
    s[p-1]+=x
    pl(tree[p-1],x)
s=[str(i) for i in s]
print(' '.join(s))


Fixed submission:
from collections import deque

N,Q=map(int,input().split())
to=[[] for _ in range(N)]
count=[0]*N
for _ in range(N-1):
    a,b=map(int, input().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
for _ in range(Q):
    p,x=map(int, input().split())
    count[p-1]+=x
q = deque()
q.append(0)
p=[True]*N
while q:
    i = q.pop()
    if p[i]:
        p[i]=False
        for j in to[i]:
            if p[j]:
                count[j]+=count[i]
                q.append(j)
print(*count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
sl = []
for _ in range(n):
    sl.append(input())
rl=[]
ll=[]
rslt=0
for i in range(n):
    r=sorted(sl[i])
    if r in rl: ll[rl.index(r)]+=1; rslt+=ll[rl.index(r)]
    else: rl.append(r); ll.append(0)
print(rslt)


Fixed submission:
a,b = map(int, input().split())
r=[a+b, a-b, a*b]
print(max(r))
Buggy python submission (verdict: Runtime Error):
n = int(input())
sl = []
for _ in range(n):
    sl.append(input())
rl=[[0 for _ in range(26)] for _ in range(n)]
for i in range(n):
    for c in sl[i]:
        a=ord(c)-ord('a')
        rl[i][a]+=1
rslt=0
for i in range(n-1):
    for j in range(i+1,n):
        if rl[i] == rl[j]: rslt+=1
print(rslt)


Fixed submission:
import heapq

N,M = map(int, input().split())
jobs = [[] for _ in range(M)]
for _ in range(N):
    a,b = map(int, input().split())
    if a <= M: jobs[a-1].append(b)
h=[]
rsl=0
for i in range(M):
    for j in jobs[i]:
        heapq.heappush(h, -j)
    if len(h) > 0:
        rsl += -heapq.heappop(h)
print(rsl)
Buggy python submission (verdict: Runtime Error):
n=input()
l=len(n)
s=0
if l%2==1:
    s+=int(n[1:])+1+(int(n[0])-1)*(10**(l-1))
    l-=1
for i in range(int(l/2)):
    s+=9*10**(i*2)
print(s)


Fixed submission:
n=input()
l=len(n)
s=0
if l>1:
    if l%2==1:
        s+=int(n[1:])+1+(int(n[0])-1)*(10**(l-1))
        l-=1
    for i in range(int(l/2)):
        s+=9*10**(i*2)
    print(s)
else:
    print(int(n))
Buggy python submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input()))
p,a=True,0
for h in H:
  if h>a:
    a=h-1
  elif a>h:
    p=False
    break
print("Yes" if p else "No")

Fixed submission:
n=int(input())
hl=list(map(int, input().split()))
m=0
for h in hl:
    if m <= h: m = h
    elif m == h+1: continue
    else: print("No"); break
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
S=input()
dp_old=[0]*13
dp_new=[0]*13
dp_old[0]=1
for c in S:
    if c == '?':
        for i in range(10):
            for j in range(13):
                dp_new[(j*10+i)%13]+=dp_old[j]
    else:
        for i in range(13):
            dp_new[(i*10+int(c))%13]+=dp_old[i]
    dp_old = [i%MOD for i in dp_new]
    dp_new = [0]*13
print(dp_old[5])


Fixed submission:
MOD = 10**9+7
S=input()
dp_old=[0]*13
dp_new=[0]*13
dp_old[0]=1
for c in S:
    if c == '?':
        for i in range(10):
            for j in range(13):
                dp_new[(j*10+i)%13]+=dp_old[j]
    else:
        for i in range(13):
            dp_new[(i*10+int(c))%13]+=dp_old[i]
    dp_old = [i%MOD for i in dp_new]
    dp_new = [0]*13
print(dp_old[5])
Buggy python submission (verdict: Runtime Error):
N=int(input())
l=[]
l.append(int(input()))
l.append(int(input()))
m1=max(l)
mx=min(l)
for _ in range(N-2):
  l.append(int(input()))
  if l[-1] >= m1:
    m2 = m1
    m1 = l[-1]
  elif l[-1] > m2:
    m2 = l[-1]
for i in range(N):
  if l[i] == m1:
    print(m2)
  else:
    print(m1)

Fixed submission:
N=int(input())
l=[]
l.append(int(input()))
l.append(int(input()))
m1=max(l)
m2=min(l)
for _ in range(N-2):
  l.append(int(input()))
  if l[-1] >= m1:
    m2 = m1
    m1 = l[-1]
  elif l[-1] > m2:
    m2 = l[-1]
for i in range(N):
  if l[i] == m1:
    print(m2)
  else:
    print(m1)
Buggy python submission (verdict: Runtime Error):
import math

N,D=map(int,input().split())
X=[]
for _ in range(N):
  X.append(list(map(int, input().split())))
count=0
for i in range(N-1):
  for j in range(i+1,N):
    a=0
    for k in range(D):
      a+=(X[i][k]-X[j][k])**2
    if math.sqrt(a).is_integer():
      coutn+=1
print(count)

Fixed submission:
import math
 
N,D=map(int,input().split())
X=[]
for _ in range(N):
  X.append(list(map(int, input().split())))
count=0
for i in range(N-1):
  for j in range(i+1,N):
    a=0
    for k in range(D):
      a+=(X[i][k]-X[j][k])**2
    if math.sqrt(a).is_integer():
      count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
d.sorted()
print(d[n/2]-d[n/2-1])

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
d.sort()
print(d[n//2]-d[n//2-1])
Buggy python submission (verdict: Runtime Error):
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

mod=10**9+7
N,K=map(int,input().split())
for i in range(1,K+1):
    print(int(cmb(N+1-K,i)*cmb(K-1,i-1))%mod)


Fixed submission:
def make_comb_dp(n):
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 1
        dp[i][i] = 1
    for i in range(2, n + 1):
        for j in range(1, i):
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]
    return dp

mod=10**9+7
N,K=map(int,input().split())
C=make_comb_dp(N)
for i in range(1,K+1):
    print(int(C[N+1-K][i]*C[K-1][i-1])%mod)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
mod=10**9+7
N,K=map(int,input().split())
for i in range(1,K+1):
    print(int(comb(N+1-K,i)*comb(K-1,i-1))%mod)


Fixed submission:
def make_comb_dp(n):
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 1
        dp[i][i] = 1
    for i in range(2, n + 1):
        for j in range(1, i):
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]
    return dp

mod=10**9+7
N,K=map(int,input().split())
C=make_comb_dp(N)
for i in range(1,K+1):
    print(int(C[N+1-K][i]*C[K-1][i-1])%mod)
Buggy python submission (verdict: Runtime Error):
S=input()
p = a
for s in S:
  if p == s:
    p = a
    break
  else:
    p = s
print("Bad" if p == a else "Good")

Fixed submission:
S=input()
p = 'a'
for s in S:
  if p == s:
    p = 'a'
    break
  else:
    p = s
print("Bad" if p == 'a' else "Good")
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=list(map(int, input().split()))
A=[]
for i in range(1,N-1):
  A.append(abs(S[:i]-S[i:]))
print(min(A))

Fixed submission:
N=int(input())
S=list(map(int, input().split()))
A=[]
for i in range(1,N):
  A.append(abs(sum(S[:i])-sum(S[i:])))
print(min(A) if not A==[] else abs(S[0]-S[1]))
Buggy python submission (verdict: Runtime Error):
MOD=10**9+7
N,M=map(int,input().split())
A=[int(input()) for _ in range(M)]
L=[-1 for _ in range(N)]
p=0
if 1 == A[p]:
  L[0] = 0
  if p < M-1:
    p +=1
else:
  L[0] = 1
if N>1:
  if 2 == A[p]:
    L[1] = 0
    if p < M-1:
      p+=1
  else:
    L[1]=L[0]+1
for i in range(2,N):
  if i+1 == A[p]:
    L[i] = 0
    if p < M-1:
      p+=1
  else:
    L[i]=L[i-1]+L[i-2]
print(L[-1]%MOD)

Fixed submission:
MOD=10**9+7
N,M=map(int,input().split())
A=[int(input()) for _ in range(M)]
L=[-1 for _ in range(N)]
p=0
if A == []:
  A=[0]
if 1 == A[p]:
  L[0] = 0
  if p < M-1:
    p +=1
else:
  L[0] = 1
if N>1:
  if 2 == A[p]:
    L[1] = 0
    if p < M-1:
      p+=1
  else:
    L[1]=L[0]+1
for i in range(2,N):
  if i+1 == A[p]:
    L[i] = 0
    if p < M-1:
      p+=1
  else:
    L[i]=L[i-1]+L[i-2]
print(L[-1]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
N,M=map(int,input().split())
A=[int(input()) for _ in range(M)]
L=[-1 for _ in range(N)]
if 1 in A:
  L[0] = 0
else:
  L[0] = 1
if N>1:
  if 2 in A:
    L[1] = 0
  else:
    L[1]=L[0]+1
for i in range(2,N):
  if i+1 in A:
    L[i] = 0
  else:
    L[i]=L[i-1]+L[i-2]
print(L[-1]%MOD)

Fixed submission:
MOD=10**9+7
N,M=map(int,input().split())
A=[int(input()) for _ in range(M)]
L=[-1 for _ in range(N)]
p=0
if A == []:
  A=[0]
if 1 == A[p]:
  L[0] = 0
  if p < M-1:
    p +=1
else:
  L[0] = 1
if N>1:
  if 2 == A[p]:
    L[1] = 0
    if p < M-1:
      p+=1
  else:
    L[1]=L[0]+1
for i in range(2,N):
  if i+1 == A[p]:
    L[i] = 0
    if p < M-1:
      p+=1
  else:
    L[i]=L[i-1]+L[i-2]
print(L[-1]%MOD)
Buggy python submission (verdict: Runtime Error):
x,D,xx=map(int,input().split())
for i for range(10):
  xx = x*xx-D
  print(xx)

Fixed submission:
x,D,xx=map(int,input().split())
for i in range(10):
  xx = x*xx-D
  print(xx)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
heapq.heapify(A)
for _ in range(M):
  b,c=map(int,input().split())
  for _ in range(b):
    a=heapq.heappop(A)
    if c>a:
      heapq.heappush(A,c)
    else:
      heapq.heappush(A,a)
      break
print(sum(A))


Fixed submission:
N,M=map(int,input().split())
A=map(int,input().split())
L=[(1,a) for a in A]
for _ in range(M):
  b,c=map(int,input().split())
  L.append((b,c))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
  if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
heapq.heapify(A)
for _ in range(M):
  b,c=map(int,input().split())
  for _ in range(b):
    a=heapq.heappop(A)
    if c>a:
      heapq.heappush(A,c)
    else:
      heapq.heappush(A,a)
      break
print(sum(A))

Fixed submission:
N,M=map(int,input().split())
A=map(int,input().split())
L=[(1,a) for a in A]
for _ in range(M):
  b,c=map(int,input().split())
  L.append((b,c))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
  if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input=sys.stdin.readline
N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
done=[0]
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if not v in done:
      deque.append(d,v)
      done.append(v)
      ans[v]=color^(w%2)
print(*ans,sep='\n')

Fixed submission:
import sys
from collections import deque
input=sys.stdin.readline
N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2)
print(*ans,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
done=[0]
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if not v in done:
      deque.append(d,v)
      done.append(v)
      ans[v]=color^(w%2)
print(*ans,sep='\n')

Fixed submission:
import sys
from collections import deque
input=sys.stdin.readline
N=int(input())
tree=[[] for _ in range(N)]
for _ in range(N-1):
  u,v,w=map(int,input().split())
  tree[u-1].append((v-1,w))
  tree[v-1].append((u-1,w))
ans=[-1]*N
ans[0]=0
d=deque([0])
while d:
  p=deque.popleft(d)
  color=ans[p]
  for v,w in tree[p]:
    if ans[v]==-1:
      deque.append(d,v)
      ans[v]=color^(w%2)
print(*ans,sep='\n')
Buggy python submission (verdict: Runtime Error):
import math
ans=0
A=[int(input()) for i in range(5)]
a=0
for i in range(5):
  if (A[i]%10)>a:
    p=i
    a=A[i]
for i in range(5):
  if i==p:
    ans+=A[i]
  else:
    ans+=10*(math.ceil(A[i]/10))
print(ans)

Fixed submission:
import math
ans=0
A=[int(input()) for i in range(5)]
a=10
p=0
for i in range(5):
  if a>(A[i]%10) and A[i]%10!=0:
    p=i
    a=A[i]%10
for i in range(5):
  if i==p:
    ans+=A[i]
  else:
    ans+=10*(math.ceil(A[i]/10))
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
ans=0
A=[int(input()) for i in range(5)]
a=10
for i in range(5):
  if a>A[i]:
    p=i
    a=A[i]
for i in range(5):
  if i==p:
    ans+=A[i]
  else:
    ans+=10*(math.ceil(A[i]/10))
print(ans)

Fixed submission:
import math
ans=0
A=[int(input()) for i in range(5)]
a=10
p=0
for i in range(5):
  if a>(A[i]%10) and A[i]%10!=0:
    p=i
    a=A[i]%10
for i in range(5):
  if i==p:
    ans+=A[i]
  else:
    ans+=10*(math.ceil(A[i]/10))
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
n=1
while K>1:
  n+=1
  if A%n==0 and B%==0:
    K-=1
print(n)

Fixed submission:
A,B,K=map(int,input().split())
k=0
n=min(A,B)
while 1:
  if A%n==0 and B%n==0:
    k+=1
  if K==k:
    break
  n-=1
print (n)

Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
for i in range(1,range(max(a,b)+1)):
  if a%i==0 and b%i==0:
    k-=1
    if k==0:
      break
print(i)

Fixed submission:
A,B,K=map(int,input().split())
k=0
n=min(A,B)
while 1:
  if A%n==0 and B%n==0:
    k+=1
  if K==k:
    break
  n-=1
print (n)
Buggy python submission (verdict: Runtime Error):
btc=380000
N=int(input())
ans=0
for i in range(N):
  x,u=input().split()
  if u=='JPY':
    ans+=int(x)
  else:
    ans+=int(x)*btc
print(ans)

Fixed submission:
btc=380000
N=int(input())
ans=0
for i in range(N):
  x,u=input().split()
  if u=='JPY':
    ans+=float(x)
  else:
    ans+=float(x)*btc
print(ans)