Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02951 (python)

Fixed submission:
# -*- coding: utf-8 -*-
a,b,c = map(int, raw_input().split())

# box1 の許容容量
tmp = a - b
rest = c - tmp

if rest >= 0:
    print rest
else:
    print 0

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, raw_input().split())

# box1 の許容容量
tmp = a - b
rest = c - tmp

print rest
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
 
if a < 3200:
  print('red')
else:
  print(s)

Buggy submission (verdict: Runtime Error):
a = int(input())
s = input()

if a < 3200:
  print('red')
 else:
  print(s)
Problem p03036 (python)

Fixed submission:
r, d, x = map(int, input().split())

for i in range(10):
    x = r*x-d
    print(x)

Buggy submission (verdict: Runtime Error):
r, d, x = map(int, input().split())

for i in range(10):
    x = r*x-d
    print(xi)
Problem p03011 (python)

Fixed submission:
P,Q,R = input().split()
# P = input().split()

# print(P)
# print(Q)
# print(R)

min = min(int(P)+int(Q), int(P)+int(R), int(Q)+int(R))

print(min)

Buggy submission (verdict: Runtime Error):
P,Q,R = int(input().split())
# P = input().split()

# print(P)
# print(Q)
# print(R)

min = min(P+Q, P+R, Q+R)

print(min)
Problem p02984 (python)

Fixed submission:
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import spsolve
import numpy as np

N = int(input())
A = np.array(input().split())

#値の入る座標の準備
rows = np.concatenate([np.arange(N), np.arange(N)])
cols = np.concatenate([np.arange(N), np.arange(1,N+1) % N])

#疎行列の作成
#csr_matrix((値だけのlist, 値の入る座標を示すtulpe:(rows, cols) ), 大きさ (N,N))
mat = csr_matrix(([1] * (2*N), (rows, cols)), (N,N))
#print(rows,cols,mat)
 
answer = (spsolve(mat,A) * 2).astype(int)
print(*answer)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=[int(x) for x in input().split()]

matrix=np.zeros((n,n))

for i in range(n-1):
  matrix[i,i:i+2]+=1
matrix[-1,0]+=1
matrix[-1,-1]+=1

X = 2*np.linalg.solve(matrix, np.array(a)).astype(int)

print(*X)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=[int(x) for x in input().split()]

matrix=np.zeros((n,n))

for i in range(n-1):
  matrix[i,i:i+2]+=1
matrix[-1,0]+=1
matrix[-1,-1]+=1

#A = np.array([[1.,3.] ,[4.,2.]])
#B = np.array([1.,1.])   # 行列Bの生成

X = np.linalg.solve(matrix, np.array(a)).tolist()
# 計算結果の表示
print(*[int(2*item) for item in X])
Problem p02990 (python)

Fixed submission:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
  

n,k=[int(x) for x in input().split()]

for i in range(1,k+1):
  #青をi個に分ける(最低数(i-1個)の赤で)
  a=comb(k-1, i-1, 10**9+7)
  #赤の残りは(n-k)-(i-1)こ
  #これをいいかんじにならべる
  b=comb(n-k+1, i, 10**9+7)
  print((a*b)%(10**9+7))

Buggy submission (verdict: Runtime Error):
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
  

n,k=[int(x) for x in input().split()]

for i in range(1,k+1):
  #青をi個に分ける(最低数(i-1個)の赤で)
  a=comb(k-1, i-1, 10**9+7)
  #赤の残りは(n-k)-(i-1)こ
  #これをいいかんじにならべる
  b=comb(n-k+1, i, 10**9+7)
  print(a,b,(a*b)%p)
Problem p03038 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from operator import itemgetter
 
N,M = map(int,readline().split())
a = list(map(int,readline().split()))
m = map(int,read().split())
bc = list(zip(m,m))


#[n,m]=[int(x) for x in input().split()]
#a=[int(x) for x in input().split()]
#bc=[[int(x) for x in input().split()] for _ in range(m)]

bc.sort(key = itemgetter(1),reverse=True)
bc.append((N,-1))
change=[]
for b,c in bc:
    change += [c] * b
    if len(change) > N:
        break
 
a += change
a.sort()
answer = sum(a[-N:])
print(answer)

Buggy submission (verdict: Runtime Error):
[n,m]=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
bc=[[int(x) for x in input().split()] for _ in range(m)]

a.sort()
bc.sort(key=lambda x:x[1])
b=[]
for item in bc[::-1]:
  b=b+[item[1],]*item[0]
