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

Fixed submission:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
ls = [A,B,C,D,E]
X = min((A,B,C,D,E))
s=N//X
if N%X==0:
  s-=1
print(s+5)

Buggy submission (verdict: Runtime Error):
inf = input().split()
X = int(inf[0])
Y = int(inf[1])
Z = int(inf[2])
K = int(inf[3])

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ab = []
for a in A:
  for b in B:
    ab +=[a+b]
ab.sort(reverse=True)
C.sort(reverse=True)
state = [ab[0]+i for i in C]
count  = 0
while count<K:
  x = max(state)
  print(x)
  count += 1
  i = state.index(x)
  j = ab.index(x-C[i])
  if j<X*Y-1:
    state[i] = ab[j+1]+C[i]
  else:
    state[i]=-1
Problem p03108 (python)

Fixed submission:
from functools import reduce
from operator import mul

def cmb(n,r):
  r = min(r, n-r)
  if r==0: return 1
  if r<0: return 0
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1,r+1))
  return over//under

class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.dic = {i:1 for i in range(n)}
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      self.dic[y] += self.dic.pop(x)
      
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
      self.dic[x] += self.dic.pop(y)
    else:
      self.par[y] = x
      self.dic[x] += self.dic.pop(y)
      self.rank[x] += 1
  def same(self, x, y):
    return self.find(x)==self.find(y)


N, M = map(int, input().split())
bridge = []
u = UnionFind(N)
m = cmb(N,2)
ans = [m]

for i in range(M):
  A, B = map(int, input().split())
  bridge += [(A,B)]
  
for i in range(M-1,0,-1):
  a, b = bridge[i]
  if u.same(a-1,b-1):
    ans += [m]
    continue
  pa = u.find(a-1)
  pb = u.find(b-1)
  m -= u.dic[pa]*u.dic[pb]
  ans += [m]
  u.unit(a-1,b-1)

for i in range(M-1,-1,-1):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
def cmb(n,r):
  r = min(r, n-r)
  if r==0: return 1
  if r<0: return 0
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1,r+1))
  return over//under

class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.size = [1]*n
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      self.size[y] += self.size[x]
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
      self.size[x] += self.size[y]
    else:
      self.par[y] = x
      self.size[x] += self.size[y]
      self.rank[x] += 1
      
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
  def count(self, x):
    return self.size[x]

N, M = map(int, input().split())
bridge = []
u = UnionFind(N)
m = cmb(N,2)
ans = [m]

for i in range(M):
  A, B = map(int, input().split())
  bridge += [(A,B)]
  
for i in range(M-1,0,-1):
  a, b = bridge[i]
  if u.same(a-1,b-1):
    ans += [m]
    continue
  pa = u.find(a-1)
  pb = u.find(b-1)
  m -= u.count(pa)*u.count(pb)
  ans += [m]
  u.unit(a-1,b-1)

for i in range(M-1,-1,-1):
  print(ans[i])
Problem p03127 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

def Gcd(*numbers):
  return reduce(gcd, numbers)
N = int(input())
ls = [int(i) for i in input().split()]

print(Gcd(*ls))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N,M,*A = map(int, open(0).read().split())
ls = [0]*10
ls[1] = 2
ls[2] = 5
ls[3] = 5
ls[4] = 4
ls[5] = 5
ls[6] = 6
ls[7] = 3
ls[8] = 7
ls[9] = 6
dic = defaultdict(int)
for a in A:
  k = ls[a]
  dic[k] = max(dic[k],a)
dp = [-1]*(N+1)
for k in dic.keys():
  if k>N:
    continue
  dp[k] = dic[k]
for i in range(N+1):
  for k in dic.keys():
    if i-k>0 and dp[i-k]!=-1:
      s = str(dp[i-k])
      m = int(s+str(dic[k]))
      dp[i] = max(dp[i], m)
print(dp[N])
Problem p03201 (python)

