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

Fixed submission:
a=input()
if a[0]==a[1] and a[1]==a[2]:
    print("Yes")
elif a[3]==a[1] and a[1]==a[2]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a=input().split()
if a[0]==a[1] and a[1]==a[2] and a[2]!=a[3]:
    print("Yes")
elif a[3]==a[1] and a[1]==a[2] and a[1]!=a[0]:
    print("Yes")
else:
    print("No")
Problem p03611 (python)

Fixed submission:
n=int(input())

a=[int(i) for i in input().split()]
a.sort()

succession=0
pre=-10000
maxnum=0
check=[0,0,0]

for i in a:
#     print(i)
    if pre<i-2:
        succession=0
        pre=i
        maxnum=max(maxnum,sum(check))
        check=[1,0,0]
    elif pre==i:
        check[succession]+=1
    elif pre==i-1 and succession==0:
        succession+=1
        check[1]+=1
        pre=i
    elif pre==i-1 and succession==1:
        succession+=1
        check[2]+=1
        pre=i
    elif pre==i-1 and succession==2:
        maxnum=max(maxnum,sum(check))
        check=[check[1],check[2],1]
        pre=i
    elif pre==i-2:
        maxnum=max(maxnum,sum(check))
        check=[check[succession],0,1]
        succession=2
        pre=i
#     print(check)
maxnum=max(maxnum,sum(check))

print(maxnum)

Buggy submission (verdict: Runtime Error):
for i in a:
#     print(i)
    if pre<i-2:
        succession=0
        pre=i
        maxnum=max(maxnum,sum(check))
        check=[1,0,0]
    elif pre==i:
        check[succession]+=1
    elif pre==i-1 and succession==0:
        succession+=1
        check[1]+=1
        pre=i
    elif pre==i-1 and succession==1:
        succession+=1
        check[2]+=1
        pre=i
    elif pre==i-1 and succession==2:
        maxnum=max(maxnum,sum(check))
        check=[check[1],check[2],1]
        pre=i
    elif pre==i-2:
        maxnum=max(maxnum,sum(check))
        check=[check[succession],0,1]
        succession=2
        pre=i
#     print(check)
maxnum=max(maxnum,sum(check))

print(maxnum)
Problem p03777 (python)

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

if a==b:
    print("H")
else:
    print("D")

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

if a==b:
    print("H")
else:
    print("D")
Problem p03797 (python)

Fixed submission:
n, m = [int(i) for i in input().split()]

if 2*n >= m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 4)

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

if n >= 2 * m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 2)
n, m = [int(i) for i in input().split()]

if n >= 2 * m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 4)

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

if n >= 2 * m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 2)
n, m = [int(i) for i in input().split()]

if n >= 2 * m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 4)
Problem p03998 (python)

Fixed submission:
a=list(input()+"A")[::-1]
b=list(input()+"B")[::-1]
c=list(input()+"C")[::-1]

turn=a

def game(turn):
    card=turn.pop()
    if len(turn)==0:
        print(card)
    else:
        
    
        if card=="a":
            turn=a
        elif card=="b":
            turn=b
        else:
            turn=c
    
        game(turn)
    
game(turn)

Buggy submission (verdict: Runtime Error):
a=list(input()+"A")[::-1]
b=list(input()+"B")[::-1]
c=list(input()+"C")[::-1]

turn=a

def game(turn):
    card=turn.pop()
    if len(turn)==0:
        print(card)
    
    if card=="a":
        turn=a
    elif card=="b":
        turn=b
    else:
        turn=c
    
    game(turn)
    
game(turn)
Problem p02555 (python)

Fixed submission:
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**9 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

s = int(input())