ans=0
#print(a,b,bc)
for i in range(n):
  if a[i]<b[i]:
    ans=ans+b[i]
  elif i!=n-1:
    ans=ans+sum(a[i:])
    break
print(ans)

Buggy submission (verdict: Runtime Error):
[n,m]=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
bc=[[int(x) for x in input().split()] for _ in range(m)]

a.sort()
bc.sort(key=lambda x:x[1])
b=[]
for item in bc[::-1]:
  b=b+[item[1],]*item[0]
ans=0
print(a,b,bc)
for i in range(n):
  if a[i]<b[i]:
    ans=ans+b[i]
  elif i!=n-1:
    ans=ans+sum(a[i:])
    break
print(ans)

Buggy submission (verdict: Runtime Error):
[n,m]=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
bc=[[int(x)-1 for x in input().split()] for _ in range(m)]

a.sort()
bc.sort(key=lambda x:x[1])
b=[]
for item in bc[::-1]:
  b=b+[item[1],]*item[0]
ans=0
for i in range(n):
  if a[i]<b[i]:
    ans=ans+b[i]
  elif i!=n-1:
    ans=ans+sum(a[i+1:])
    break

print(ans)
Problem p03272 (python)

Fixed submission:
l=list(map(int,input().split()))
print(l[0]-l[1]+1)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())

print(a-b+1)
Problem p03315 (python)

Fixed submission:
s=input()
print(2*len([x for x in s if x=="+"])-len(s))

Buggy submission (verdict: Runtime Error):
s=input()
print(2*len([x for x in s if x=="+"]-len(s)
         )
     )
Problem p02933 (python)

Fixed submission:
a=int(input())
s=input()
if a>=3200:
  print(s)
else:
  print('red')

Buggy submission (verdict: Runtime Error):

Copy
Copy
a=int(input())
s=input()
if a>=3200:
  print(s)
else:
  print('red')
Problem p03835 (python)

Fixed submission:
a,s  = map(int,input().split())

sum = 0
for i in range(0,a+1):
    for j in range(0,a+1):
        if 0 <= s-i-j <= a:
            sum += 1
print(sum)

Buggy submission (verdict: Runtime Error):
a,s  = map(int,input().split())

sum = 0
for i in range(0,a+1):
    for j in range(0,a+1):
        if s-i-j <= a:
            sum + = 1
print(sum)
Problem p02987 (python)