Fixed submission:
from collections import defaultdict
N, *A = map(int, open(0).read().split())
ans = 0
A.sort()
dic = defaultdict(list)
for i, a in enumerate(A):
  dic[a] += [i]
for i in range(N-1,-1,-1):
  a = A[i]
  if dic[a]==[]:
    continue
  dic[a].pop()
  k = 1
  while k<=a:
    k *= 2
  n = k-a
  if dic[n]!=[]:
    dic[n].pop()
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N, *A = map(int, open('0').read().split())
ans = 0
A.sort()
dic = defaultdict(list)
for i, a in enumerate(A):
  dic[a] += [i]
for i in range(N-1,-1,-1):
  a = A[i]
  if dic[a]==[]:
    continue
  dic[a].pop()
  k = 1
  while k<=a:
    k *= 2
  n = k-a
  if dic[n]!=[]:
    dic[n].pop()
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, *A = map(int, open(0).read().split())
ans = 0
A.sort()
used = [False]*N
for i in range(N-1,-1,-1):
  if used[i]:
    continue
  a = A[i]
  k = 1
  while k<=a:
    k *= 2
  n = k-a
  ind  = bisect_left(A,n)
  while A[ind]==n:
    if not used[ind] and ind!=i:
      break
    ind += 1
  else:
    continue
  ans += 1
  used[ind] = True
  used[i] = True
print(ans)
Problem p03209 (python)

Fixed submission:
N, X = map(int, input().split())
p = 1
t = 1
pdic = {}
tdic = {}
for i in range(N):
  pdic[i] = p
  tdic[i] = t
  p = 2*p+1
  t = 2*t+3
pdic[N] = p
tdic[N] = t
ans = 0
nokori = X
state = N
count = N
while True:
  while tdic[count]+state-count>nokori:
    count -= 1
    if count<0:
      break
  if count<0:
    break
  nokori -= (tdic[count]+state-count)
  state = count
  ans += pdic[count]
  if nokori==0:
    break
  nokori -= 1
  ans += 1
  if nokori==0:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
 N, X = map(int, input().split())
2
3 a, p = [1], [1]
4 for i in range(N):
5 a.append(a[i] * 2 + 3)
6 p.append(p[i] * 2 + 1)
7
8 def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
9 if N == 0:
10 return 0 if X <= 0 else 1
11 elif X <= 1 + a[N-1]:
12 return f(N-1, X-1)
13 else:
14 return p[N-1] + 1 + f(N-1, X-2-a[N-1])
15
16 print(f(N, X))
Problem p03291 (python)

Fixed submission:
S = input()
INF = 10**9+7
dp = [0,0,0]
N = 1
for i in range(len(S)):
  if S[i]=='A':
    dp[0] += N
    dp[0] %= INF
  elif S[i]=='B':
    dp[1] += dp[0]
    dp[1] %= INF
  elif S[i]=='C':
    dp[2] += dp[1]
    dp[2] %= INF
  else:
    a = dp[0]
    b = dp[1]
    dp[0] = N + dp[0]*3
    dp[1] = a + dp[1]*3
    dp[2] = b + dp[2]*3
    dp[0] %= INF
    dp[1] %= INF
    dp[2] %= INF
    N = (3*N)%INF
print(dp[2]%INF)

Buggy submission (verdict: Runtime Error):
import numpy as np
S = input()
INF = 10**9+7
dp = np.array([0,0,0], dtype=np.int64)
N = 1
for i in range(len(S)):
  if S[i]=='A':
    dp[0] += N%INF
    dp[0] %= INF
  elif S[i]=='B':
    dp[1] += dp[0]
    dp[1] %= INF
  elif S[i]=='C':
    dp[2] += dp[1]
    dp[2] %= INF
  else:
    dp[1:] = dp[1:]*3+dp[:-1]
    dp[0] = dp[0]*3+N
    dp %= INF
    N *= 3
print(dp[2])