ans = 0
for i in range(1, s // 3 + 1):
    rest = s - 3 * i
    ans += cmb(rest + i - 1, rest, MOD)

print(ans % MOD)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**9 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

ans = 0
for i in range(1, s // 3 + 1):
    rest = s - 3 * i
    ans += cmb(rest + i - 1, rest, MOD)

print(ans % MOD)
Problem p02574 (python)

Fixed submission:
import numpy as np
from numba import njit


n = int(input())
arr = np.array(list(map(int, input().split())))


n = 10**6 + 1
primes = set(range(3, n+1, 2))

for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes.add(2)


@njit
def solve(arr, primes):
    cnt = np.bincount(arr)
    for p in primes:
        if (cnt[p::p]).sum() > 1:
            return False
    else:
        return True


if np.gcd.reduce(arr) != 1:
    print("not coprime")
elif solve(arr, primes):
    print("pairwise coprime")
else:
    print("setwise coprime")

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit


n = int(input())
arr = np.array(list(map(int, input().split())))


n = 10**3
primes = set(range(3, n+1, 2))

for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes.add(2)


@njit
def solve(arr, primes):
    used = [False] * 1000
    ans = True
    for x in arr:
        for p in primes:
            while x % p == 0:
                if used[p]:
                    ans = False
                    return ans
                while x % p == 0:
                    x //= p
                used[p] = True
    return ans


ans1 = np.all([sum(cnt[i::i]) <= 1 for i in range(2, 10**6+1)])


if np.gcd.reduce(arr) != 1:
    print("not coprime")
elif ans1:
    print("pairwise coprime")
else:
    print("setwise coprime")

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = np.array(list(map(int, input().split())))


@njit
def solve(arr):
    for i in range(arr.shape[0] - 1):
        if np.gcd(arr[i], arr[i + 1]) != 1:
            ans1 = False
            break
    else:
        ans = True
    return ans


ans1 = solve(arr)
ans2 = np.gcd.reduce(arr) == 1

if ans1 and ans2:
    print("pairwise coprime")
elif ans2:
    print("setwise coprime")
else:
    print("not coprime")

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
arr = np.array(list(map(int, input().split())))

def solve()
for i in range(arr.shape[0] - 1):
    if np.gcd(arr[i], arr[i + 1]) != 1:
        ans1 = False
        break
else:
    ans1 = True

ans2 = np.gcd.reduce(arr) == 1

if ans1 and ans2:
    print("pairwise coprime")
elif ans2:
    print("setwise coprime")
else:
    print("not coprime")

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from collections import Counter

n = int(input())
arr = list(map(int, input().split()))

a = 1
result = []
for x in arr:
    y = gcd(a, x)
    result.append(y)
    a = a * x // y

if result.count(1) == len(arr):
    print("pairwise coprime")
    sys.exit()

if len(Counter(result[1:])) == 1:
    print("not coprime")
else:
    print("setwise coprime")
Problem p02614 (python)

Fixed submission:
import numpy as np
from itertools import product

h, w, k = map(int, input().split())
grid = np.array([list(map(str, input().rstrip())) for _ in range(h)])

ans = 0
for i in np.array(list(product([0, 1], repeat=h)), np.bool):
    for j in np.array(list(product([0, 1], repeat=w)), np.bool):
        if np.any(i) and np.any(j):
            arr = grid[i].copy()
            arr = arr[:, j]
            arr = arr.flatten()
            if np.where(arr == "#")[0].shape[0] == k:
                ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

h, w, k = map(int, input().split())
grid = np.array([list(map(str, input().rstrip())) for _ in range(h)])

ans = 0
for i in np.array(list(product([0, 1], repeat=h)), np.bool):
    for j in np.array(list(product([0, 1], repeat=w)), np.bool):
        if np.any(i) and np.any(j):
            arr = grid[i].copy()
            arr = arr[:, j]
            arr = arr.flatten()
            if np.where(arr == "#")[0].shape[0] == k:
                ans += 1

print(ans)
Problem p02618 (python)

Fixed submission:
import numpy as np
d = int(input())
c = list(map(int, input().split()))
s = np.array([list(map(int, input().split())) for _ in range(d)])

init = s.argmax(axis=1) + 1

print(*init, sep="\n")

Buggy submission (verdict: Runtime Error):
d = int(input())
c = list(map(int, input().split()))
s = np.array([list(map(int, input().split())) for _ in range(d)])

init = s.argmax(axis=1) + 1

for i in range(d):
    print(init[i])
Problem p02630 (python)

Fixed submission:
from collections import defaultdict
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
arr = defaultdict(int)
for k, v in Counter(a).items():
    arr[k] = v
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))

whole = sum([x * y for x, y in arr.items()])

for b, c in bc:
    arr[c] += arr[b]
    tmp = arr[b]
    arr[b] = 0
    whole += (c - b) * tmp
    print(whole)

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

n = int(input())
a = list(map(int, input().split()))
arr = defaultdict(int)
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))


