Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
cand = ['*'] * M
mn = ''
for m in range(M):
    s, c = map(int, input().split())
    if s==1 and c==0 and N > 1:
        mn = '-1'

    if cand[s-1] == '*' or cand[s-1] == str(c):
        cand[s-1] = str(c)
    else:
        mn = '-1'
if mn == '-1':
    print (mn)
else:  
    for i in range(N):
        if cand[i]=='*':
            if i==0:
                mn+='1'
            else:
                mn+='0'
        else:
            mn+=cand[i]
    print (mn)

Fixed submission:
N, M = map(int, input().split())
cand = ['*'] * N
mn = ''
for m in range(M):
    s, c = map(int, input().split())
    if s==1 and c==0 and N > 1:
        mn = '-1'

    if cand[s-1] == '*' or cand[s-1] == str(c):
        cand[s-1] = str(c)
    else:
        mn = '-1'
if mn == '-1':
    print (mn)
    exit()

for i in range(N):
    if cand[i]=='*':
        if i==0 and N > 1:
            mn+='1'
        else:
            mn+='0'
    else:
        mn+=cand[i]
print (mn)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
cand = ['*'] * M
mn = ''
for m in range(M):
    s, c = map(int, input().split())
    if s==1 and c==0 and N > 1:
        mn = '-1'

    if cand[s-1] == '*' or cand[s-1] == str(c):
        cand[s-1] = str(c)
    else:
        mn = '-1'
if mn == '-1':
    print (mn)
    exit()

for i in range(N):
    if cand[i]=='*':
        if i==0:
            mn+='1'
        else:
            mn+='0'
    else:
        mn+=cand[i]
print (mn)

Fixed submission:
N, M = map(int, input().split())
cand = ['*'] * N
mn = ''
for m in range(M):
    s, c = map(int, input().split())
    if s==1 and c==0 and N > 1:
        mn = '-1'

    if cand[s-1] == '*' or cand[s-1] == str(c):
        cand[s-1] = str(c)
    else:
        mn = '-1'
if mn == '-1':
    print (mn)
    exit()

for i in range(N):
    if cand[i]=='*':
        if i==0 and N > 1:
            mn+='1'
        else:
            mn+='0'
    else:
        mn+=cand[i]
print (mn)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
cand = ['*'] * M
mn = ''
for m in range(M):
    s, c = map(int, input().split())
    if s==1 and c==0:
        mn = '-1'

    if cand[s-1] == '*' or cand[s-1] == str(c):
        cand[s-1] = str(c)
    else:
        mn = '-1'
if mn == '-1':
    print (mn)
    exit()

for i in range(N):
    if cand[i]=='*':
        if i==0:
            mn+='1'
        else:
            mn+='0'
    else:
        mn+=cand[i]
print (mn)

Fixed submission:
N, M = map(int, input().split())
cand = ['*'] * N
mn = ''
for m in range(M):
    s, c = map(int, input().split())
    if s==1 and c==0 and N > 1:
        mn = '-1'

    if cand[s-1] == '*' or cand[s-1] == str(c):
        cand[s-1] = str(c)
    else:
        mn = '-1'
if mn == '-1':
    print (mn)
    exit()

for i in range(N):
    if cand[i]=='*':
        if i==0 and N > 1:
            mn+='1'
        else:
            mn+='0'
    else:
        mn+=cand[i]
print (mn)
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
N, K = map(int,input().split())
P = list(map(int,input().split()))
P = [(p+1)/2 for p in P]
mx = 0
for i in range(N-K+1):
    mx = max(mx,sum(P[i:K+i]))
print (mx)

Fixed submission:
#coding:utf-8
N, K = map(int,input().split())
P = list(map(int,input().split()))
P = [(p+1)/2 for p in P]
mx = sum(P[:K])
sm = sum(P[:K])
for i in range(N-K):
    sm = sm - P[i] + P[K+i]
    mx = max(mx,sm)
print (mx)
Buggy python submission (verdict: Runtime Error):
from math import gcd
#from fractions import gcd
from functools import reduce

def lcm(a,b):
    return a * b // gcd(a,b)
def ls_lcm(A):
    return reduce(lcm ,A)
def ls_gcd(A):
    return reduce (gcd, A)

