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

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

print(min(str(A)*B, str(B)*A))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())

print(min(int(str(A)*B), int(str(B)*A)))
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())

print(6-A-B)

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

print(6-A-B)
Problem p02835 (python)

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

print("bust" if sum(A) >= 22 else "win")

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

MOD = 10**9+7

sum_num = 0
for i in range(60):
    o = 0
    for a in A:
        o += (a>>i)%2
    z = N - o
    sum_num = (sum_num + (o*z)*(1<<i)) % MOD

print(sum_num)
Problem p02951 (python)

Fixed submission:
A, B, C = map(int, input().split())

print(max(0, C-(A-B)))

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

print(max(0, C-(A-B)))
Problem p02970 (python)

Fixed submission:
N, D = map(int, input().split(" "))

print(-(-N//(2*D+1)))

Buggy submission (verdict: Runtime Error):
N, D = int(input())

print(-(-N//(2*D+1)))
Problem p02990 (python)

Fixed submission:
from math import factorial

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

l = [None]*2010
l[0] = 1
for i in range(1, 2010):
    l[i] = l[i-1]*i

for i in range(1, K+1):
    a = l[N-K+1] // l[i] // l[(N-K+1)-i]
    b = l[K-1] // l[i-1] // l[(K-1)-(i-1)]
    print(a*b % (10**9+7))

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

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

l = [None]*2010
l[0] = 1
for i in range(1, N+1):
    l[i] = l[i-1]*i

for i in range(1, K+1):
    a = l[N-K+1] // l[i] // l[(N-K+1)-i]
    b = l[K-1] // l[i-1] // l[(K-1)-(i-1)]
    print(a*b % (10**9+7))
Problem p03038 (python)

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

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

i = 0
for b, c in BC:
    for j in range(b):
        A[i] = max(A[i], c)
        i += 1
        if i >= N:
            print(sum(A))
            exit()

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

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

i = 0
for b, c in BC:
    for j in range(b):
        A[i] = max(A[i], c)
        i += 1

print(sum(A))
Problem p02879 (python)

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

if a > 9 or a < 1:
	print(-1)
elif b > 9 or b < 1:
	print(-1)
else:
	print(a*b)

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

if a,b > 9:
  print(a*b)
  else:
    print(-1)
Problem p02580 (python)

Fixed submission:
from collections import defaultdict

H,W,M = map(int,input().split())
dic = defaultdict(bool)
h_c = [ 0 for _ in range(H) ]
w_c = [ 0 for _ in range(W) ]

for _ in range(M):
  h,w = map(int,input().split())
  h -= 1
  w -= 1
  h_c[h] += 1
  w_c[w] += 1
  dic[(h,w)] = True

h_cans,w_cans = [],[]
h_max,w_max = max(h_c),max(w_c)
for i in range(H):
  if h_c[i] == h_max:
    h_cans.append(i)

for i in range(W):
  if w_c[i] == w_max:
    w_cans.append(i)

ans = h_max + w_max - 1
for h in h_cans:
  for w in w_cans:
    if not dic[(h,w)]: 
      print(ans+1)
      exit()

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

H,W,M = map(int,input().split())

maze = [[0]*W for _ in range(H)]
for _ in range(M):
  h,w = map(int,input().split())
  h -= 1
  w -= 1
  maze[h][w] = 1

max_row = 0
rows = defaultdict(list)
for i in range(H):
  s = sum(maze[i])
  rows[s].append(i)
  max_row = max(max_row, s)

max_col = 0
cols = defaultdict(list)
for i in range(W):
  s = 0
  for j in range(H):
    s += maze[j][i]
  cols[s].append(i)
  max_col = max(max_col, s)

r_cans = rows[max_row]
c_cans = cols[max_col]

ans = 0
for r_can in r_cans:
  for c_can in c_cans:
    t = max_row + max_col
    if maze[r_can][c_can]: t -= 1
    ans = max(ans, t)

print(ans)
Problem p02623 (python)

Fixed submission:
import bisect
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = LI()
B = LI()

cumA = [0]
for a in A:
  cumA.append(cumA[-1]+a)

cumB = [0]
for b in B:
  cumB.append(cumB[-1]+b)

res = 0
for i in range(N+1):
  cuma = cumA[i]
  if cuma > K: continue
  rem = K-cuma
  deskb = bisect.bisect_right(cumB, rem)-1

  res = max(res, i+deskb)

print(res)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int,input().split())
A = deque(LI())
B = deque(LI())
res = 0
rem = K

for _ in range(N+M):
  if len(A) == 0 and len(B) == 0: break

  if len(A) == 0:
    book = B.popleft()
  elif len(B) == 0:
    book = A.popleft()
  else:
    if A[0] > B[0]:
      book = B.popleft()
    elif A[0] < B[0]:
      book = A.popleft()
    else:
      if len(A) > 1 and len(B) > 1:
        if A[1] > B[1]:
          book = B.popleft()
        else:
          book = A.popleft()
      elif len(A) > 1:
        book = A.popleft()
      else:
        book = B.popleft()

  if rem - book >= 0:
    res += 1
    rem -= book
  else:
    break

print(res)

Buggy submission (verdict: Runtime Error):
from collections import deque
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = deque(LI())
B = deque(LI())
res = 0

while K >= 0:
  if len(A) == 0:
    if K >= B[0]:
      b = B.popleft()
      K -= b
    else:
      break
  elif len(B) == 0:
    if K>=A[0]:
      a = A.popleft()
      K -= a
    else:
      break
  else:
    if A[0] > B[0]:
      b = B.popleft()
      K -= b
    elif A[0] < B[0]:
      a = A.popleft()
      K -= a
    else:
      if A[1] > B[1]:
        b = B.popleft()
        K -= b
      else:
        a = A.popleft()
        K -= a

  if K >= 0:
    res += 1
  else:
    break

  if len(A) == 0 and len(B) == 0:
    break


print(res)

Buggy submission (verdict: Runtime Error):
from collections import deque
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = deque(LI())
B = deque(LI())
res = 0

while K > 0:
  if len(A) == 0:
    if K >= B[0]:
      b = B.popleft()
      K -= b
    else:
      break
  elif len(B) == 0:
    if K>=A[0]:
      a = A.popleft()
      K -= a
    else:
      break
  else:
    if A[0] > B[0]:
      b = B.popleft()
      K -= b
    elif A[0] < B[0]:
      a = A.popleft()
      K -= a
    else:
      if A[1] > B[1]:
        b = B.popleft()
        K -= b
      else:
        a = A.popleft()
        K -= a

  if K >= 0:
    res += 1
  else:
    break


print(res)
Problem p02726 (python)

Fixed submission:
N, X, Y = list(map(int, input().split()))
result = [0] * N


for i in range(1, N):
  for j in range(i+1, N+1):
    step = min( j-i, abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
    result[step] += 1

for e in result[1:]: print(e)

Buggy submission (verdict: Runtime Error):
import math

N, x, y = list(map(int, input().split()))
INF = math.inf
adj_mtx = [ [INF] * (N+1) for _ in range(N+1) ]

for i in range(1, N+1):
  if i != N:
    adj_mtx[i][i] = 0
    adj_mtx[i][i+1] = 1
    adj_mtx[i+1][i] = 1
adj_mtx[x][y] = 1
adj_mtx[y][x] = 1

for k in range(1, N+1):
  for i in range(1, N+1):
    for j in range(1, N+1):
      adj_mtx[i][j] = min(adj_mtx[i][j], adj_mtx[i][k] + adj_mtx[k][j])

for i in range(1, N):
  # print("i", i)
  print(sum([ r.count(i) for r in adj_mtx ]) // 2)

Buggy submission (verdict: Runtime Error):
N, x, y = list(map(int, input().split()))
import math
INF = math.inf
adj_mtx = [ [INF] * (N+1) for _ in range(N+1) ]

for i in range(1, N+1):
  if i != N:
    adj_mtx[i][i] = 0
    adj_mtx[i][i+1] = 1
    adj_mtx[i+1][i] = 1
adj_mtx[x][y] = 1
adj_mtx[y][x] = 1

for k in range(1, N+1):
  for i in range(1, N+1):
    for j in range(1, N+1):
      if i == 1 and j == 6 and k == 7: import pdb; pdb.set_trace()
      adj_mtx[i][j] = min(adj_mtx[i][j], adj_mtx[i][k] + adj_mtx[k][j])

for i in range(1, N):
  print(sum([ r.count(i) for r in adj_mtx ]) // 2)
Problem p02763 (python)

Fixed submission:
class BIT:
  def __init__(self,n):
    self.s = [0]*(n+1)
    self.n = n
  
  def add(self,val,idx):
    while idx < self.n+1:
      self.s[idx] = self.s[idx] + val
      idx += idx&(-idx)
    return
  
  def get(self,idx):
    res = 0
    while idx > 0:
      res = res + self.s[idx]
      idx -= idx&(-idx)
    return res
 
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
 
n = int(input())
S = [ord(s) - ord('a') for s in input()[:-1]]
 
bits = [BIT(n) for i in range(26)]
 
for i,s in enumerate(S):
  bits[s].add(1,i+1)
 
Q = int(input())
ans = []
for _ in range(Q):  
  flag,x,y = input().split()

  if flag == "1":
    i = int(x)
    c = ord(y) - ord('a')
    bits[S[i-1]].add(-1,i)
    bits[c].add(1,i)
    S[i-1] = c
  else:
    l = int(x)
    r = int(y)
    res = 0
    for i in range(26):
      res += (bits[i].get(r) > bits[i].get(l-1))
    ans.append(str(res))

print("\n".join(ans))

Buggy submission (verdict: Runtime Error):
class BIT():
  def __init__(self, n):
    self.s = [0] * (n+1)
    self.n = n

  def add(self, idx, val):
    while idx < self.n+1:
      self.s[idx] += val
      idx += idx&(-idx)

  def get(self, idx):
    res = 0
    while idx > 0:
      res += self.s[idx]
      idx -= idx&(-idx)

n = int(input())
S = [ ord(s)-ord('a') for s in input()[::-1] ]
bits = [BIT(n) for i in range(26)]

for i,s in enumerate(S):
  bits[s].add(i+1,1)

Q = int(input())
ans = []
for _ in range(Q):
  flg,x,y = map(str, input().split())
  if flg == "1":
    i = int(x)
    c = ord(y) - ord('a')
    bits[S[i-1]].add(i, -1)
    bits[c].add(i, 1)
    S[i-1] = c
  else:
    l = int(x)
    r = int(y)
    res = 0
    for i in range(26):
      res += bits[i].get(r) > bits[i].get(l-1)
    ans.append(res)

for a in ans: print(a)
Problem p02829 (python)

Fixed submission:
input1 = int(input())
input2 = int(input())
 
if input1 == 1:
  print(3) if input2 == 2 else print(2)
elif input1 == 2:
  print(3) if input2 == 1 else print(1)
else:
  print(1) if input2 == 2 else print(2)

Buggy submission (verdict: Runtime Error):
input1 = int(input())
input2 = int(input())

if input1 == 1 and input2 == 2:
  return 3
elif input1 == 1 and input2 == 3:
  return 2
else:
  return 1
Problem p02948 (python)

Fixed submission:
import heapq
N,M = map(int,input().split())
jobs = [ [] for _ in range(M+1) ]
for _ in range(N):
  a,b = map(int,input().split())
  if a <= M:
    jobs[a].append(b)

pq = []
d = 1
res = 0
for _ in range(M-1, -1, -1):
  for b in jobs[d]:
    heapq.heappush(pq, -b)
  if pq:
    res += -heapq.heappop(pq)
  d += 1

print(res)

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split())
jobs = [ [] for _ in range(M+1) ]
for _ in range(N):
  a,b = map(int,input().split())
  jobs[a].append(b)

pq = []
d = 1
res = 0
for _ in range(M-1, -1, -1):
  for b in jobs[d]:
    heapq.heappush(pq, -b)
  if pq:
    res += -heapq.heappop(pq)
  d += 1

print(res)
Problem p02984 (python)

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

x1 = 0
for i,a in enumerate(A):
  if (i&1):
    x1 -= a
  else:
    x1 += a
x1 //= 2

res = [0] * N
res[0] = x1
for i in range(N-1):
  res[i+1] = A[i] - res[i]
for i in range(N):
  res[i] *= 2

print(" ".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
        modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
adj = [ [ ]for _ in range(N) ]
comb = Combination(10**5)

def nPr(n,r):
  if n < r: return 0
  return comb(n, r) * comb.fac[r]

for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  adj[a].append(b)
  adj[b].append(a)

def dfs(v, p=-1):
  global ans
  c = 0
  for nei in adj[v]:
    if nei == p: continue
    c += 1
    dfs(nei, v)

  nk = K-1 if p==-1 else K-2
  ans *= nPr(nk, c)
  ans %= 10**9+7

ans = K
dfs(0)
print(ans)
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce

def cmb(n, r):
  if n < r:
    return 0
  r = min(n - r, r)
  if r == 0:
    return 1
  numer = reduce(mul, range(n, n - r, -1))
  denom = reduce(mul, range(1, r + 1))
  return (numer // denom) % (10 ** 9 + 7)

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

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n, r):
  if n < r:
    return 0
  r = min(n - r, r)
  if r == 0:
    return 1
  numer = reduce(mul, range(n, n - r, -1))
  denom = reduce(mul, range(1, r + 1))
  return numer // denom % (10 ** 9 + 7)

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

Fixed submission:
N,M = map(int,input().split())
MOD = 10**9+7
dp = [0] * (N+1)
dp[1] = 1
for _ in range(M):
  dp[int(input())] = -1
if N<2:
  print(dp[N])
  exit()

if dp[2] != -1:
  dp[2] = 1
for i in range(N+1):
  if dp[i] == -1: continue
  if i-1>=0 and dp[i-1] != -1:
    dp[i] += dp[i-1]
  if i-2>=0 and dp[i-2] != -1:
    dp[i] += dp[i-2]
  dp[i] %= MOD

print(dp[N])

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
MOD = 10**9+7
dp = [0] * (N+1)
dp[1] = 1
dp[2] = 1
for _ in range(M):
  dp[int(input())] = -1

for i in range(N+1):
  if dp[i] == -1: continue
  if i-1>=0 and dp[i-1] != -1:
    dp[i] += dp[i-1]
  if i-2>=0 and dp[i-2] != -1:
    dp[i] += dp[i-2]
  dp[i] %= MOD

print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
N,M = map(int,input().split())
A = []
MOD = 10**9+7
memo = {}
for _ in range(M):
  memo[a] = 0

def step(cur):
  if cur in memo:
    return memo[cur]
  if cur == N:
    memo[cur] = 1
    return memo[cur]
  if cur > N:
    memo[cur] = 0
    return memo[cur]
 
  memo[cur] = (step(cur+1) + step(cur+2))%MOD
  return memo[cur]
 
print(step(0)%MOD)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = []
MOD = 10**9+7
memo = {}
for _ in range(M):
  A.append(int(input()))
def step(cur):
  global res
  if cur in memo:
    return memo[cur]
  if cur == N:
    memo[cur] = 1
    return memo[cur]
  if cur > N or cur in A:
    memo[cur] = 0
    return memo[cur]

  memo[cur] = (step(cur+1) + step(cur+2))%MOD
  return memo[cur]

res = 0
print(step(0)%MOD)
Problem p03775 (python)

Fixed submission:
N = int(input())


def digits(n):
    return len(list(str(n)))


digit_list = []
for a in range(1, int(N**(1/2))+1):
    b = N // a if N % a == 0 else 0
    if b != 0:
        digit_list += [max(digits(a), digits(b))]

print(min(digit_list))

Buggy submission (verdict: Runtime Error):
N = int(input())


def digits(n):
    return len(list(str(n)))


digit_list = []
for a in range(1, int(N**(1/2))):
    b = N // a if N % a == 0 else 0
    if b != 0:
        digit_list += [max(digits(a), digits(b))]

print(min(digit_list))
Problem p02580 (python)

Fixed submission:
H,W,M = map(int, input().split())
# grid = [[0 for _ in range(W)] for _ in range(H)]
bombs = set()

hc = [0 for h in range(H)]
wc = [0 for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    h-=1
    w-=1
    bombs.add((h, w))
    hc[h] += 1
    wc[w] += 1

hmax = max(hc)
wmax = max(wc)

htable = []
for h in range(H):
    if hc[h] == hmax:
        htable.append(h)

wtable = []
for w in range(W):
    if wc[w] == wmax:
        wtable.append(w)

# print(uw, uh)
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in htable:
    for w in wtable:
        if (h,w) not in bombs:
            print(hmax + wmax)
            exit(0)

print(hmax + wmax - 1)

Buggy submission (verdict: Runtime Error):
H,W,M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]

hc = [(0, h) for h in range(H)]
wc = [(0, w) for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    grid[h-1][w-1] = 1
    hc[h-1] = (hc[h-1][0] + 1, hc[h-1][1])
    wc[w-1] = (wc[w-1][0] + 1, wc[w-1][1])

hc = sorted(hc, key=lambda p: p[0], reverse=True)
wc = sorted(wc, key=lambda p: p[0], reverse=True)

hmax = hc[0][0]
wmax = wc[0][0]

uh = 0
while hc[uh][0] == hmax:
    uh += 1

uw = 0
while wc[uw][0] == wmax:
    uw += 1

uh -= 1
uw -= 1
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in range(uh):
    for w in range(uw):

        if grid[hc[h][1]][wc[w][1]] == 0:
            found = True
            break
    if found:
        break

print(hmax + wmax if found else hmax + wmax - 1)

Buggy submission (verdict: Runtime Error):
H,W,M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]

hc = [(0, h) for h in range(H)]
wc = [(0, w) for w in range(W)]

for _ in range(M):
    h,w = map(int, input().split())
    grid[h-1][w-1] = 1
    hc[h-1] = (hc[h-1][0] + 1, hc[h-1][1])
    wc[w-1] = (wc[w-1][0] + 1, wc[w-1][1])

hc = sorted(hc, key=lambda p: p[0], reverse=True)
wc = sorted(wc, key=lambda p: p[0], reverse=True)

hmax = hc[0][0]
wmax = wc[0][0]

uh = 0
while hc[uh][0] == hmax:
    uh += 1

uw = 0
while hc[uw][0] == wmax:
    uw += 1

uh -= 1
uw -= 1
#print(grid)
#print(wc, uw)
#print(hc, uh)

found = False
for h in range(uh):
    for w in range(uw):

        if grid[hc[h][1]][wc[w][1]] == 0:
            found = True
            break
    if found:
        break

print(hmax + wmax if found else hmax + wmax - 1)
Problem p02759 (python)

Fixed submission:
def resolve():
    N = int(input())
    print((N+1)//2)
    
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    N,M = list(map(int, input().split(' ')))
    K = [-1] * N
    for i in range(M):
        s, c = list(map(int, input().split(' ')))
        if K[s-1] != -1 and K[s-1] != c:
            print('-1')
            return
        K[s-1] = c
    if K[0] == 0:
        print('-1')
        return
    ans = ""
    if N==1:
        X = max(0, K[0])
        print(max(0, K[0]))
        return

    for i in range(N):
        if i==0 and K[i]==-1:
            ans += '1'
        elif K[i] == -1:
            ans += '0'
        else:
            ans += str(K[i])
    print(ans)

resolve()
Problem p03038 (python)

Fixed submission:
from operator import itemgetter

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []
    for i in range(M):
        bc = list(map(int, input().split()))
        BC.append(bc)

    BC.sort(key=itemgetter(1), reverse=True)
    # B = []
    # for b, c in BC:
    #     B = B + [c] * b
    #     if len(B) > N:
    #         break

    A.sort(reverse=True)
    
    i = 0
    j = 0
    r = []

    cnt = 0
    while len(r) != N:
        # print(i, j)
        if j > M - 1:
            r.append(A[i])
            i += 1
            continue

        b, c = BC[j]
        if A[i] >= c:
            r.append(A[i])
            i += 1
        else:
            r.append(c)
            cnt += 1
            if cnt == b:
                j += 1
                cnt = 0

    # print(r)
    ans = sum(r)
    print(ans)


if __name__ == "__main__":
    main()

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

    BC.sort(key=lambda x: x[1], reverse=True)
    B = []
    for b, c in BC:
        B = B + [c] * b
        if len(B) > N:
            break

    A.sort(reverse=True)
    
    i = 0
    j = 0
    r = [None] * N
    while i + j < N:
        if A[i] > B[j]:
            r[i+j] = A[i]
            i += 1
        else:
            r[i+j] = B[j]
            j += 1

    # print(r)
    ans = sum(r)
    print(ans)


if __name__ == "__main__":
    main()
Problem p03242 (python)

Fixed submission:
n = input()
print(n.replace("1", "x").replace("9", "1").replace("x", "9"))

Buggy submission (verdict: Runtime Error):
import collections

num = int(input())
values = [int(i) for i in input().split()]

odd = []  # kisuu
even = []  # gusu

for n, i in enumerate(values):
    if (n + 1) % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

odd_counts = collections.Counter(odd)
even_counts = collections.Counter(even)

# print(odd_counts.most_common())
# print(even_counts.most_common())

odd_most_common = odd_counts.most_common()
even_most_common = even_counts.most_common()

half_num = int(num / 2)

if odd_most_common[0][0] != even_most_common[0][0]:
    odd_replace_num = half_num - odd_most_common[0][1]
    even_replace_num = half_num - even_most_common[0][1]
    print(odd_replace_num + even_replace_num)
else:
    answers = []
    odd_replace_num = half_num - odd_most_common[0][1]
    if len(even_most_common) == 1:
        even_replace_num = half_num
    else:
        even_replace_num = half_num - even_most_common[1][1]
    answers.append(odd_replace_num + even_replace_num)

    if len(odd_most_common) == 1:
        odd_replace_num = half_num
    else:
        odd_replace_num = half_num - odd_most_common[1][1]
    even_replace_num = half_num - even_most_common[0][1]
    answers.append(odd_replace_num + even_replace_num)

    print(min(answers))
Problem p03345 (python)

Fixed submission:
A, B, C, K = list(map(int, input().split()))

if K % 2 != 0:
    r = B - A
else:
    r = A - B

if abs(r) > 10 ** 18:
    print('Unfair')
else:
    print(r)

Buggy submission (verdict: Runtime Error):
n = int(input())

l = len(str(n))
# if n < 10:
#     ans = n
# else:
ans1 = 9 * (l-1) + int(str(n)[0]) - 1
ans2 = sum([int(x) for x in list(str(n))])
ans = max(ans1, ans2)
# print(ans1, ans2)
print(ans)
Problem p02676 (python)

Fixed submission:
K = int(input())
S = input()
 
if len(S) <= K:
  print(S)
  
else:
  print("{}...".format(S[:K]))

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

if len(S) <= K:
  print(S)
  
else:
  print("{}...".format(S[0,K]))
Problem p02781 (python)

Fixed submission:
from math import factorial


def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


N = input()
K = int(input())
ans = 0
if K == 1:
    for i in range(1, len(N)):
        ans += 9
    ans += int(N[0])
elif K == 2:
    for i in range(K, len(N)):
        ans += 81 * comb(i - 1, 1)
    for i1 in range(1, 10):
        for i2 in range(1, 10):
            for p in range(len(N) - 1):
                if str(i1) + "0" * (len(N) - p - 2) + str(i2) + "0" * p <= N:
                    ans += 1
elif K == 3:
    for i in range(K, len(N)):
        ans += 729 * comb(i - 1, 2)
    for i1 in range(1, 10):
        for i2 in range(1, 10):
            for i3 in range(1, 10):
                for p1 in range(1, len(N) - 1):
                    for p2 in range(p1):
                        st = str(i1) + "0" * (len(N) - p1 - 2) + str(i2) + \
                            "0" * (p1 - p2 - 1) + str(i3) + "0" * p2
                        if st <= N:
                            ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
def comb(n, k):
    nume, deno = 1, 1
    for i in range(k):
        deno *= n - i
        nume *= i + 1
    return deno // nume


def ans(N, K):
    ret = sum([9 ** K * comb(max(dig - 1, 1), K - 1)
               for dig in range(K, len(N))])
    ret += (int(N[0]) - 1) * 9 ** (K - 1) * comb(len(N) - 1, K - 1)
    if K == 1:
        return ret + 1
    elif K == 2:
        return ret + ans(N[1:], 1)
    elif K == 3:
        return ret + ans(N[1:], 2)


N = input()
K = int(input())
print(ans(N, K))