@jit
def solve(n, a, arr, q, bc):
    for k, v in Counter(a).items():
        arr[k] = v

    q = int(input())

    for b, c in bc:
        arr[c] += arr[b]
        arr[b] = 0
        print(sum([x * y for x, y in arr.items()]))


solve(n, a, arr, q, bc)

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

n = int(input())
a = list(map(int, input().split()))
arr = defaultdict(int)
q = int(input())
bc = []
for _ in range(q):
    b, c = map(int, input().split())
    bc.append((b, c))


@jit('void(i8, i8[:], i8[:], i8, i8[:])')
def solve(n, a, arr, q, bc):
    for k, v in Counter(a).items():
        arr[k] = v

    q = int(input())

    for b, c in bc:
        arr[c] += arr[b]
        arr[b] = 0
        print(sum([x * y for x, y in arr.items()]))


solve(n, a, arr, q, bc)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
arr = np.array(list(map(int, input().split())))
q = int(input())

cnt = np.bincount(arr)
cnt = np.concatenate([cnt, np.zeros(10**5 - cnt.shape[0], dtype=int)])

for i in range(q):
    b, c = map(int, input().split())
    cnt[c] += cnt[b]
    cnt[b] = 0
    print((cnt * np.arange(cnt.shape[0])).sum())
Problem p02632 (python)

Fixed submission:
def solve(k, length, MOD, div, dp):
    for i in range(1, k + 1):
        dp[0] = dp[0] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
        dp[1] = (dp[1] + dp[0]) % MOD

    return(dp[1])


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7
div = pow(26, -1, MOD)

dp = [pow(26, k, MOD)] * 2

print(solve(k, length, MOD, div, dp))

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

length = len(s)
MOD = 10**9 + 7

dp = [[0] * (k + 1) for _ in range(2)]
dp[0][0] = pow(26, k, MOD)
dp[1][0] = pow(26, k, MOD)

div = pow(26, -1, MOD)

for i in range(1, k + 1):
    dp[0][i] = dp[0][i - 1] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
    dp[1][i] = (dp[1][i - 1] + dp[0][i]) % MOD

print(dp[-1][-1])
Problem p02702 (python)

Fixed submission:
import numpy as np

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)
x = 10

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * x % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1
    x = x * 10 % 2019

ans_c = ans[np.nonzero(ans)]

print(int(sum([ans_c[i] * (ans_c[i]-1) for i in range(ans_c.shape[0])]) / 2) + ans[0])

Buggy submission (verdict: Runtime Error):
# ABC164 D - Multiple of 2019
import numpy as np

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * 10**i % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1

ans_f = ans[np.nonzero(ans)]

print(int(sum([ans_f[i] * (ans_f[i]-1) for i in range(ans_f.shape[0])]) / 2) + ans[0])

Buggy submission (verdict: Runtime Error):
# ABC164 D - Multiple of 2019
import numpy as np

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * 10**i % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1

ans_f = ans[np.nonzero(ans)]

print(int(sum([ans_f[i] * (ans_f[i]-1) for i in range(ans_f.shape[0])]) / 2) + ans[0])

Buggy submission (verdict: Runtime Error):
import numpy as np
import math

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)

for i in range(length):
    a[i] = int(s[i]) * pow(10, i) % 2019
d[0] = a[0]

for i in range(length-1):
    d[i+1] = (d[i] + a[i+1]) % 2019
    
x = np.unique(d, return_counts=True)[1]
x = x[np.where(x > 1)]

print(int(sum([math.factorial(x[i]) for i in range(x.shape[0])]) / 2) + d.shape[0] - np.count_nonzero(d))

Buggy submission (verdict: Runtime Error):
import numpy as np
import math

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)

for i in range(length):
    a[i] = int(s[i]) * pow(10, i) % 2019
d[0] = a[0]

for i in range(length-1):
    d[i+1] = (d[i] + a[i+1]) % 2019
    
x = np.unique(d, return_counts=True)[1]
x = x[np.where(x > 1)]

print(int(sum([math.factorial(x[i]) for i in range(x.shape[0])]) / 2) + d.shape[0] - np.count_nonzero(d))

Buggy submission (verdict: Runtime Error):
import numpy as np
s = input()
print(0) if int(s) < 2019 else print(sum(np.mod(int(s[j:i+j]), 2019) == 0 for i in range(4, len(s)) for j in range(len(s)-i+1)))