Buggy submission (verdict: Runtime Error):
import numpy as np
S = input()
INF = 10**9+7
dp = np.array([0,0,0], dtype=np.int64)
N = 1
for i in range(len(S)):
  if S[i]=='A':
    dp[0] += N%INF
    dp[0] %= INF
  elif S[i]=='B':
    dp[1] += (dp[0]%INF)
  elif S[i]=='C':
    dp[2] += (dp[1]%INF)
  else:
    dp[1:] = dp[1:]*3+dp[:-1]
    dp[0] = dp[0]*3+N
    dp %= INF
    N *= 3
print(dp[2]%INF)
Problem p03326 (python)

Fixed submission:
from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
for i in range(N):
  x, y, z = map(int, input().split())
  ls = (x,y,z)
  for j in range(8):
    m = 0
    n = j
    for h in range(3):
      a = ls[h]
      if n%2==1:
        a = -a
      m += a
      n >>= 1
    heappush(dic[j], -m)
#print(dic)
ans = 0
for i in range(8):
  m = 0
  for j in range(M):
    m -= heappop(dic[i])
  if m>ans:
    ans = m
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M, *L = map(int, open('0').read().split())
L = [np.array(m) for m in zip(*[iter(L)]*3)]
ans = 0
for i in range(8):
  X = []
  c = []
  for j in range(3):
    if i%2==1:
      c.append(-1)
    else:
      c.append(1)
    i >>= 1
  c = np.array(c)
  X = list(map(lambda x:sum(x*c), L))
  X.sort(reverse=True)
  ans = max(ans, sum(X[:M]))
print(ans)
Problem p03426 (python)

Fixed submission:
H, W, D = map(int, input().split())
px = [0]*(H*W+1)
py = [0]*(H*W+1)
dp = [0]*(H*W+1)
for i in range(H):
  inf = input().split()
  for j in range(W):
    a = int(inf[j])
    py[a] = i
    px[a] = j
for i in range(D+1, H*W+1):
  dp[i] = dp[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])

Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  print(dp[R]-dp[L])

Buggy submission (verdict: Runtime Error):
H, W, D, *L = map(int, open('0').read().split())
A = L[:W*H]
Q = L[H*W]
inf = []
for l,r in zip(*[iter(L[H*W+1:])]*2):
  inf += [(l,r)]
dic = {A[i*W+j]:(i,j) for i in range(H) for j in range(W)}
ls = [[] for i in range(D)]
for i in range(D):
  s = i if i!=0 else D
  ls[i].append(0)
  m = s
  n = s
  while True:
    n += D
    if H*W<n:
      n = s
    px, py = dic[m]
    x, y = dic[n]
    ls[i].append(ls[i][-1]+abs(px-x)+abs(py-y))
    m = n
    if m==s:
      break
for l, r in inf:
  i = l%D
  if i==0:
    il = (l-D)//D
    ir = (r-D)//D
  else:
    il = (l-i)//D
    ir = (r-i)//D
  if l<r:
    print(ls[i][ir] - ls[i][il])
  elif l>r:
    print(ls[i][-1]-ls[i][il]+ls[i][ir])
  else:
    print(0)
Problem p03652 (python)

