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

Fixed submission:
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    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
c = Combination(3000)

def H(n, r, mod=10**9+7):
    return c(n+r-1, r)


mod = 10**9+7
N, K = map(int, input().split())
B = K
R = N-K
for i in range(1, K+1):
    bn = i
    br = B-i
    rn = i+1
    rr = R-i+1
    if rr<0 or br<0:
        print(0)
    else:
        #print(i, bn, br, rn, rr)
        ans = H(bn, br) * H(rn, rr) % mod
        print(ans)

Buggy submission (verdict: Runtime Error):
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    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
c = Combination(3000)

def H(n, r, mod=10**9+7):
    return c(n+r-1, r)


mod = 10**9+7
#N, K = map(int, input().split())
N = int(input())
K = int(input())
B = K
R = N-K
for i in range(1, K+1):
    bn = i
    br = B-i
    rn = i+1
    rr = R-i+1
    if rr<0 or br<0:
        print(0)
    else:
        #print(i, bn, br, rn, rr)
        ans = H(bn, br) * H(rn, rr) % mod
        print(ans)
Problem p03253 (python)

Fixed submission:
from collections import defaultdict

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


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

pr = prime_decomposition(M)
di = defaultdict(int)
for p in pr:
    di[p] += 1
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def combination(n, mod):
    lst = [1]
    for i in range(1, n+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst
mod = 10**9+7
ans = 1
for k, v in di.items():
    ans *= combination(v+N-1, mod)[N-1]
    ans %= mod
print(ans)

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

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


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

pr = prime_decomposition(M)
di = defaultdict(int)
for p in pr:
    di[p] += 1

def combination(n, mod):
    lst = [1]
    for i in range(1, n+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst
mod = 10**9+7
ans = 1
for k, v in di.items():
    ans *= combination(v+N-1, mod)[N-1]
    ans %= mod
print(ans)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)

N = int(input())
ABC = [list(map(int, input().split())) for i in range(N-1)]
Q, K = map(int, input().split())
D = [0] * (N+1)
L = [[] for i in range(N+1)]
for a, b, c in ABC:
    L[a].append([b, c])
    L[b].append([a, c])


def dfs(n, np):
    for nc in L[n]:
        if nc[0] == np:
            continue
        else:
            D[nc[0]] = D[n] + nc[1]
            dfs(nc[0], n)


dfs(K, 0)
for i in range(Q):
    x, y = map(int, input().split())
    print(D[x] + D[y])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

N = int(input())
ABC = [list(map(int, input().split())) for i in range(N-1)]
Q, K = map(int, input().split())
D = [0] * (N+1)
L = [[] for i in range(N+1)]
for a, b, c in ABC:
    L[a].append([b, c])
    L[b].append([a, c])


def dfs(n, np):
    for nc in L[n]:
        if nc[0] == np:
            continue
        else:
            D[nc[0]] = D[n] + nc[1]
            dfs(nc[0], n)


dfs(K, 0)
for i in range(Q):
    x, y = map(int, input().split())
    print(D[x] + D[y])

Buggy submission (verdict: Runtime Error):
N = int(input())
ABC = [list(map(int, input().split())) for i in range(N-1)]
Q, K = map(int, input().split())
D = [0] * (N+1)
L = [[] for i in range(N+1)]
for a, b, c in ABC:
    L[a].append([b, c])
    L[b].append([a, c])


def dfs(n, np):
    for nc in L[n]:
        if nc[0] == np:
            continue
        else:
            D[nc[0]] = D[n] + nc[1]
            dfs(nc[0], n)


dfs(K, 0)
for i in range(Q):
    x, y = map(int, input().split())
    print(D[x] + D[y])
Problem p03726 (python)

Fixed submission:
N = int(input())

if N%2==1:
    print("First")
    exit()
elif N==2:
    print("Second")
    exit()

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

E_dim = [len(e) for e in E]
E_set = [set(e) for e in E]
q = []
for v, (dim, e) in enumerate(zip(E_dim, E)):
    if dim==1:
        for u in e:
            if E_dim[u] == 2:
                q.append(v)
                
while q:
    v = q.pop()
    u = E_set[v].pop()
    if E_dim[u] == 1:
        print("Second")
        exit()
    E_set[u].remove(v)
    w = E_set[u].pop()
    E_set[w].remove(u)
    E_dim[w] -= 1
    if E_dim[w] == 1:
        x = E_set[w].copy().pop()
        if E_dim[x] == 2:
            q.append(w)
    elif E_dim[w] == 2:
        for x in E_set[w]:
            if E_dim[x] == 1:
                q.append(x)
print("First")

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

if N%2==1:
    print("First")
    exit()
elif N==2:
    print("Second")
    exit()

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

E_dim = [len(e) for e in E]
E_set = [set(e) for e in E]
q = []
for v, (dim, e) in enumerate(zip(E_dim, E)):
    if dim==1:
        for u in e:
            if E_dim[u] == 2:
                q.append(v)
                
while q:
    v = q.pop()
    u = E[v][0]
    if E_dim[u] == 1:
        print("Second")
        exit()
    E_set[u].remove(v)
    w = E_set[u].pop()
    E_set[w].remove(u)
    E_dim[w] -= 1
    if E_dim[w] == 1:
        x = E_set[w].copy().pop()
        if E_dim[x] == 2:
            q.append(w)
    elif E_dim[w] == 2:
        for x in E_set[w]:
            if E_dim[x] == 1:
                q.append(x)
print("First")
Problem p03806 (python)

Fixed submission:
N, Ma, Mb = map(int, input().split())
L = [[float("inf")]*410 for i in range(410)]
P = [[0, 0]]
L[0][0] = 0

for i in range(N):
    a, b, c = map(int, input().split())
    OldP = P.copy()
    Lsub = [L[p[0]][p[1]] for p in OldP]
    for xp, p in enumerate(OldP):
        if L[p[0]+a][p[1]+b] == float("inf"):
            P.append([p[0]+a, p[1]+b])
        L[p[0]+a][p[1]+b] = min(L[p[0]+a][p[1]+b], Lsub[xp]+c)
g = [Ma, Mb]
ans = float("inf")
while g[0]<410 and g[1]<410:
    ans = min(ans, L[g[0]][g[1]])
    g[0] += Ma
    g[1] += Mb
print(ans if ans != float("inf") else -1)

Buggy submission (verdict: Runtime Error):
N, Ma, Mb = map(int, input().split())
L = [[float("inf")]*410 for i in range(410)]
P = [[0, 0]]
L[0][0] = 0

for i in range(N):
    a, b, c = map(int, input().split())
    OldP = P.copy()
    Lsub = [L[p[0]][p[1]] for p in OldP]
    for xp, p in enumerate(OldP):
        if L[p[0]+a][p[1]+b] == float("inf"):
            P.append([p[0]+a, p[1]+b])
        L[p[0]+a][p[1]+b] = min(L[p[0]+a][p[1]+b], Lsub[xp]+c)
g = [Ma, Mb]
ans = float("inf")
while g[0]<410 and g[1]<410:
    ans = min(ans, L[g[0]][g[1]])
    g[0] += Ma
    g[1] += Mb
print(ans if ans != float("inf") else -1)
Problem p03221 (python)

Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print('{:06}{:06}'.format(p, rank))

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

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print(f'{p:06}{rank:06}')

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

N, M = map(int, input().split())
P, Y = [], []
ylist = defaultdict(list)
pset = set()
for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    ylist[p].append(y)
    pset.add(p)
assert len(pset) == N

cdict = defaultdict(dict)
for p in pset:
    syear = sorted(ylist[p])
    for i, y in enumerate(syear):
        cdict[p][y] = i + 1

for i in range(M):
    p = P[i]
    y = Y[i]
    rank = cdict[p][y]
    print(f'{p:06}{rank:06}')
Problem p03346 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# dbg = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

N = ini()
P = list(map(int, sys.stdin.readlines()))
INF = 1 << 40


def solve():
    if N == 1:
        return 0

    inds = [None] * (N + 1)
    for i, x in enumerate(P):
        inds[x] = i

    streak = [1] * (N + 1)
    for k in range(2, N + 1):
        if inds[k - 1] < inds[k]:
            streak[k] = streak[k - 1] + 1
    ans = INF
    for k in range(2, N + 1):
        r = 0 if k == P[-1] else 1
        r += N - k
        l = (k - 1) - streak[k - 1]
        if ans > l + r:
            ans = l + r
        # dbg(f"{ans=} {l=} {r=}")
    return ans


print(solve())

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
dbg = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

N = ini()
P = list(map(int, sys.stdin.readlines()))
INF = 1 << 40


def solve():
    inds = [None] * (N + 1)
    for i, x in enumerate(P):
        inds[x] = i

    streak = [1] * (N + 1)
    for k in range(2, N + 1):
        if inds[k - 1] < inds[k]:
            streak[k] = streak[k - 1] + 1
    ans = INF
    for k in range(2, N + 1):
        r = 0 if k == P[-1] else 1
        r += N - k
        l = (k - 1) - streak[k - 1]
        if ans > l + r:
            ans = l + r
        # dbg(f"{ans=} {l=} {r=}")
    return ans


print(solve())
Problem p03835 (python)

Fixed submission:
K,S=map(int,input().split())
cnt=0
for x in range(K+1):
  for y in range(K+1):
    z = S - x - y
    if 0 <= z <= K:
      cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
K,S=map(int,input().split())
print(sum(1for x in range(K+1)for y in range(K+1)if0<=S-x-y<=K))
Problem p03986 (python)

Fixed submission:
X = list(input())
N = len(X)
NHALF = N // 2

def solve():
    nt, ns = 0, 0
    for i in range(N):
        if X[i] == 'S':
            ns += 1
        elif ns > 0:
            ns -= 1
        else:
            nt += 1
    return nt + ns


print(solve())

Buggy submission (verdict: Runtime Error):
X=input()
t,s=0,0
for x in X:
 if x=='S':ns+=1
 elif ns>0:ns-=1
 else:nt+=1
print(nt+ns)

Buggy submission (verdict: Runtime Error):
import sys
X = list(sys.stdin.readline().strip())
N = len(X)

def solve():
    cnt = 0
    i = 0
    while True:
        while i < N and X[i] != 'S':
            i += 1
        j = i + 1
        while j < N and X[j] != 'T':
            j += 1
        if j == N:
            return N - 2*cnt
        cnt += 1
        X[i] = ' '
        X[j] = ' '
        i += 1
        j += 1

print(solve())
Problem p02594 (python)

Fixed submission:
x = int(input())
if x>=30:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
x = int(input())
if x>=30:
  print("Yes")
else:
  praint("No")
Problem p02847 (python)

Fixed submission:
S = str(input())
day = 0
if S == "SUN":
    day = 7
elif S == 'MON':
    day = 6
elif S == 'TUE':
    day = 5
elif S == 'WED':
    day = 4
elif S == 'THU':
    day = 3
elif S == 'FRI':
    day = 2
elif S == 'SAT':
    day = 1
print(day)

Buggy submission (verdict: Runtime Error):
import math
# 二分探索で効率的に数値を探す。
A, B, X  = map(int,input().split())

def buy(N):
    if N <= 0:
        return 0
    else:
        s = A*N + B*((math.log10(N)//1)+1)
        return int(s)

n = 10**9
L = 1
H = n
if buy(n) <= X:
    print(n)
elif buy(1) > X:
    print(0)
else:
    while H - L > 1:
        mid = int((L+H)/2)
        if buy(mid) <= X:
            L = mid
        elif buy(mid) > X:
            H = mid
    print(L)
Problem p02935 (python)

Fixed submission:
N = int(input())
V = list(map(int,input().rstrip().split(' ')))
V.sort(reverse=True)

sum = 0
for i, v in enumerate(V):
    sum += v/(2**(i+1))
sum += V[-1]/(2**(N))
print(sum)

Buggy submission (verdict: Runtime Error):
N = int(input())
V = list(map(int,input().rstrip().split(' ')))
V.sort(reverse=True)

sum = 0
for i, v in enumerate(V):
    sum += v/(2**(i+1)))
sum += V[-1]/(2**(N-1))
print(sum)
Problem p02987 (python)

Fixed submission:
from collections import defaultdict
s = str(input())
d = defaultdict(int)
for x in s:
  d[x]+=1
if len(d)==2:
  for key in d:
    if d[key]!=2:
      print("No")
      exit()
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
s = str(input())
d = defaultdict(int)
for x in s:
  d[x]+=1
if len(d)==2:
  for key,value in d:
    if value!=2:
      print("No")
      exit()
  print("Yes")
else:
  print("No")
Problem p03104 (python)

Fixed submission:
# coding: utf-8
import os
from sys import stdin, stdout

__LOCAL__ = False
if(__LOCAL__):
    __dirname = os.path.dirname(__file__)
    __basename = os.path.splitext(os.path.basename(__file__))[0]
    __inputname = './input/' + __basename + '.txt'
    __outputname = './output/' + __basename + '.txt'
    input_path = os.path.join(__dirname, __inputname)
    output_path = os.path.join(__dirname, __outputname)
    stdin = open(input_path)
    stdout = open(output_path, "w")

def TLEmain():
    A, B = map(int,stdin.readline().rstrip().split(' '))
    ans = 0
    for x in range(A,B+1):
        ans ^= x
    print(ans)

def xorsum(A):
    if(A&1):
        return (A+1)//2 & 1
    else:
        return ((A+1)//2 & 1) ^ A

def main():
    A, B = map(int,stdin.readline().rstrip().split(' '))
    if(A==B):
        ans = A
        stdout.write("{}\n".format(ans))
    else:
        ans = xorsum(A-1)^xorsum(B)
        stdout.write("{}\n".format(ans))     

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import os
from sys import stdin, stdout

__LOCAL__ = True
if(__LOCAL__):
    __dirname = os.path.dirname(__file__)
    __basename = os.path.splitext(os.path.basename(__file__))[0]
    __inputname = './input/' + __basename + '.txt'
    __outputname = './output/' + __basename + '.txt'
    input_path = os.path.join(__dirname, __inputname)
    output_path = os.path.join(__dirname, __outputname)
    stdin = open(input_path)
    stdout = open(output_path, "w")

def TLEmain():
    A, B = map(int,stdin.readline().rstrip().split(' '))
    ans = 0
    for x in range(A,B+1):
        ans ^= x
    print(ans)

def xorsum(A):
    if(A&1):
        return (A+1)//2 & 1
    else:
        return ((A+1)//2 & 1) ^ A

def main():
    A, B = map(int,stdin.readline().rstrip().split(' '))
    if(A==B):
        ans = A
        stdout.write("{}\n".format(ans))
    else:
        ans = xorsum(A-1)^xorsum(B)
        stdout.write("{}\n".format(ans))     

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

Fixed submission:
a,b,c=map(int,input().rstrip().split(' '))
if(a==b and b==c):
	if(a%2==0):
		print(-1)
	else:
		print(0)
else:
	n=0
	while(a%2==0 and b%2==0 and c%2==0):
		n+=1
		tmp_a=(b+c)/2
		tmp_b=(a+c)/2
		tmp_c=(b+a)/2
		a=tmp_a
		b=tmp_b
		c=tmp_c
	print(n)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().rstrip().split(' '))
if(a==b and b==c):
	if(a%2==0):
    	print(-1)
	else:
		print(0)
else:
	n=0
	while(a%2==0 and b%2==0 and c%2==0):
		n+=1
		tmp_a=(b+c)/2
		tmp_b=(a+c)/2
		tmp_c=(b+a)/2
		a=tmp_a
		b=tmp_b
		c=tmp_c
	print(n)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input())
if(a==b and b==c):
	print(-1)
else:
	n=0
	while(a%2==0 and b%2==0 and c%2==0):
		n+=1
    	a=(b+c)/2
    	b=(a+c)/2
    	c=(b+a)/2
	print(n)
Problem p03785 (python)

Fixed submission:
n,c,k = map(int,input().split())
t = []
for i in range(n):
  t.append(int(input()))

t.sort()
ans = 0
now = 0
ter = -1
for i in range(n):
  if ter < t[i]:
    ans += 1
    ter = t[i]+k
    now = 1
  else:
    if(c<=now):
      ans+=1
      ter = t[i]+k
      now = 1
    else:
      now += 1
      
print(ans)

Buggy submission (verdict: Runtime Error):
n,c,k = map(int,input().split())
t = []
for i in range(n):
  t.append(int(input()))


sort(t)
ans = 0
now = 0
ter = -1
for i in range(n):
  if ter < t[i]+k:
    ans+=1
    ter = t[i]+k
    now = 1
  else:
    if(c>=now):
      ans+=1
      ter = t[i]+k
      now = 1
    else:
      now += 1
      
print(ans)
Problem p02835 (python)

Fixed submission:
import numpy as np
a = np.array(input().split(),dtype=int)
sum  = a[0] + a[1] + a[2]
if sum > 21:
    print("bust")
else:
    print("win")

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = np.array([[int(j) for j in list(format(i,'b').zfill(60))] for i in a]).T
mod = 10**9+7

"""
#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数を求める
c0 = np.sum(ba, axis=1)
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
a = np.array(input().split(),dtype=int)
sum  = a[0] + a[1] + a[2]
if sum > 21:
    print(bust)
else:
    print(win)
Problem p02815 (python)

Fixed submission:
# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

mod=10**9+7
N = int(input())
C = [0]
C.extend(sorted(list(map(int,input().split())), reverse=True)) # 1-indexed, 降順

# print(C)
# C[i]が最後からj番目に操作される（コストが C[i]*j 掛かる）のは，c[1]~C[i-1]にj-1個操作すべきもの，すなわち，C[i]以上のものがあるとき。
# C[i+1]~C[N]の選び方は自由。
# ⇒ combi(i-1, j-1)*2**(N-i) を掛ける。
# 総和を計算すると，結局，2**N * Σ[i=1->N](2**(N-i)*Ci*(2**(i-2)*(i-1) + 2**(i-1))) になる

pow2 = [1]
for k in range(1, N+1):    
    pow2.append(pow2[-1] * 2 % mod)

# print(pow2)

ans=0
for i in range(1, N+1):
    temp = pow2[N - i] * C[i] * ((0 if i == 1 else (pow2[i - 2] * (i - 1))) + pow2[i - 1]) % mod
    ans = (ans + temp) % mod

ans = ans * pow2[N] % mod

print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*int(pow(2,N-2,mod))%mod
    # print(tmp)
    ans=(ans+tmp)%mod
    # print(j,ans)
ans=ans*int(pow(2,N,mod))%mod

print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*pow(2,N-2,mod)%mod
    # print(tmp)
    ans=(ans+tmp)%mod
    # print(j,ans)
ans=ans*pow(2,N,mod)%mod

print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*pow(2,N-2,mod)%mod
    # print(tmp)
    ans=(ans+tmp)%tmp
    # print(j,ans)
ans=ans*pow(2,N,mod)%mod

print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*pow(2,N-2,mod)%mod
    # print(tmp)
    ans+=tmp
    # print(j,ans)
ans=ans*pow(2,N,mod)%mod

print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
N=int(input())
C=[0]
C.extend(sorted(list(map(int,input().split())),reverse=True)) # 1-indexed

# print(C)

ans=0
for j in range(1,N+1):
    tmp=C[j]*(j+1)*pow(2,N-2,mod)%mod
    # print(tmp)
    ans+=tmp
    # print(j,ans)
ans=ans*pow(2,N,mod)%mod

print(ans)
Problem p03327 (python)

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

Buggy submission (verdict: Runtime Error):
N=int(input())
print(f"ABC{N:03}" if N<=999 else f"ABD{N-999:03}")
Problem p03705 (python)

Fixed submission:
N,A,B=map(int,input().split())
if N==1:
    if A==B:
        ans=1
    else:
        ans=0
else:
    if A>B:
        ans=0
    else:
        ans=(B-A)*(N-2)+1
print(ans)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
if N==1:
    if A==B:
        ans=1
    else:
        ans=0
elif:
    if A>B:
        ans=0
    else:
        ans=(B-A)*(N-2)+1
print(ans)
Problem p02833 (python)

Fixed submission:
N=int(input())

if N%2==1:
    print(0)
else:
    ans=0
    div=10
    while N//div>0:
        ans+=N//div
        div*=5
    print(ans)

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

if N%2==1:
    print(0)
else:
    ans=0
    div=10
    while N//div>0:
        ans+=N//div
        div*=5
print(ans)