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

Fixed submission:
import math

N = int(input())

for i in reversed(range(1, int(math.sqrt(N)) +1  )):
    if N % i == 0:
        print(i + N//i - 2)
        break

Buggy submission (verdict: Runtime Error):
import math

N = int(input())

for i in reversed(range(int(math.sqrt(N)))):
    if N % i == 0:
        print(i + N//i - 2)
        exit()
Problem p02695 (python)

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

As = []
q = [[]]
while len(q) > 0:
    arg = q.pop()
    if len(arg) == N:
        As.append(arg)
    else:
        A_str = 1 if len(arg) == 0 else arg[-1]
        for i in range(A_str, M + 1):
            q.append(arg + [i])

ans = 0
for A in As:
    ans_tmp = 0
    for j, (aj, bj, cj, dj) in enumerate(abcd):
        if A[bj - 1] - A[aj - 1] == cj:
            ans_tmp += dj
    #
    ans = max(ans, ans_tmp)

print(ans)

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

q = []
def dp(arg):
    global N
    if len(arg) == N:
        q.append(arg)
    else:
        tmp = 0 if len(arg) == 0 else arg[-1]
        for i in range(arg[-1], M + 1):
            dp(arg + [i])

dp([])

ans = 0
for A_tmp in q:
    ans_tmp = 0
    for j, (aj, bj, cj, dj) in enumerate(abcd):
        if A_tmp[bj - 1] - A_tmp[aj - 1] == cj:
            ans_tmp += dj
    #
    ans = max(ans, ans_tmp)

print(ans)
Problem p02959 (python)

Fixed submission:
inf = 10 ** 18
P = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_all = sum(A)

xi = min(A[0], B[0])
A[0] -= xi
B[0] -= xi
for i in range(N):
    yi = min(B[i], A[i + 1])
    A[1 + i] -= yi
    B[i] -= yi
    #
    if i < N - 1:
        xi = min(A[1 + i], B[1 + i])
        A[1 + i] -= xi
        B[1 + i] -= xi
    #
    # print("#", A, B, A_all - sum(A))
    
A_r = list(reversed(A))
B_r = list(reversed(B))


xi = min(A_r[0], B_r[0])
A_r[0] -= xi
B_r[0] -= xi
for i in range(N):
    yi = min(B_r[i], A_r[i + 1])
    A_r[1 + i] -= yi
    B_r[i] -= yi
    #
    if i < N - 1:
        xi = min(A_r[1 + i], B_r[1 + i])
        A_r[1 + i] -= xi
        B_r[1 + i] -= xi
    #
    # print("#", A, B, A_all - sum(A))

print(A_all - sum(A))

Buggy submission (verdict: Runtime Error):
2
100 1 1
1 100
Problem p02990 (python)

Fixed submission:
# encoding: utf-8
import sys
# input = sys.stdin.readline
P = 10 ** 9 + 7

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

# molec = 1
# for i in range(K - 1):
#     molec = (molec * (i + 1)) % P

power = 10 ** 9 + 5
digits = []
for i in range(64):
    digits.append(power % 2)
    power >>= 1

def modinv(b):
    binv = 1
    val = b % P
    for i, digit in enumerate(digits):
        if digit == 1:
            binv = (binv * val) % P
        val = (val * val) % P
    # print("##", b, binv)
    return binv

molec = 1
tab_nck = [1]
for i in range(1, K - 1):
    molec = (molec * (K - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck.append(molec)
tab_nck.append(1)

molec = 1
tab_nck2 = [1]
for i in range(1, N - K + 1):
    molec = (molec * (N - K + 2 - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck2.append(molec)
tab_nck2.append(1)

# print("#", tab_nck)
# print("#", tab_nck2)

def nck(a, b):
    # a = K - 1
    if b < 0: return 0
    elif b > K - 1: return 0
    else: return tab_nck[b]

def nck2(a, b):
    # a = N - K + 1
    if b < 0: return 0
    elif b > N - K + 1: return 0
    else: return tab_nck2[b]

for i in range(1, K + 1):
    ans = 1
    #
    ans = (ans * nck(K - 1, i - 1)) % P
    ans = (ans * nck2(N - K + i - 1, i)) % P
    #
    print(ans)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
import sys
# input = sys.stdin.readline
P = 10 ** 9 + 7

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

# molec = 1
# for i in range(K - 1):
#     molec = (molec * (i + 1)) % P

power = 10 ** 9 + 5
digits = []
for i in range(64):
    digits.append(power % 2)
    power >>= 1

def modinv(b):
    binv = 1
    val = b % P
    for i, digit in enumerate(digits):
        if digit == 1:
            binv = (binv * val) % P
        val = (val * val) % P
    # print("##", b, binv)
    return binv

molec = 1
tab_nck = [1]
for i in range(1, K - 1):
    molec = (molec * (K - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck.append(molec)
tab_nck.append(1)

molec = 1
tab_nck2 = [1]
for i in range(1, N - K + 1):
    molec = (molec * (N - K + 2 - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck2.append(molec)
tab_nck2.append(1)

# print("#", tab_nck)
# print("#", tab_nck2)

def nck(a, b):
    # a = K - 1
    return tab_nck[b]

def nck2(a, b):
    # a = N - K + + 1
    return tab_nck2[b]

for i in range(1, K + 1):
    ans = 1
    #
    ans = (ans * nck(K - 1, i - 1)) % P
    # print("#", nck(K - 1, i - 1))
    ans = (ans * nck2(N - K + i - 1, i)) % P
    # print("#", nck2(N - K + i - 1, i))
    #
    print(ans)
Problem p03045 (python)

Fixed submission:
import sys
# input = sys.stdin.readline
inf = 10 ** 18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(M)]

# https://qiita.com/maron8676/items/6010128f4ef5c268f719
class UFnode(object):
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()
        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                unite_root.parent_ = root
                root.rank_ = max(root.rank_, unite_root.rank_ + 1)
            else:
                root.parent_ = unite_root
                unite_root.rank_ = max(root.rank_ + 1, unite_root.rank_)

nodes = [UFnode(i) for i in range(N)]

for i, (Xi, Yi, Zi) in enumerate(XYZ):
    nodes[Xi - 1].unite(nodes[Yi - 1])

print(len(set([nodes[i].find() for i in range(N)])))

Buggy submission (verdict: Runtime Error):
import sys
# input = sys.stdin.readline
inf = 10 ** 18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(M)]

grp = [0] * N
moushiokuri = []
idx = 1
for i, (Xi, Yi, Zi) in enumerate(XYZ):
    if grp[Xi - 1] == grp[Yi - 1] == 0:
        grp[Xi - 1] = grp[Yi - 1] = idx
        idx += 1
    elif grp[Xi - 1] == 0:
        grp[Xi - 1] = grp[Yi - i]
    elif grp[Yi - 1] == 0:
        grp[Yi - 1] = grp[Xi - 1]
    else:
        moushiokuri.append((grp[Xi - 1], grp[Yi - 1]))

for src, dst in moushiokuri:
    for i, grpi in enumerate(grp):
        if grpi == src:
            grp[i] = dst

# print("#", grp)

ans = len(set(grp))
if 0 in grp:
    ans -= 1
    ans += grp.count(0)

print(ans)
Problem p03307 (python)

Fixed submission:
# encoding: utf-8
N = int(input())
if N % 2: print(2 * N)
else: print(N)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8
import math
N = int(input())
A = list(map(int, input().split()))

def binsearch(seq, l, r, tar):
    # print("##", l, r, LmR[l:r + 1], tar)
    m = l + (r - l) // 2
    if l >= r: return l
    elif seq[m] < tar: return binsearch(seq, m + 1, r, tar)
    else: return binsearch(seq, l, m, tar)

Asum = [0]
tmp = 0
for Ai in A:
    tmp += Ai
    Asum.append(tmp)

LmR = []
for SAi in Asum[:-1]:
    LmR.append(-Asum[-1] + 2 * SAi)

ans = max(A) - min(A)
for b2 in range(2, N - 1):
    # b1
    # tar = -sum(A[b2:])
    tar = -(Asum[N] - Asum[b2])
    b1 = binsearch(LmR, 1, b2 - 1, tar)
    if tar - LmR[b1 - 1] < LmR[b1] - tar: b1 = max((1, b1 - 1))
    # escape
    if math.fabs((Asum[b2] - Asum[b1]) - (Asum[b1])) >= ans: continue
    # b3
    # tar = Asum[:b2]
    tar = Asum[b2]
    b3 = binsearch(LmR, b2 + 1, N - 1, tar)
    if tar - LmR[b3 - 1] < LmR[b3] - tar: b3 = max((b2 + 1, b3 - 1))
    parts = (Asum[b1], Asum[b2] - Asum[b1], Asum[b3] - Asum[b2], Asum[-1] - Asum[b3])
    # print("#", A[:b1], A[b1:b2], A[b2:b3], A[b3:], parts)
    if max(parts) - min(parts) < ans: ans = max(parts) - min(parts)
    
print(ans)
Problem p03036 (python)

Fixed submission:
R, D, X = map(int, input().split())
for i in range(10):
    X = X*R - D
    print(X)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
lmax = 0
rmin = 10**5
for i in range(M):
    L, R = map(int, input().split())
    lmax = max(lmax, L)
    rmin = min(rmin, R)
ans = rmin - lmax
if ans >= 0:
    print(ans + 1)
else:
    print(0)
Problem p02598 (python)

Fixed submission:
from math import ceil

def isOK(length):
  ans = 0
  for a in A:
    ans += ceil(a / length) - 1
  return ans <= k

n, k = map(int, input().split())
A = list(map(int, input().split()))

start, end = 0, 10**9 + 1
while True:
  mid = (start + end) // 2
  if mid == 1:
    print(mid)
    exit()
  prev = mid - 1
  if isOK(mid):
    if isOK(prev):
      end = mid
    else:
      print(mid)
      exit()
  else:
    start = mid

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

def isOK(length):
  ans = 0
  for a in A:
    ans += ceil(a / length) - 1
  return ans <= k


n, k = map(int, input().split())
A = list(map(int, input().split()))

start, end = 0, 10**9 + 1
while True:
  mid = (start + end) // 2
  prev = mid - 1
  if isOK(mid):
    if isOK(prev):
      end = mid
    else:
      print(mid)
      exit()
  else:
    start = mid
Problem p02753 (python)

Fixed submission:
S = input()
if S == 'AAA' or S == 'BBB':
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
if S == 'AAA' or S == 'BBB':
  print('No')
else:
  print('Yes')
Problem p02771 (python)

Fixed submission:
array = list(map(int,input().split()))
array.sort()
if array[0] != array[2] and (array[0] == array[1] or array[1] == array[2]):
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
array = map(int,input().split())
array.sort()
if array[0] != array[2] and (array[0] == array[1] or array[1] == array[2]):
  print('Yes')
else:
  print('No')
Problem p02777 (python)

Fixed submission:
s,t = input().split()
a,b = map(int, input().split())
u = input()
 
dic = {s: a, t: b}
dic[u] -= 1
print(str(dic[s]) + ' ' + str(dic[t]))

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

dic = {s: a, t: b}
dic[u] -= 1
print(dic[s] + ' ' + dic[t])
Problem p03011 (python)

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

Buggy submission (verdict: Runtime Error):
array = list(map(int, input().split())).sort()
print(array[0]+array[1])
Problem p03012 (python)

Fixed submission:
n = int(input())
ws = list(map(int, input().split()))
ans = float('inf')
s = 0
whole = sum(ws)

for i in range(n-1):
  s += ws[i]
  ans = min(ans, abs(whole- 2*s))

print(ans)

Buggy submission (verdict: Runtime Error):
n = input()
ws = list(map(int, input().split()))
ans = float('inf')
s = 0
whole = sum(ws)

for i in range(n-1):
  s += ws[i]
  ans = min(ans, abs(whole- 2*s))

print(ans)
Problem p03041 (python)

Fixed submission:
n, k = map(int, input().split())
s = list(input())
s[k-1] = s[k-1].lower()
print("".join(s))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
s[k] = s[k].lower()
Problem p02699 (python)

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

if A<=B:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
S = [int(a) for a in input()[::-1]]
m = 2019
N = len(S)
s = 0
p = 1
X = [0] * 2019
X[0] = 1
ans = 0


for a in S:

    s = (s + a * p) % m
    ans += X[s]
    X[s] += 1
    p = p * 10 % m
 
print(ans)
Problem p02701 (python)

Fixed submission:
N = int(input())
 
Ws = [input() for _ in range(N)]
 
print(len(set(Ws)))

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

Ws = [s for _ in range(N)]

print(len(set(Ws)))
Problem p03327 (python)

Fixed submission:
N = int(input())

if N < 1000:
    print('ABC')
else:
    print('ABD')

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

if N < 1000:
    print(f'ABC{N:03}')
else:
    print(f'ABD{N-999:03}')
Problem p02725 (python)

Fixed submission:
K,N=map(int,input().split())
A=[int(i) for i in input().split()]
ma=K-A[-1]+A[0]
for i in range(N-1):
    Z=A[i+1]-A[i]
    ma=max(ma,Z)
print(K-ma)

Buggy submission (verdict: Runtime Error):
K,N=map(int,input().split())
a,b,c=map(int,input().split())
print(min(c-a,K-b+a,b+K-c))
Problem p02753 (python)

Fixed submission:
S=input()
station=set(S)
if len(station)>1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S=input()
if S[1]==S[2]==S[3]:
    print('No')
else:
    print('Yes')
Problem p02777 (python)

Fixed submission:
S,T=map(str,input().split())
A,B=map(int,input().split())
U=input()
if U==S:
    A-=1
else:
    B-=1
print(A, B)

Buggy submission (verdict: Runtime Error):
S,T=map(str,input().split())
A,B=map(int,input().split())
U=input()
if U==S:
    A-=1
else:
    B-=1
print(f"{A} {B}")
Problem p02831 (python)

Fixed submission:
import fractions
A,B=map(int,input().split())
print(A*B//(fractions.gcd(A,B)))

Buggy submission (verdict: Runtime Error):
import math
A,B=map(int,input().split())
print(A*B//(math.gcd(A,B)))

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
import math
print(A*B//(math.gcd(A,B)))
Problem p02915 (python)

Fixed submission:
N=int(input())
print(N**3)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
ans=sum(B)
for s in range(N-1):
        if A[s+1]==A[s]+1:
            ans+=C[A[s]-1]
print(ans)
Problem p03127 (python)

Fixed submission:
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=fractions.gcd(ans,A[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=fractions.gcd(ans,A[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=math.gcd(ans,A[i+1])
print(ans)
Problem p03327 (python)

Fixed submission:
N=int(input())
print('ABC' if N<=999 else'ABD')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
n=b-a
summy=((n+1)*n)/2
print(int(summy-b))
Problem p02881 (python)

Fixed submission:
import math

N = int(input())

sqrtN = int(math.sqrt(N))

for i in reversed(range(1, sqrtN+1)):
    if N % i == 0:
        print(int(i + N/i - 2))
        quit(0)

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

count = 0
odd = []
even = []
idou = []

for a in range(2, N):
    if N % a == 0:
        if count == 0:
            odd.append(a)
            count = 1
            if N / (a * a) == 1:
                even.append(a)
                count = 0

        elif count == 1:
            even.append(a)
            count = 0
            if N / (a * a) == 1:
                odd.append(a)
                count = 1

for c in range(len(odd)):
    idou.append(odd[c] + even[len(odd)-c-1])

result = min(idou) - 2

print(result)
Problem p02629 (python)

Fixed submission:
import math
from decimal import Decimal

N = int(input())

res = ""

alp = "0abcdefghijklmnopqrstuvwxyz"

while N > 0:
    # print(N)
    if N > 26:
        
        NN = N//26
        # print("NN: ", NN)
        # print(N - NN*26)
        m = N - NN*26
        N = N//26
        # print("m is ", m)
        if m==0:
            m=26
            N = N-1
        # print(alp[m], "!")
        res = alp[m] + res
    else:
        # print(alp[N])
        # print(alp[N], "!")
        res = alp[N] + res
        N = 0

print(res)

Buggy submission (verdict: Runtime Error):
import math
from decimal import Decimal

N = int(input())

res = ""

alp = "0abcdefghijklmnopqrstuvwxyz"

while N > 0:
    if N > 26:
        
        NN = N//26
        m = N - NN*26
        N = N//26
        # print(alp[m])
        res = alp[m] + res
    else:
        # print(alp[N])
        res = alp[m] + res
        N = 0

print(res)
Problem p02679 (python)

Fixed submission:
import math
N = int(input())
A = 0
B = 0
Z = 0
C = {}
m = 1000000007

def mypow(dummy, num):
    ans = 1
    for i in range(num):
        ans = (ans*2)%1000000007
    return ans

def rNum(a, b):
    g = math.gcd(a, b)
    if a <0 and b<0:
        a *= -1
        b *= -1
    if a >0 and b <0:
        return (-1*(a//g), -1*(b//g))
    else:
        return (a//g, b//g)


for i in range(N):
    a, b = map(int, input().split())
    
    if a == 0 and b==0:
        Z += 1
        continue
    elif a==0:
        A += 1
        continue
    elif b==0:
        B +=1
        continue
    
    r = rNum(a, b)
    if r in C.keys():
        C[r] +=1
    else: C[r] = 1


used = set()
ans = 1
ans *= (mypow(2, A) + mypow(2, B) -1)%m


for c in C.keys():
    if c in used: continue
    a, b = c
    r = rNum(b, -1*a)
    if r in C.keys():
        if c == r: continue
        used.add(r)
        score = (mypow(2, C[c]) + mypow(2, C[r])- 1)
        ans *= score

    else:
        ans *= mypow(2, C[c])

ans += Z

print((ans-1)%m)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
B = []
C = {}
m = 1000000007

def mypow(dummy, num):

    ans = 1
    for i in range(num):
        ans = (ans*2)%1000000007
    return ans

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    if a/b in C.keys():
        C[a/b] +=1
    else: C[a/b] = 1
    
used = set()
ans = 1
for c in C.keys():
    if c in used: continue
    if -1/c in C.keys():
        used.add(-1/c)
        
        score = mypow(2, C[c]) + mypow(2, C[-1/c])- 1
        
        ans = (ans * score)%m

    else:
        
        ans = (ans*mypow(2, C[c]))%m

print(ans-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
B = []
C = {}
m = 1000000007
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    if a/b in C.keys():
        C[a/b] +=1
    else: C[a/b] = 1
    
used = set()
ans = 1
for c in C.keys():
    if c in used: continue
    if -1/c in C.keys():
        used.add(-1/c)
        score = pow(2, C[c]) + pow(2, C[-1/c])- 1
        
        ans = (ans * score)%m

    else:
        
        ans = (ans*pow(2, C[c]))%m

print(ans-1)
Problem p02682 (python)

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

score = 0
if A < K:
    K -=A
    score += A
else:
    score = K
    print(score)
    exit()

if B < K:
    K -=B
else:
    print(score)
    exit()

if C < K:
    K -=C
    score -= C
else:
    score -= K
    print(score)
    exit()
print(score)

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

if A >= K:
    print(A)
elif A+B >=K:
    print(A)
else A+B+C >=K:
    nc = K - A - B
    print(A - nc)
Problem p02753 (python)

Fixed submission:
S = input()
if S == "AAA" or S=="BBB":
    print("No")
else:print("Yes")

Buggy submission (verdict: Runtime Error):

S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f == '1':
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
# slist = list(slist)
if isReversed:
    slist.reverse()

print("".join(slist))
# print(S)
Problem p02990 (python)

Fixed submission:
import math
n, k = (int(i) for i in input().split()) 
mod = 1000000007

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

r = n - k
for i in range(1, k+1):
  if r + 1 >= i:
    print(combinations_count(r+1, i) % mod * combinations_count(k-1, i-1) % mod)
  else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
n, k = (int(i) for i in input().split()) 
mod = 1000000007

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

r = n - k
for i in range(1, k+1):
    print(combinations_count(r+1, i) % mod * combinations_count(k-1, i-1) % mod)

Buggy submission (verdict: Runtime Error):
import math
n, k = (int(i) for i in input().split()) 
mod = 1000000007

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

r = n - k
for i in range(1, k+1):
    print(combinations_count(r+1, i) * combinations_count(k-1, i-1) % mod)
Problem p03104 (python)

Fixed submission:
A, B = map(int, input().split())
 
def xor(A):
  ans = ((A+1)//2)%2
  if A%2==0:
    ans ^= A
  return ans
 
print(xor(B)^xor(A-1))

Buggy submission (verdict: Runtime Error):
from functools import reduce
from operator import xor
a, b = (int(i) for i in input().split())  
print(reduce(xor, list(range(a, b+1))))
Problem p03127 (python)

Fixed submission:
import fractions
N = int(input())
A = [int(i) for i in input().split()]
gcd = A[0]
for i in range(N-1):
  gcd = fractions.gcd(gcd, A[i+1])
  
print(gcd)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
A = set(A)
 
min1 = min(A)
A.remove(min1)
min2 = min(A)
if len(A) == 1:
  print(A.pop())
  exit()
 
is_all_even = True
 
for x in A:
  if x % 2 == 1:
    is_all_even = False
    break
    
if is_all_even or min2 % min1 == 0:
  print(min(A))
else:
  print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
A = set(A)

if len(A) == 1:
  print(A.pop())
  exit()

min1 = min(A)
A.remove(min1)
min2 = min(A)

while True:
  min3 = min(A)
  A.remove(min3)
  if min3 % 2 == 1:
    break 
  
while True:
  tmp1 = min1
  min1 = min2 % min1
  min2 = tmp1
  
  tmp2 = min3
  min3 = min2 % min3
  min2 = tmp2
  if min1 == 0:
    min1 = tmp1
    min3 = tmp2
    break
  if min1 == 1:
    break
    
print(min(min1, min3))
Problem p03221 (python)

Fixed submission:
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
D = [[] for _ in range(N)]

for i, (p, y) in enumerate(PY):
  D[p-1].append((y, i))

ans = [None] * M
output = [[] for _ in range(M)]
for i, d in enumerate(D):
  d.sort()
  for k, (y, j) in enumerate(d):
    ans[j] = (i, k)

for i, k in ans:
  print('{}{}'.format(str(i+1).zfill(6), str(k+1).zfill(6)))

Buggy submission (verdict: Runtime Error):
import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for i in range(M):
  p, y = [int(i) for i in input().split()]
  if p not in d:
    d[p] = [y]
  else:
    #d[p] = (d[p] + [y])
    index = bisect.bisect_left(d[p], y)
    d[p].insert(index, y)

 #for x in d:
 # d[x].sort()

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))9
Problem p03307 (python)

Fixed submission:
n = int(input())

if n % 2 == 0:
  print(n)
else:
  print(n * 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()] 

print(max(a) - min(a))