Buggy submission (verdict: Runtime Error):
import numpy as np
s = input()
print(0) if int(s) < 2019 else print(sum(np.mod(int(s[j:i+j]), 2019) == 0 for i in range(4, len(s)) for j in range(len(s)-i+1)))

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

if int(s) < 2019:
    print(0)
else:
    count = sum(int(s[j:i+j]) % 2019 == 0 for i in range(4, len(s)) for j in range(len(s) - i + 1))
print(count)
Problem p02743 (python)

Fixed submission:
from decimal import Decimal
a, b, c = map(Decimal, input().split())

ans = (c - a - b)**2 > 4 * a * b

if c - a - b < 0:
    ans = False

print("Yes" if ans else "No")

Buggy submission (verdict: Runtime Error):
from decimal import Decimal, getcontext
getcontext().prec = 1000

li = list(map(Decimal, input().split()))
li = map(lambda x: x.sqrt(), li)

print("Yes" if a + b < c else "No")
Problem p02748 (python)

Fixed submission:
from collections import defaultdict
import numpy as np

A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

ans = a.min() + b.min()

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

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

A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

C = defaultdict(int)

for i in range(M):
    x, y, c = map(int, input().split())
    C[tuple([x-1, y-1])] = c

ans = a.min() + b.min()

for c in C:
    ans = min(ans, a[c[0]] + b[c[0]] - C[c])
    
print(ans)
Problem p02761 (python)

Fixed submission:
import sys
from collections import defaultdict

N, M = map(int, input().split())
d = defaultdict(int)

for i in range(M):
    s, c = map(int, input().split())
    if (d[s] != 0) & (d[s] != c):
        print(-1)
        sys.exit()
    elif ((s == 1) & (c == 0)) & (N > 1):
        print(-1)
        sys.exit()
    elif d[s] == 0:
        d[s] = c
    else:
        continue

if N==1:
    print(d[1])
    sys.exit()

ans = ["1"] + ["0"] * (N - 1)

for s, c in d.items():
    ans[int(s) - 1] = str(c)

print("".join(ans))

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

N, M = map(int, input().split())
d = defaultdict(int)

for i in range(M):
    s, c = map(int, input().split())
    if (d[s] != 0) & (d[s] != c):  # 数指定に矛盾があったら終わり
        print(-1)
        sys.exit()
    elif ((s == 1) & (c == 0)) & (N > 1):　　# 桁数に矛盾があったら終わり
        print(-1)
        sys.exit()
    elif d[s] == 0:　　# 初めて出会ったものはメモしていく
        d[s] = c
    else:
        continue

# 1桁ならそのまま出す
if N==1:
    print(d[1])
    sys.exit()

# 2桁以上の場合は最も大きい桁を1、それ未満の桁を0で初期化
ans = ["1"] + ["0"] * (N - 1)

# 値更新
for s, c in d.items():
    ans[int(s) - 1] = str(c)

print("".join(ans))

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

n, m = map(int, input().split())
tmp = [0] * n
memo = defaultdict(int)

for i in range(m):
    s, c = map(int, input().split())
    if i==0:
        memo[s] = c
    elif s in memo & memo[s]!=c:
        print(-1)
        sys.exit()
    elif (n==3 & s==1 & c==0):
        print(-1)
        sys.exit()
    else:
        tmp[s-1] = c
    
print(0) if sum(tmp) == 0 else print(*tmp, sep="")

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
s = [0] * m
c = [0] * m
tmp = [0] * m

for i in range(m):
    s[i], c[i] = map(int, input().split())
    
for x, y in zip(s, c):
    if tmp[x-1]==0:
        tmp[x-1] = y
    elif tmp[x-1]==y:
        continue
    else:
        print(-1)
        sys.exit()

ans = 0

for i, a in enumerate(tmp[::-1]):
    ans += a*10**(i)

if n==1 & ans==0:
    print(ans)
elif ans // 10**(m-1) < 1:
    print(-1)
    sys.exit()
    
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
s = [0] * m
c = [0] * m
tmp = [0] * m

for i in range(m):
    s[i], c[i] = map(int, input().split())
    
for x, y in zip(s, c):
    if tmp[x-1]==0:
        tmp[x-1] = y
    elif tmp[x-1]==y:
        continue
    else:
        print(-1)
        sys.exit()