N, M = map(int, input().split())
A = list(map(int, input().split()))
half = ls_lcm(A) // 2
#print (((M // half) + 1) // 2)
print ((M + half) // (2*half))

Fixed submission:
#from math import gcd
from fractions import gcd
from functools import reduce

def lcm(a,b):
    return a * b // gcd(a,b)
def ls_lcm(A):
    return reduce(lcm ,A)
def ls_gcd(A):
    return reduce (gcd, A)

def check_two(A):
    old = None
    for n in A:
        cnt = 0
        while(n & 1 == 0):
            cnt += 1
            n = n >> 1
        if old is None:
            old = cnt
        else:
            if old!=cnt:
                return False
    return True

N, M = map(int, input().split())
A = list(map(int, input().split()))
if not check_two(A):
    print (0)
    exit()
A = [a//2 for a in A]
half = ls_lcm(A)
print ((M + half) // (2*half))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
import fractions
a = int(input())
b = int(input())
print( a * b // fractions.gcd(a, b))


Fixed submission:
#coding:utf-8
import fractions
a,b = map(int,input().split())
print( a * b // fractions.gcd(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
N = int(input())
A = list(map(int,input().split()))
sm = 0
MOD = 1000000007
for i in range(len(A)-1):
    for j in range(i+1,len(A)):
        sm += A[i]^A[j]
        sm = sm % MOD
print (sm)

# print (MOD)
# left = [0]
# for a in A:
#     sm+=a
#     sm = sm % MOD
#     left.append(sm)
# print (left)
# sm = 0
# right = [0]
# for a in A[::-1]:
#     sm+=a
#     sm = sm % MOD
#     right.append(sm)
# right = right[::-1]
# print (right)


# ans = 0
# for i in range(len(A)):
#     sm = left[i]+right[i+1]
#     if (len(A)%2==0):
#         sm = sm^A[i]
#     ans += sm
#     ans = ans % MOD
# print (ans)

Fixed submission:
#coding:utf-8
MOD = 10 ** 9 + 7
n = int(input())
A = list(map(int, input().split()))
ans = 0
b = 1
for _ in range(60):
    sm = sum(a&b for a in A)
    sm //= b
    ans = (ans + sm * (n-sm) * b) % MOD
    b<<=1
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Fixed submission:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)
            


Fixed submission:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
N = int(input())
S = input()
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==str(q[i]):
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)
            


Fixed submission:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
S = input()
print (len(set(combinations(S,3))))

Fixed submission:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
X, Y = map(int, input().split()))
if (X > Y):
    X, Y = Y, X

if (X+Y)%3 != 0:
    print (0)
    exit()

if (2*X < Y):
    print (0)
    exit()

W = X - ((X+Y)//3)
H = Y - ((X+Y)//3)

mx = 10**6
fact = [1] * (mx+1) # 階乗を格納するリスト
def inv(n): # MODを法とした逆元
    return pow(n, MOD-2, MOD)
for i in range(mx):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算
ans = (fact[W+H] * inv(fact[W]) * inv(fact[H])) % MOD # comb(W+H,W) = (W+H)!/(W!H!)
print (ans)

Fixed submission:
MOD = 10**9+7
X, Y = sorted(list(map(int, input().split())))

if (X+Y)%3 != 0:
    print (0)
    exit()

if (2*X < Y):
    print (0)
    exit()

W = X - ((X+Y)//3)
H = Y - ((X+Y)//3)

mx = 10**6
fact = [1] * (mx+1) # 階乗を格納するリスト
def inv(n): # MODを法とした逆元
    return pow(n, MOD-2, MOD)
for i in range(mx):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算
ans = (fact[W+H] * inv(fact[W]) * inv(fact[H])) % MOD # comb(W+H,W) = (W+H)!/(W!H!)
print (ans)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
s = input()
k = int(input())


if len(set(s))==1:
    print ((len(s)*k)//2)
    exit()

old = ""
ans = 0
for i in range(len(s)):
    if(s[i]==old):
        ans+=1
        old = ""
    else:
        old = s[i]



head = 0
for i in range(len(s)):
    if head==0 or s[i]==s[i-1]:
        head+=1
    else:
        break

tail = 0
t = s[::-1]
for i in range(len(t)):
    if tail==0 or t[i]==t[i-1]:
        tail+=1
    else:
        break

print (ans*k-(k-1)*(head//2)+tail//2)-((head+tail)//2)))



Fixed submission:
#coding: utf-8
s = input()
k = int(input())

if len(set(s))==1:
  print((len(s)*k)//2)
  exit()

dup = [1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    dup[-1]+=1
  else:
    dup.append(1)
    
ans = 0
for i in dup:
  ans += (i//2)*k

if s[0]==s[-1]:
  ans += ((dup[0]+dup[-1])//2 - (dup[0]//2+dup[-1]//2))*(k-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N)
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
    #print (lis)
print (bisect.bisect_left(lis, INF)) a

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N+1)
lis[0] = -1
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
print (bisect.bisect_left(lis, INF) - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N+1)
lis[-1] = -1
for n in range(N):
    i = bisect.bisect(lis[::-1], A[n])    
    lis[N-i] = A[n]
print (bisect.bisect_left(lis[::-1], INF) - 1)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N+1)
lis[0] = -1
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
print (bisect.bisect_left(lis, INF) - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N+1)
lis[-1] = -1
for n in range(N):
    i = bisect.bisect(lis[::-1], A[n])    
    lis[N-i] = A[n]
print (bisect.bisect_left(lis[::-1], INF) - 1)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N+1)
lis[0] = -1
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
print (bisect.bisect_left(lis, INF) - 1)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
argmn = np.argmin(A)
mn = A[argmn]
for m in range(mn+1):
  B = np.zeros(len(A))
  B[argmn] = m * 2
  for i in range(len(A)):
    idx = (i + argmn)%len(A)
    B[(idx+1)%len(A)]  += A[idx] * 2  - B[idx]
  B[argmn] -= m * 2
  if (B[argmn]+B[(argmn+1)%len(A)]==(A[argmn]*2)):
    print (" ".join(B.astype(np.int).astype(np.str)))
    exit()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
sm = sum(A)
x = sm-2*sum(A[1::2])
X = []
X.append(str(x))
for i in range(N-1):
   x = 2*A[i]-x
   X.append(str(x))
print (" ".join(X))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
argmn = np.argmin(A)
mn = A[argmn]
for m in range(mn+1):
  B = np.zeros(len(A))
  B[argmn] = m * 2
  for i in range(len(A)):
    idx = (i + argmn)%len(A)
    B[(idx+1)%len(A)]  += A[idx] * 2  - B[idx]
  B[argmn] -= m * 2
  if (B[argmn]+B[(argmn+1)%len(A)]==(A[argmn]*2)):
    print (" ".join(B.astype(np.int).astype(np.str)))
    exit()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
sm = sum(A)
x = sm-2*sum(A[1::2])
X = []
X.append(str(x))
for i in range(N-1):
   x = 2*A[i]-x
   X.append(str(x))
print (" ".join(X))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
N = int(input())
D = list(map(int,input().split()))
D = sorted(D)
idx = len(D) // 2
print(D[idx] - D[idx-1])

Fixed submission:
#coding:utf-8
from collections import Counter

S = input()
cnt = Counter(list(S))
ls = list(cnt.values())
if (ls[0]==2 and ls[1]==2):
    print ("Yes")
else:
    print ("No")
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
N = int(input())
D = list(map(int,input().split()))
D = sorted(D)
idx = len(D) // 2
print(D[idx] - D[odx-1])

Fixed submission:
#coding:utf-8
N = int(input())
D = list(map(int,input().split()))
D = sorted(D)
#print (D)
a = D[int(len(D)/2)-1:int(len(D)/2)+1]
print (a[1]-a[0])

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
N = int(input())
D = list(map(int,input().split()))
D = sorted(D)
idx = len(D) // 2
print(D[idx] - D[odx-1])

Fixed submission:
#coding:utf-8
N = int(input())
D = list(map(int,input().split()))
D = sorted(D)
#print (D)
a = D[int(len(D)/2)-1:int(len(D)/2)+1]
print (a[1]-a[0])
Buggy python submission (verdict: Runtime Error):
import itertools
import math
MOD = 1000000007
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)% MOD
N,K = map(int,input().split())
for i in range(1,K+1):
    print ((C(N-K+1,i)*C(K-1,i-1))% MOD)


Fixed submission:
import itertools
import math
MOD = 1000000007
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)% MOD
def X(n, r):
  try:
    return C(n-1,n-r) 
  except:
    return 0
N,K = map(int,input().split())

for i in range(1,K+1):
  if (1==i and K==N):
    print (1)
  else:
    print (X(K,i)*((X(N-K,i+1)+2*X(N-K,i)+X(N-K,i-1)))% MOD)

Buggy python submission (verdict: Runtime Error):
import itertools
import math
MOD = 1000000007
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)% MOD
def X(n, r):
  try:
    return C(n-1,n-r) 
  except:
    return 0
N,K = map(int,input().split())

for i in range(1,K+1):
  if (1==i and K==N):
    print (1)
  else:
    #print (X(K,i)*((X(N-K,i+1)+2*X(N-K,i)+X(N-K,i-1)))% MOD)
    print ((C(N-K+1,i)*C(K-1,i-1))% MOD)


Fixed submission:
import itertools
import math
MOD = 1000000007
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)% MOD
def X(n, r):
  try:
    return C(n-1,n-r) 
  except:
    return 0
N,K = map(int,input().split())

for i in range(1,K+1):
  if (1==i and K==N):
    print (1)
  else:
    print (X(K,i)*((X(N-K,i+1)+2*X(N-K,i)+X(N-K,i-1)))% MOD)

Buggy python submission (verdict: Runtime Error):
import itertools
import math
MOD = 1000000007
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)% MOD
def X(n, r):
  try:
    return C(n-1,n-r) 
  except:
    return 0
N,K = map(int,input().split())

for i in range(1,K+1):
  if (1==i and K==N):
    print (1)
  else:
    #ßprint (X(K,i)*((X(N-K,i+1)+2*X(N-K,i)+X(N-K,i-1)))% MOD)
    print (C(N-K+1,i)*C(K-1,i-1)% MOD)


Fixed submission:
import itertools
import math
MOD = 1000000007
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)% MOD
def X(n, r):
  try:
    return C(n-1,n-r) 
  except:
    return 0
N,K = map(int,input().split())

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



Fixed submission:
N, M = map(int, input().split())
MOD = 10 ** 9 + 7
ng = set([int(input()) for _ in range(M)])
ans = [0, 1] 
for i in range(1, N+1):
  if i in ng:
    ans.append(0)
  else:
    ans.append((ans[-2] + ans[-1]) % MOD)
print(ans[-1] % MOD)

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
from math import *
def fib(n):
    return round(( ((1 + sqrt(5))/2)**n - ((1 - sqrt(5))/2)**n ) / sqrt(5))
F = 10001
MD = 1000000007
ls = [0,1]
for f in range(F-2):
    s = sum(ls[-2:])
    ls.append(s)
def fib2(n):
    return ls[n]
old_a = 0
diff = []
N,M = map(int, input().split())
for m in range(M):
    a = int(input())
    if a-old_a==1 and old_a != 0:
        print (0)
        exit()
    diff.append(a-old_a)
    old_a = a
diff.append(N - old_a)
    
#print (diff)
ans = 1
for i,d in enumerate(diff):
    if i!=0 and i!=len(diff)-1:
        d-=1
    ans *= fib2(d)
    #ans %= 1000000007
print (ans % MD)
#print (ans)



Fixed submission:
N, M = map(int, input().split())
MOD = 10 ** 9 + 7
ng = set([int(input()) for _ in range(M)])
ans = [0, 1] 
for i in range(1, N+1):
  if i in ng:
    ans.append(0)
  else:
    ans.append((ans[-2] + ans[-1]) % MOD)
print(ans[-1] % MOD)

Buggy python submission (verdict: Runtime Error):
#coding:utf-8
from math import *
def fib(n):
    return round(( ((1 + sqrt(5))/2)**n - ((1 - sqrt(5))/2)**n ) / sqrt(5))
F = 1001
MD = 1000000007
ls = [0,1]
for f in range(F-2):
    s = sum(ls[-2:])
    ls.append(s)
def fib2(n):
    return ls[n]
old_a = 0
diff = []
N,M = map(int, input().split())
for m in range(M):
    a = int(input())
    if a-old_a==1 and old_a != 0:
        print (0)
        exit()
    diff.append(a-old_a)
    old_a = a
diff.append(N - old_a)
    
#print (diff)
ans = 1
for i,d in enumerate(diff):
    if i!=0 and i!=len(diff)-1:
        d-=1
    ans *= fib(d)
    #ans %= 1000000007
print (ans % MD)
#print (ans)



Fixed submission:
N, M = map(int, input().split())
MOD = 10 ** 9 + 7
ng = set([int(input()) for _ in range(M)])
ans = [0, 1] 
for i in range(1, N+1):
  if i in ng:
    ans.append(0)
  else:
    ans.append((ans[-2] + ans[-1]) % MOD)
print(ans[-1] % MOD)
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 n in range(M):
    B, C = map(int,input().split())
    for b in range(B):
        if C > A[0]:
            heapq.heappushpop(A,C)
        else:
            break
print (sum(A))



Fixed submission:
import heapq
N, M = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)
ls_BC = []
for m in range(M):
    ls_BC.append(list(map(int,input().split())))
#print(ls_BC)
ls_BC = sorted(ls_BC, key=lambda x: x[1],reverse=True)
#print(ls_BC)
for B,C in ls_BC:
    for b in range(B):
        if C > A[0]:
            heapq.heappushpop(A,C)
        else:
            break
print (sum(A))

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 n in range(M):
    B, C = map(int,input().split())
    for b in range(B):
        if C > A[0]:
            heapq.heappushpop(A,C)
        else:
            break
print (sum(A))



Fixed submission:
import heapq
N, M = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)
ls_BC = []
for m in range(M):
    ls_BC.append(list(map(int,input().split())))
#print(ls_BC)
ls_BC = sorted(ls_BC, key=lambda x: x[1],reverse=True)
#print(ls_BC)
for B,C in ls_BC:
    for b in range(B):
        if C > A[0]:
            heapq.heappushpop(A,C)
        else:
            break
print (sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
#coding:utf-8
N = int(input())
S = input()
ans = 1000000
for i in range(N+1):
    l = S[:i]
    r = S[i:]
    #print (l,r)
    cnt = l.count("#")+r.count(".")
    #print (cnt)
    if cnt < ans:
        ans = cnt
print (ans)


Fixed submission:
#coding:utf-8
N = int(input())
S = input()
lb = 0
lw = 0
rb = S.count("#")
rw = S.count(".")
ans = lb + rw
for i in range(N):
    if S[i] == "#":
        lb += 1
        rb -= 1
    else:
        lw += 1
        rw -= 1
    ans = min(ans,lb+rw)
print (ans)
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
import copy
N, K = map(int,input().split())
T = []
D = []
ls_td = []
for n in range(N):
    t, d = map(int,input().split())
    ls_td.append([t,d])
ls_td = sorted(ls_td, key=lambda x: x[1])[::-1]
head = ls_td[:K]
tail = ls_td[K:]
def get_set(mat):
    st = set()
    for t,d in mat:
        st.add(t)
    return st
def score(mat):
    r = 0
    ls_t = set()
    for t,d in mat:
        ls_t.add(t)
        r += d
    r += len(ls_t)**2
    return r

def search_del(mat):
    idx = -1
    st = set()
    for i,(t,d) in enumerate(mat):
        if t in st:
            idx = i
        st.add(t)
    return idx
st = get_set(head)
current_score = score(head)
idx = search_del(head)
for t,d in tail:
    if idx == -1:
        break

    if t in st:
        pass
    else:
        new = copy.deepcopy(head)
        new[idx] = t,d
        candidate_score = score(new)
        if current_score < candidate_score:
            head = new
            st.add(t)
            current_score = candidate_score
            idx = search_del(head)
print (current_score) 
        


Fixed submission:
#coding:utf-8
a,b,c = map(int,input().split())
s = (a+b+c)/2.0
S = (s * (s-a) * (s-b) * (s-c)) ** 0.5
print (int(S))
Buggy python submission (verdict: Runtime Error):
#coding:utf-8
n,k = map(int,input().split())
ls = []
for i in range(n):
    ls.append(int(input()))
ls = sorted(ls)
ans = 10000000
for i in range(n-k+1):
    mx = max(ls[i:k+1])
    mn = min(ls[i:k+1])
    ans = min(ans,mx - mn)
print (ans)

Fixed submission:
#coding:utf-8
n,k = map(int,input().split())
ls = []
for i in range(n):
    ls.append(int(input()))
#ls = [100000-i for i in range(100000)]
#n = 100000
#k = 1000
ls = sorted(ls)
ans = 1000000000
for i in range(n-k+1):
    mx = ls[i+k-1]
    mn = ls[i]
    ans = min(ans,mx - mn)
print (ans)