Fixed submission:
N, M, *X = map(int, open(0).read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = []
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans.append(max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(min(ans))

Buggy submission (verdict: Runtime Error):
N, M, *X = map(int, open('0').read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = N
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans = min(ans,max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(ans)
Problem p03822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N, *A = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for i in range(N-1):
  dic[A[i]] += [i+2]
def solve(n):
  if len(dic[n])==0:
    return 0
  ls = []
  for e in dic[n]:
    ls += [solve(e)]
  ls.sort(reverse=True)
  return max(ls[i]+i+1 for i in range(len(ls)))

print(solve(1))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
N, *A = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for i in range(N-1):
  dic[A[i]] += [i+2]
@lru_cache(None)
def solve(n):
  if len(dic[n])==0:
    return 0
  ls = []
  for e in dic[n]:
    ls += [solve(e)]
  ls.sort(reverse=True)
  return max(ls[i]+i+1 for i in range(len(ls)))

print(solve(1))
Problem p03839 (python)

Fixed submission:
from itertools import accumulate as acc
N, K, *A = map(int, open(0).read().split())
B = [0]+list(acc(A))
M = list(acc(a if a>0 else 0 for a in A))
ans = -10**30
s = sum(A)
for i in range(N-K+1):
  mi = B[i+K]-B[i]
  c = M[N-1] - M[i+K-1]
  if i>0:
    c += M[i-1]
  ans = max(ans,mi+c,c)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate as acc
N, K, *A = map(int, open('0').read().split())
B = [0]+list(acc(A))
M = list(acc(a if a>0 else 0 for a in A))
ans = -10**30
s = sum(A)
for i in range(N-K+1):
  mi = B[i+K]-B[i]
  c = M[N-1] - M[i+K-1]
  if i>0:
    c += M[i-1]
  ans = max(ans,mi+c,c)
print(ans)
Problem p04021 (python)

Fixed submission:
N, *A = map(int, open(0).read().split())
ans = 0
B = sorted(A)
dic = {B[i]:i for i in range(N)}
for i,n in enumerate(A):
  if i%2!=dic[n]%2:
    ans += 1
print(ans//2)

Buggy submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
ans = 0
B = sorted(A)
dic = {B[i]:i for i in range(N)}
for i,n in enumerate(A):
  if i%2!=dic[n]%2:
    ans += 1
print(ans//2)
Problem p02726 (python)

Fixed submission:
from collections import deque
N, X, Y = map(int, input().split())

# G[v]: 頂点vに隣接する頂点list
# N: 頂点数
G = [[] for i in range(N)]
G[X - 1].append(Y - 1)
for i in range(N - 1):
    G[i].append(i + 1)
    G[i + 1].append(i)
# print(G)


def bfs(start):
    dist = [-1] * N
    que = deque([start])
    dist[start] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    return dist


ans = [0] * N

for i in range(N - 1):
    # print(bfs(i))
    for ele in bfs(i)[i + 1:]:
        ans[ele] += 1
for a in ans[1:]:
    print(a)

Buggy submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
inf = float("inf")

graph = np.zeros((N, N))
for i in range(N - 1):
    graph[i][i + 1] = 1
    graph[i + 1][i] = 1
graph[X - 1][Y - 1] = 1
graph[Y - 1][X - 1] = 1

shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="D", unweighted=True)
ans = [0] * (N - 1)
for i in range(N):
    for j in range(N):
        if i != j:
            ans[shortest_paths[i][j]] += 1
for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
inf = float("inf")

graph = np.zeros((N, N))
for i in range(N - 1):
    graph[i][i + 1] = 1
    graph[i + 1][i] = 1
graph[X - 1][Y - 1] = 1
graph[Y - 1][X - 1] = 1

shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="D", unweighted=True)
ans = [0] * (N - 1)
for i in range(N):
    for j in range(N):
        if i != j:
            ans[shortest_paths[i][j]] += 1
Problem p02762 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = map(int, input().split())
uf = UnionFind(N)
not_friend_candidates = [1]*N
for _ in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)
    not_friend_candidates[A-1] += 1
    not_friend_candidates[B-1] += 1
for _ in range(K):
    C, D = map(int, input().split())
    if uf.same(C-1, D-1):
        not_friend_candidates[C-1] += 1
        not_friend_candidates[D-1] += 1
for hito in range(N):
    print(uf.size(hito) - not_friend_candidates[hito], end=" ")
print()

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
inf = 10**6


N, M, K = map(int, input().split())
graph = np.zeros((N, N), np.int32)
for _ in range(M):
    A, B = map(int, input().split())
    graph[A-1][B-1] = 1
    graph[B-1][A-1] = 1
for _ in range(K):
    C, D = map(int, input().split())
    graph[C-1][D-1] = inf
    graph[D-1][C-1] = inf


csgraph = csr_matrix(graph)
shortest_paths = shortest_path(csgraph, directed=False, method="BF")


ok = sorted(list(zip(*np.where(graph < inf))))
now = 0
ans = 0
for x, y in ok:
    if x == now:
        if shortest_paths[x][y] > 1:
            ans += 1
    else:
        print(ans, end=" ")
        ans = 0
        now += 1
        while now < x:
            if now != N - 1:
                print(0, end=" ")
            else:
                print(0, end="")
            now += 1
        if shortest_paths[x][y] != 1:
            ans += 1

while now <= N-1:
    if ans != 0:
        print(ans , end=" ")
        continue
    if now != N-1:
        print(0, end=" ")
    else:
        print(0, end="")
    now += 1
print()
Problem p02773 (python)

Fixed submission:
from collections import Counter
N = int(input())
Sc = Counter([input() for _ in range(N)]).most_common()
# print(Sc)
max_num = Sc[0][1]
ans = []
for key, val in Sc:
    if val == max_num:
        ans.append(key)
ans.sort()
for t in ans:
    print(t)

Buggy submission (verdict: Runtime Error):
N = int(input())
from collections import Counter
Sc = Counter([input() for _ in range(N)])
max_count = max(Sc.values())
ans = sorted([k for k, v in Sc.items() if v == max_count)])
print(*ans, sep="\n")
Problem p02832 (python)

Fixed submission:
N = int(input())
alist = list(map(int, input().split()))
now = 1
for a in alist:
    if a == now:
        now += 1
if now == 1:
    print(-1)
else:
    print(N - now + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
alist = list(map(int, input().split()))
left = 0
for i in range(1, N + 1):
    try:
        old_left = left
        left = alist[left:].index(i)
        p = left + old_left
    except ValueError:
        print(i, p)
        if i == 1:
            print(-1)
        else:
            print(N - i + (N - p))
        break
else:
    print(0)
Problem p02862 (python)

Fixed submission:
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10**9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


from sys import exit
X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()

if X % 2 == 0:
    syurui = X - (X // 2) + 1
else:
    syurui = X - (X // 2)
for i in range(syurui):
    two = i
    one = X - two * 2
    if (two + one * 2) == Y:
        print(nCk(two + one, two))
        exit()
print(0)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10**9+7
b = (2*Y-X)//3
a = Y - 2*b
max_num = a + b + 5
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    return facts[n]*invs[k] * invs[n-k] % mod

if (X+Y)%3 == 0:
    print(nCk(a+b, a))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10**9+7
b = (2*Y-X)//3
a = Y - 2*b
max_num = a + b + 5
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    return facts[n]*invs[k] * invs[n-k] % mod

if (X+Y)%3 == 0:
    print(nCk(a+b, a))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10**9+7
b = (2*Y-X)//3
a = Y - 2*b
max_num = a + b + 1
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    return facts[n]*invs[k] * invs[n-k] % mod

def nHk(n, k):
  return nCk(n-1+k, n-1)

if (X+Y)%3 == 0:
    print(nCk(a+b, a))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10**9+7
b = (2*Y-X)//3
a = Y - 2*b
max_num = a + b + 1
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    return facts[n]*invs[k] * invs[n-k] % mod

def nHk(n, k):
  return nCk(n-1+k, n-1)

if (X+Y)%3 == 0:
    print(nCk(a+b, a))
else:
    print(0)
Problem p02912 (python)

Fixed submission:
import heapq


def int_and_reverse(num):
    return int(num) * -1


N, M = map(int, input().split())
Alist = list(map(int_and_reverse, input().split()))
heapq.heapify(Alist)
for _ in range(M):
    x = (heapq.heappop(Alist) * -1) // 2
    heapq.heappush(Alist, -x)
print(-sum(Alist))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())
Alist = np.array(list(map(int, input().split())))
for _ in range(M):
    Alist[np.argmax(Alist)] /= 2
print(np.sum(Alist.astype(np.int64)))