Fixed submission:
S = input()
if all([S.count(x) == 2 for x in set(S)]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
n = min(K, N-K+1)
for k in range(1, n+1):
  print(combination(N-K+1, k) * combination(K-1, k-1) % m)
Problem p02990 (python)

Fixed submission:
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
fact = [1] * (N+1)
for i in range(1, N+1):
  fact[i] = fact[i-1] * i
  
def combination(n, r):
  return fact[n] // fact[r] // fact[n-r]
  
for k in range(1, K+1):
  print(combination(N-K+1, k) % m * combination(K-1, k-1) % m)

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
for k in range(1, K+1):
  print(combination(N-K+1, k) % m * combination(K-1, k-1) % m)

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
for k in range(1, n+1):
  print(combination(N-K+1, k) % m * combination(K-1, k-1) % m)

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
for k in range(1, N-K+2):
  print(combination(N-K+1, k) % m * combination(K-1, k-1))

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
for k in range(1, K+1):
  print(combination(N-K+1, k) % m * combination(K-1, k-1))

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
for k in range(1, K+1):
  print(combination(N-K+1, k) * combination(K-1, k-1) % m)

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
for k in range(1, K+1):
  print(combination(N-K+1, k) * combination(k, k-1) % m)

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
m = 10**9 + 7
import math
def combination(n, r):
  return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
  
for k in range(1, K+1):
  if k in [1, K]:
    print(combination(N - K + 1, k) % m)
  else:
    print(combination(N - K + 1, k) * (K-1) % m)
Problem p02891 (python)

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

L = len(S)
rtn = 0
las = False

if (L == 1):
    rtn = K // 2

else:
    ichi = 0
    mae = S[0]
    i = 1
    while(i < L):
        las = False
        if (S[i] == mae):
            ichi += 1
            i += 1
            las = True
        if (i < L):
            mae = S[i]
        i += 1

    if (las and (i == L+1)): #らすかえた
        rtn = ichi * K

    else: #らすかえてない
        ni = 0
        mae = S[L-1]
        i = 0
        while(i < L):
            las = False
            if (S[i] == mae):
                ni += 1
                i += 1
                las = True
            if (i < L):
                mae = S[i]
            i += 1

        if (las and (i == L+1)): #らすかえた
            T = K // 2
            rtn = ichi * (K - T) + ni * T
        else:
            rtn = ichi + ni * (K - 1)

print(rtn)

Buggy submission (verdict: Runtime Error):
S = str(input())
K = int(input())

L = len(S)
rtn = 0
las = False

if (L == 1):
    rtn = K // 2

else:
    ichi = 0
    mae = S[0]
    i = 1
    while(i < L):
        las = False
        if (S[i] == mae):
            ichi += 1
            i += 1
            las = True
        if (i < L):
            mae = S[i]
        i += 1

    if (las and (i == L+1)): #らすかえた
        rtn = ichi * K

    else: #らすかえてない
        ni = 0
        mae = S[L-1]
        i = 0
        while(i < L):
            las = False
            if (S[i] == mae):
                ni += 1
                i += 1
                las = True
            mae = S[i]
            i += 1

        if (las and (i == L+1)): #らすかえた
            T = K // 2
            rtn = ichi * (K - T) + ni * T
        else:
            rtn = ichi + ni * (K - 1)

print(rtn)
Problem p02989 (python)

Fixed submission:
n=int(input())
l = sorted(list(map(int, input().split())))
print(l[n//2] - l[n//2-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
l = sorted(list(map(int, input().split())))
print(l[n/2] - l[n/2-1])
Problem p02933 (python)

Fixed submission:
a = int(input())
b = input()
if 2800 <= a and a<3200:
    print("red")
elif 3200 <=a and a <=5000:
    print(b)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
if 2800 <= a and a<3200:
    print("red")
elif 3200 <=a and a <=5000:
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if 2800 <= a and a<3200:
    print("red")
elif 3200 <=a and a <=5000:
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if 2800 <= a and a<3200:
    print("red")
else if 3200 <=a and a <=5000:
    print(b)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
if a<3200:
    print("red")
else:
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if 2800<=a and a<3200:
    print("red")
else:
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if 2800<=a and a<3200:
    print("red")
else  
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if 2800<=a and a<3200:
    print("red")
else if 3200 <= a and a <= 5000:
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if 2800<=a and a<3200:
    print("red")
else if 3200 <= a and a <= 5000:
    print(b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if 2800<=a and a<3200:
    print("red")
else if 3200 <= a and a <= 5000:
    print(b)
Problem p02891 (python)

Fixed submission:
S=list(input())
K=int(input())
l=[1]
for i in range(len(S)-1):
    if S[i]==S[i+1]:l[-1]+=1;
    else:l.append(1)
if len(l)==1:ans = len(S)*K//2;
else:
    l2=[i//2 for i in l]
    if S[0]==S[-1]:
        ht=(l[0]+l[-1])//2
        ans=l2.pop(0)
        ans+=l2.pop(-1)
        ans+=sum(l2)*K
        ans+=ht*(K-1)
    else:
        ans=sum(l2)*K
print(int(ans))

Buggy submission (verdict: Runtime Error):
S=list(input())
K=int(input())
l=[1]
for i in range(len(S)-1):
    if S[i]==S[i+1]:l[-1]+=1;
    else:l.append(1)
if len(l)==1:ans = len(S)*K/2;
else:
    l2=[i/2 for i in l]
    if S[0]==S[-1]:
        ht=l(l[0]+l[-1])//2
        ans=ls2.pop(0)
        ans+=l2.pop(-1)
        ans+=sum(l2)*K
        ans+=ht*(K-1)
    else:
        ans=sum(ls)*K
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
if len(set(S)) == 1:
    print(K/2)
    
s=list(S*2)
c=0
for i in range(len(s)-2):
    t=set(s[i:i+2])
    if len(t)==1:
        s[i+1]=""
        c+=1
if S[0]!=S[-1]:
    print(c*K)
else:
    i,h,t=0,0,0
    while S[i]==S[i+1]:
        h+=1
        i+=1
    i=0
    while S[-i]==S[-i-1]:
        t+=1
        i+=1
    print(c*K-(h/2+t/2-(h+t)/2)**(K-1))
Problem p03208 (python)

Fixed submission:
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
print(min([h[i+K-1] - h[i] for i in range(N-K+1)]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
print(min([h[i+K] - h[i] for i in range(N-K+1)]))
Problem p02990 (python)

Fixed submission:
from math import factorial as fac

N, K = map(int, input().split())


def func(n, k, r):
    return (fac(k - 1) * fac(n - k + 1) // (fac(k - r) * fac(r - 1) * fac(n - k - r + 1) * fac(r)))


for i in range(1, K + 1):
    if N-K+1>=i:
        print(func(N, K, i) % (10 ** 9 + 7))
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from math import factorial as fac

N, K = map(int, input().split())


def func(n, k, r):
    return (fac(k - 1) * fac(n - k + 1) // (fac(k - r) * fac(r - 1) * fac(n - k - r + 1) * fac(r)))


for i in range(1, K + 1):
    print(func(N, K, i) % (10 ** 9 + 7))
Problem p02897 (python)

Fixed submission:
def myinput(rownum):
    res = []
    for i in range(rownum):
        temp = input().split(" ")
        res += temp
    return res

def main():
    r = int(myinput(1)[0])
    if r == 1:
        print(1)
    elif r % 2 == 0:
        print(0.5)
    else:
        print((int(r/2)+1)/r)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = input()
    a = list(map(lambda x:int(x),input().split(" ")))
    res = ""
    res = [str(a.index(i+1) + 1) for i in range(len(a))]
    print(" ".join(res))

if __name__ == '__main__':
    main()
Problem p02951 (python)

Fixed submission:
x = list(map(int, input().split()))
x[0] = -1*x[0]
print(max(sum(x), 0))

Buggy submission (verdict: Runtime Error):
x = map(int, input().split())
x[0] = -1*x[0]
print(sum(x))
Problem p02916 (python)

Fixed submission:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

out = 0
out += sum(B_list)
a_prev = 0

for index, a in enumerate(A_list):
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        out += C_list[a-2]
    a_prev = a
    
print(out)

Buggy submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

outNum = 0
outNum += sum(B_list)
a_prev = 0

for index, a in enumerate(A_list):
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        outNum += C_list[index]
    a_prev = a
    
print(out)

Buggy submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

out = 0
out += sum(B_list)
#print("out", out)

a_prev = 0

for index, a in enumerate(A_list):
#    print(index, a, a_prev)
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        out += C_list[index]
    a_prev = a
    
print(out)

Buggy submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

out = 0
out += sum(B_list)
print("out", out)

a_prev = 0

for index, a in enumerate(A_list):
    print(index, a, a_prev)
    if a_prev == 0:
        a_prev = 0
    elif a - a_prev == 1:
        out += C_list[index]
    a_prev = a
    
print(out)
Problem p02984 (python)

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

S = sum(A)
Y = [0]*N
Y[0] = S - 2*sum(A[1::2])
for i in range(1,N):
  Y[i] = 2*A[i-1] - Y[i-1]

print(*Y)

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

S = sum(A)
Y = [0]*N
Y[0] = S - 2*sum(A[1::2])
for i in range(1,N):
  Y[i] = 2*A[i-1] - Y[i-1]

print(*Y)

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

S = sum(A)
Y = [0]*N
Y[0] = S - 2* sum(A[1::2])
for i in range(1,N):
  Y[i] = 2*A[i-1] - Y[i-1] 

print(*Y)

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

import numpy as np

Y = [1]*N
for i in range(N):
  if A[i] == (Y[i]+Y[i+1])/2:
    continue
  else:
    Y[i] += A[i]-(Y[i]+Y[i+1])/2

for i in Y:
print(i)
Problem p03013 (python)

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

A = set(A)
dp = [0] * (N+1)
dp[0] = 1
if 1 in A:
  dp[1] = 0
else:
  dp[1] = 1
mod = 1000000007

for i in range(2,N+1):
  if (dp[i-1] == 0) & (dp[i-2]==0):
    print(0)
    exit()
  elif i in A:
    continue
  else:
    dp[i] = dp[i-1]+dp[i-2]

print(dp[N]%mod)

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

dp = [0] * (N+1)
dp[0] = 1
if 1 in A:
  dp[1] = 0
else:
  dp[1] = 1
div = 1000000007

for i in range(2,N+1):
  if (dp[i-1] == 0) & (dp[i-2]==0):
    print(dp)
    print(0)
    sys.exit()
  elif i in A:
    continue
  else:
    dp[i] = dp[i-1]+dp[i-2]

print(dp[N])
Problem p03038 (python)

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

BC.sort(key=lambda x: x[1], reverse=True)

for i in BC:
  A.extend([i[1]]*i[0])
  if len(A) > 2*N:
    break
    
A = sorted(A,reverse=True)
print(sum(A[:N]))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
D = []
for i in range(M):
  B,C = map(int, input().split())
  for j in range(B):
  D.append(C)

import bisect
from collections import deque

D = sorted(D,reverse=True)
A = sorted(A)

for i in range(min(len(D),N)):
  if D[i]>A[i]:
    A[i] = D[i]
  else:
    break
    
print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(M)]
C = [0 for i in range(M)]
D = []
for i in range(M):
  B,C = map(int, input().split())
  for j in range(B):
  D.append(C)

import bisect
from collections import deque

D = sorted(D,reverse=True)
A = sorted(A)

for i in range(min(len(D),N)):
  if D[i]>A[i]:
    A[i] = D[i]
  else:
    break
    
print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(M)]
C = [0 for i in range(M)]
for i in range(M):
B[i],C[i] = map(int, input().split())
import bisect
from collections import deque

for i in range(M):
  A = sorted(A)
  lm = bisect.bisect_right(A, C[i]-1)-1
  print(lm)
  for j in range(min(B[i],lm+1)):
    A[j] = C[i]
    
print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(M)]
C = [0 for i in range(M)]
for i in range(M):
B[i],C[i] = map(int, input().split())
import bisect
import deque

for i in range(M):
  A = sorted(A)
  lm = bisect.bisect_right(A, C[i]-1)-1
  print(lm)
  for j in range(min(B[i],lm+1)):
    A[j] = C[i]
    
print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(M)]
C = [0 for i in range(M)]
for i in range(M):
B[i],C[i] = map(int, input().split())
import bisect
import deque

for i in range(M):
  A = deque(sorted(A))
  lm = A.bisect_right(A, C[i]-1)
  A[:min(B[i],lm)] = C[i]

print(sum(A))
Problem p03077 (python)

Fixed submission:
N = int(input())
ABC = [0]*5
for i in range(5):
  ABC[i] = int(input())
  
Amin = min(ABC)

if N%Amin ==0:
  ans = N//Amin-1+5
else:
  ans = N//Amin+5

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ABC = []*5
for i in range(5):
  ABC[i] = int(input())
  
Amin = min(ABC)

if N%Amin ==0:
  ans = N//2-1+5
else:
  ans = N//2+5

print(ans)
Problem p03108 (python)

Fixed submission:
n, m = map(int, input().split())
A = [0]*m
B = [0]*m
for i in range(m):
  A[i],B[i] =map(int, input().split())

al = n*(n-1)//2
ansl = [al]
d = list(range(n+1))
dl = [[_] for _ in range(n+1)]

for i in range(m-1,0,-1):
  x = d[A[i]]
  y = d[B[i]]
  x,y = max(x,y),min(x,y)
  if x > y:
    al -= len(dl[x])*len(dl[y])
    for i in dl[y]:
      d[i] = x
    dl[x] += dl[y]
  ansl.append(al)

for i in range(m-1,-1,-1):
  print(int(ansl[i]))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = [0]*m
B = [0]*m
for i in range(m):
  A[i],B[i] =map(int, input().split())

al = n*(n-1)//2
ansl = [al]
d = list(range(m+1))
dl = [[_] for _ in range(m+1)]

for i in range(m-1,0,-1):
  x = d[A[i]]
  y = d[B[i]]
  x,y = max(x,y),min(x,y)
  if x > y:
    al -= len(dl[x])*len(dl[y])
    for i in dl[y]:
      d[i] = x
    dl[x] += dl[y]
  ansl.append(al)

for i in range(m-1,-1,-1):
  print(int(ansl[i]))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = []*m
B = []*m
for i in range(m):
  A[i],B[i] =map(int, input().split())

al = n*(n-1)//2
ansl = [al]
d = list(range(m+1))
dl = [[_] for _ in range(m+1)]

for i in range(m-1,0,-1):
  x = d[A[i]]
  y = d[B[i]]
  x,y = max(x,y),min(x,y)
  if x > y:
    al -= len(dl[x])*len(dl[y])
    for i in dl[y]:
      d[i] = x
    dl[x] += dl[y]
  ansl.append(al)

for i in range(m-1,-1,-1):
  print(int(ansl[i]))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = []*m
B = []*m
for i in range(m):
  A[i],B[i] =map(int, input().split())

al = n(n-1)/2
ansl = [al]
d = list(range(m+1))
dl = [[_] for _ in range(m+1)]

for i in range(m-1,0,-1):
  x = d[A[i]]
  y = d[B[i]]
  x,y = max(x,y),min(x,y)
  al -= dl[x]*dl[y]
  for i in range(dl[y]):
    d[i] = x
  dl[x] += dl[y]
  ansl.append(al)
  
for i in range(m-1,-1,-1):
print(ansl[i])