ans = 0
for i, a in enumerate(tmp[::-1]):
    ans += a*10**(i)

if (n==1) & (ans==0):
    print(0)
    sys.exit()

if (n>=2) & (ans < 10**(n-1)):
    print(-1)
    sys.exit()
    
print(ans)
Problem p02765 (python)

Fixed submission:
N, R = map(int, input().split())
print(R + 100*(10-N)) if N < 10 else print(R)

Buggy submission (verdict: Runtime Error):
N, R = map(int, input().split())
print(R + 100*(10-N)) if n < 10 else print(R)
Problem p02780 (python)

Fixed submission:
import numpy as np
from decimal import Decimal

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

if N==1:
    print((p.max() + 1) / Decimal(2))
elif N==K:
    print((p.sum() + K) / Decimal(2))
else:
    p = np.cumsum(p)

    ans = []
    for i in range(N - K):
        ans.append(p[i + K]-p[i])

    ans = (max(ans) + K) / Decimal(2)

    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from decimal import Decimal

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

if N==1:
    print((p.max() + 1) / Decimal(2))
else:
    p = np.cumsum(p)

    ans = []
    for i in range(N - K):
        ans.append(p[i + K]-p[i])

    ans = (max(ans) + K) / Decimal(2)

    print(ans)
Problem p02791 (python)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
m = float('inf')
ans = 0

for p in P:
    if p <= m:
        ans += 1
        m = p

print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
P = list(map(int, input().split()))
m = math.inf
ans = 0

for p in P:
    if p <= m:
        ans += 1
        m = p

print(ans)
Problem p02804 (python)

Fixed submission:
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


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


MOD = 10 ** 9 + 7
facts, invs = prepare(n, MOD)

ans_max = 0
for i in range(k - 1, n):
    ans_max += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

arr.sort(reverse=True)

ans_min = 0
for i in range(k - 1, n):
    ans_min += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

print((ans_max - ans_min) % MOD)

Buggy submission (verdict: Runtime Error):
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


MOD = 10 ** 9 + 7
facts, invs = prepare(n, MOD)


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

ans_max = 0
for i in range(k - 1, n):
    ans_max += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

arr.sort(reverse=True)

ans_min = 0
for i in range(k - 1, n):
    ans_min += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

print((ans_max - ans_min) % MOD)
Problem p02842 (python)

Fixed submission:
import math, sys
N = int(input())
p = [int(N/1.08), math.ceil(N/1.08)]

for n in p:
    if int(n*1.08)==N:
        print(n)
        sys.exit()

print(":(")

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
p = [int(N/1.08), math.ceil(N/1.08)]

for n in p:
    if int(n*1.08)==N:
        print(n)
        sys.exit()

print(":(")
Problem p02843 (python)

Fixed submission:
X = int(input())

if X >= 2000:
    print(1)
elif X < 100:
    print(0)
else:
    limit, mods = divmod(X, 100)
    if mods / limit <= 5:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import sys
X = int(input())

if X >= 2000:
    print(1)
else:
    limit, mods = divmod(X, 100)
    if mods / limit <= 5:
        print(1)
    else:
        print(0)
Problem p02850 (python)

Fixed submission:
from collections import deque
from collections import defaultdict

n = int(input())
graph = defaultdict(list)

for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append([b, i])
    graph[b].append([a, i])

ans = [0] * (n - 1)

q = deque([[1, 0, 0]])
while q:
    v, pcol, root = q.popleft()
    cnt = 1
    for node in graph[v]:
        if node[0] == root:
            continue
        if cnt == pcol:
            cnt += 1
        ans[node[1]] = cnt
        q.append([node[0], cnt, v])
        cnt += 1

print(max(ans))
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
from collections import deque
from collections import defaultdict
n = int(input())

graph = defaultdict(list)

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

max_c = max([len(x) for x in list(graph.values())])

colors = set(range(1, max_c + 1))


q = deque([1])
ans = [0] * (n + 1)
ans[1] = 1

while q:
    curr = q.popleft()
    can_use = colors - set([ans[curr]])
    for v in graph[curr]:
        if ans[v] == 0:
            ans[v] = min(can_use)
            can_use -= set([min(can_use)])
            q.append(v)

print(*ans[1:], sep="\n")