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

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

def DFS(G, A, use, Wlist, visit, jud, node):
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, A, use, Wlist, visit, jud, i)
			Wlist[node].append(use[i])

	#抜けの処理
	if Wlist[node] == []:
		use[node] = A[node]
	else:
		Z = sum(Wlist[node])
		if max(max(Wlist[node]), (Z + 1) // 2) <= A[node] and A[node] <= Z:
			use[node] = 2 * A[node] - Z
		else:
			use[node] = 2 * A[node] - Z
			jud[node] = "NO"

#処理内容
def main():
	N = int(input())
	A = getlist()
	G = Graph()
	for i in range(N - 1):
		a, b = getlist()
		a -= 1; b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)

	#面倒なケース
	if N == 2:
		if A[0] == A[1]:
			print("YES")
			return
		else:
			print("NO")
			return

	s = None
	for i in range(N):
		if len(G.graph[i]) >= 2:
			s = i
			break
	#DFS
	judge = "YES"
	use = [None] * N
	jud = ["YES"] * N
	Wlist = [[] for i in range(N)]
	visit = ["No"] * N
	visit[s] = "Yes"
	DFS(G, A, use, Wlist, visit, jud, s)
	# print(use)

	for i in range(N):
		if jud[i] == "NO":
			judge = "NO"

	if use[s] != 0:
		judge = "NO"
	#答え
	print(judge)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#部分木 大きさ
import sys
sys.setrecursionlimit(10**7)

from collections import defaultdict

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

def DFS(G, A, use, Wlist, visit, node):
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, A, use, Wlist, visit, i)
			Wlist[node].append(use[i])

	#抜けの処理
	if Wlist[node] == []:
		use[node] = A[node]
	else:
		Z = sum(Wlist[node])
		if max(max(Wlist[node]), (Z + 1) // 2) <= A[node] and A[node] <= Z:
			use[node] = 2 * A[node] - Z
		else:
			judge = "NO"

#処理内容
def main():
	N = int(input())
	A = getlist()
	G = Graph()
	for i in range(N - 1):
		a, b = getlist()
		a -= 1; b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)

	s = None
	for i in range(N):
		if len(G.graph[i]) >= 2:
			s = i
			break

	#DFS
	judge = "YES"
	use = [None] * N
	Wlist = [[] for i in range(N)]
	visit = ["No"] * N
	visit[s] = "Yes"
	DFS(G, A, use, Wlist, visit, s)
	# print(use)

	if use[s] != 0:
		judge = "NO"
	#答え
	print(judge)


if __name__ == '__main__':
	main()
Problem p03835 (python)

Fixed submission:
K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = (-3 * (K ** 2) + 3 * K + 6 * S * K - 2 * (S ** 2) + 2) // 2
	print(int(ans))
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2) / 2))

Buggy submission (verdict: Runtime Error):
K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = int((S - K + 1) * (2 * K - S) * (S - K) (S - K + 1) / 2)
	print(ans)
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2) / 2))

Buggy submission (verdict: Runtime Error):
K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = (S - K + 1) * (2 * K - S) * int((S - K) (S - K + 1) / 2)
	print(ans)
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2) / 2))

Buggy submission (verdict: Runtime Error):
K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = (S - K + 1) * (2 * K - S) * int((S - K) (S - K + 1) / 2)
	print(ans)
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2)) / 2)
Problem p04005 (python)

Fixed submission:
A, B, C = list(map(int, input().split()))
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
	print(0)
else:
	ABC = sorted([A, B, C])
	print(ABC[0] * ABC[1])

Buggy submission (verdict: Runtime Error):
A, B, C = list(map(int, input().split()))
if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
	print(0)
else:
	ABC = sort([A, B, C])
	print(ABC[0] * ABC[1])
Problem p03013 (python)

Fixed submission:
N,M=map(int,input().split())
A = [0]*(N+1)

for _ in range(M):
  a = int(input())
  A[a] = 1

#初期化
dp=[0]*(N+1)
dp[0] = 1
if A[1] == 0:
  dp[1] = 1

#dp
for i in range(2,N+1):
  if A[i] == 0:
    dp[i] = dp[i-1] + dp[i-2]
      
print(dp[N]%1000000007)

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

if M != 0:
  for _ in range(M):
    A.append(int(input()))

#初期化
dp=[0]*N
if A.count(1) == 0:
  dp[0]=1
if A.count(1) == 0 and A.count(2) == 0:
  dp[1]=2
elif A.count(1) ==1 and A.count(2) ==0:
  dp[1]=1

#dp
if N >= 3:
  for i in range(N-2):
    if A.count(i+3) ==1:
      dp[i+2] = 0
    elif A.count(i+1) == 0 and A.count(i+2) == 0:
      dp[i+2] = dp[i+1] + dp[i]
    elif A.count(i+1) == 0 and A.count(i+2) == 1:
      dp[i+2] = dp[i]
    elif A.count(i+1) == 1 and A.count(i+2) == 0:
      dp[i+2] = dp[i+1]
    else:
      dp[i+2] = 0
      
print(dp[N-1]%1000000007)

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

for _ in range(M):
  A.append(int(input())-1)

#初期化
dp=[0]*N
if A.count(0) == 0:
  dp[0]=1
if A.count(0) == 0 and A.count(1) == 0:
  dp[1]=2
elif A.count(0) ==1 and A.count(1) ==0:
  dp[1]=1

#dp
if N >= 3:
  for i in range(N-2):
    if A.count(i+2) ==1:
      dp[i+2] = 0
    elif A.count(i) == 0 and A.count(i+1) == 0:
      dp[i+2] = dp[i+1] + dp[i]
    elif A.count(i) == 0 and A.count(i+1) == 1:
      dp[i+2] = dp[i]
    elif A.count(i) == 1 and A.count(i+1) == 0:
      dp[i+2] = dp[i+1]
    else:
      dp[i+2] = 0
      
print(dp[N-1]%1000000007)
Problem p02570 (python)

Fixed submission:
def main():
    d, t, s = map(int, input().split())  
    print('Yes' if s * t >= d else 'No')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def generate_primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def main():  
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    primes = generate_primes(max(A))
    for a in A:
        for p in primes:
            if a < p: break
            if a % p == 0:
                d[p] += 1
    d[1] = 0
    m = max(d.values())
    if m == n:
        print('not coprime')
    elif m >= 2:
        print('setwise coprime')
    else:
        print('pairwise coprime')
    

if __name__ == '__main__':
    main()
Problem p02771 (python)

Fixed submission:
a = list(map(int, input().split()))
if len(set(a)) == 2:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split()))
if len(set(a, b, c)) == 2:
    print('Yes')
else:
    print('No')
Problem p03017 (python)

Fixed submission:
def main():
    n, a, b, c, d = list(map(lambda x: int(x) - 1, input().split()))
    n += 1
    s = list(input())
    s = s[a:max(c, d) + 1]
    for i in range(len(s) - 1):
        if s[i] == '#' and s[i + 1] == '#':
            print('No')
            exit()
    if c < d:
        print('Yes')
    else:
        ch = False
        for i in range(b, d + 1):
            if s[i - 1] == s[i] == s[i + 1] == '.':
                ch = True
        if ch:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, a, b, c, d = list(map(lambda x: int(x) - 1, input().split()))
    n += 1
    s = list(input())
    s = s[a:d + 1]
    for i in range(len(s) - 1):
        if s[i] == '#' and s[i + 1] == '#':
            print('No')
            exit()
    if c < d:
        print('Yes')
    else:
        ch = False
        for i in range(b, d + 1):
            if s[i - 1] == s[i] == s[i + 1] == '.':
                ch = True
        if ch:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()
Problem p03053 (python)

Fixed submission:
from collections import deque
def main():
    h, w = map(int, input().split())
    A = [list(input()) for _ in range(h)]
    B = [(i, j) for i, a in enumerate(A) for j, b in enumerate(a) if b == '#']
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    stack = deque(B)
    colored = len(B)
    tot = h * w
    count = 0
    while colored < tot:
        next = deque([])
        while stack:
            y, x = stack.popleft()
            for dx, dy in dxy:
                X = x + dx
                Y = y + dy
                if X < 0 or X >= w or Y < 0 or Y >= h:
                    continue
                if A[Y][X] == '.':
                    next.append((Y, X))
                    A[Y][X] = '#'
        stack = next
        count += 1
        colored += len(next)
    print(count)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
def main():
    h, w = map(int, input().split())
    A = [list(input()) for _ in range(h)]
    B = [(i, j) for i, a in enumerate(A) for j, b in enumerate(a) if b == '#']
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    stack = deque(B)
    colored = len(B)
    tot = h * w
    count = 0
    while colored < tot:
        next = deque([])
        while stack:
            y, x = stack.popleft()
            for dx, dy in dxy:
                X = x + dx
                Y = y + dy
                if X < 0 or X >= w or Y < 0 or Y >= h:
                    continue
                if A[X][Y] == '.':
                    next.append((X, Y))
                    A[X][Y] = '#'
        stack = next
        count += 1
        colored += len(next)
    print(count)

if __name__ == '__main__':
    main()
Problem p03803 (python)

Fixed submission:
a = list(map(int, input().split()))
a = [i if i != 1 else 14 for i in a]
if a[0] > a[1]:
    print('Alice')
elif a[0] == a[1]:
    print('Draw')
else:
    print('Bob')

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a = [i for i in a if i != 1 else 14]
if a[0] > a[1]:
    print('Alice')
elif a[0] == a[1]:
    print('Draw')
else:
    print('Bob')
Problem p03127 (python)

Fixed submission:
from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]

for i in range(N-1):
    A[-1]=gcd(A[-1],A[i])
print(A[-1])

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

for i in range(N-1):
    A[-1]=gcd(A[-1],A[i])
print(A[-1])
Problem p02897 (python)

Fixed submission:
N = int(input())
if N % 2 == 0:
    print(0.5)
else:
    print((N + 1)/2 / N)

Buggy submission (verdict: Runtime Error):
N = int(input())
# if N % 2 == 0:
#     print(0.5)
# else:
#     print((N + 1)/2 / N)

cnt = 0
for i in range(1, N+1):
    if i % 2 == 1:
        cnt += 1
print(cnt/n)
Problem p03250 (python)

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

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

def p(n,r):
    return int(math.factorial(n)/math.factorial(n-r))
def c(n,r):
    return int(p(n,r)/math.factorial(r))

n, m = map(int, input().split())
dic = sympy.factorint(m)
print(dic)
ans = [c(i+n-1,i) % (10**9+7) for i in dic.values()]
print(np.prod(ans) % (10**9+7))
Problem p02688 (python)

Fixed submission:
n, k = map(int, input().split())

mans = [0]*n
for i in range(k):
    d = input()
    a = list(map(int, input().split()))
    for aa in a:
        mans[aa-1] += 1

cnt = 0
for m in range(len(mans)):
    if mans[m] == 0:
        cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
import os
f = open('input.txt', 'r')
sys.stdin = f

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

mans = [0]*n
for i in range(k):
    d = input()
    a = list(map(int, input().split()))
    for aa in a:
        mans[aa-1] += 1

cnt = 0
for m in range(len(mans)):
    if mans[m] == 0:
        cnt += 1

print(cnt)
Problem p02707 (python)

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

out = [0]*n

for aa in a:
  out[aa-1] += 1

for i in range(len(out)):
  print(out[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input()))

out = [0]*n

for aa in a:
  out[a] += 1

for o in range(len(out)):
  print(o)
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())

if a+b == 3:
  print(3)
elif a+b == 4:
  print(2)
else:
  print(1)

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

if a+b == 3:
  print(3)
elif a+b == 4:
  print(2)
else:
  print(1)
Problem p02879 (python)

Fixed submission:
a,b = map(int, input().split())
if a <= 9 and b <= 9:
  print(a*b)
else:
  print(-1)

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

def xx(y):
  aHeight = a*math.sin(y)
  bHeight = b*math.sin(0.5*math.pi-y)
  if aHeight < bHeight:
    menseki = 0.5*a*b + (bHeight/aHeight*a-b)*math.sin(0.5*math.pi-y)*(a/math.cos(y))
  else:
    aD = bHeight/math.sin(y)
    menseki = 0.5*aD*b
  return menseki

minY = 0
maxY = 0.5*math.pi
while True:
  menseki = xx((minY+maxY)/2)
  if abs(x/a - menseki) < 0.1:
    print((minY+maxY)/2 * (180/math.pi))
    break
  elif menseki < x/a:
    maxY = (minY+maxY)/2
  else:
    minY = (minY+maxY)/2

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
sqN = int(math.sqrt(N))
for i in range(sqN):
  if N % (sqN-i) == 0:
    print(int(N/(sqN-i)+sqN-i))
    break
Problem p02912 (python)

Fixed submission:
import math
import bisect

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)

def XX(A, M):
  if M <= 0 or A[0]<1:
    return
  A[0] = A[0]/2
  M -= 1
  for i in range(1, len(A)):
    if A[i] > A[0] and M > 0:
      A[i] = A[i]/2
      M -= 1
    else:
      break
  A.sort(reverse = True)
  XX(A, M)
  
XX(A, M)
A = list(map(math.floor, A))
print(sum(A))

Buggy submission (verdict: Runtime Error):
import math
import bisect

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)

def XX(A, M):
  if M <= 0:
    return
  A[0] = A[0]/2
  M -= 1
  for i in range(1, len(A)):
    if A[i] > A[0] and M > 0:
      A[i] = A[i]/2
      M -= 1
    else:
      break
  A.sort(reverse = True)
  XX(A, M)
  
XX(A, M)
A = list(map(math.floor, A))
print(sum(A))

Buggy submission (verdict: Runtime Error):
import math
import bisect

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)

def XX(A, M):
  if M <= 0:
    return
  A[0] = A[0]/2
  M -= 1
  for i in range(1, len(A)):
    if A[i] > A[0] and M > 0:
      A[i] = A[i]/2
      M -= 1
    else:
      break
  A.sort(reverse = True)
  XX(A, M)
  
A = list(map(math.floor, A))
XX(A, M)
print(sum(A))

Buggy submission (verdict: Runtime Error):
A = list(map(math.floor, A))
Problem p02948 (python)

Fixed submission:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

def aa(sh, idx, M, x, ans):
  if idx >= M:
    return sh, ans, x
  elif sh[idx] == 0:
    sh[idx] = idx+1
    sh[x["d"]] = idx+1
    ans += x["m"]
    return sh, ans, x
  else:
    zz = idx
    sh, ans, x = aa(sh, sh[idx], M, x, ans)
    sh[zz] = sh[x["d"]]
    return sh, ans, x
  
sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  sh, ans, x = aa(sh, idx, M, x, ans)
print(ans)

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

def aa(sh, idx, M, x, ans):
  if idx >= M:
    return sh, ans, x
  elif sh[idx] == 0:
    sh[idx] = idx+1
    sh[x["d"]] = idx+1
    ans += x["m"]
    return sh, ans, x
  else:
    sh, ans, x = aa(sh, sh[idx], M, x, ans)
    sh[idx] = sh[x["d"]]
    return sh, ans, x
  
sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  sh, ans, x = aa(sh, idx, M, x, ans)
print(ans)

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

def aa(sh, idx, M, x, ans):
  if idx >= M:
    return sh, ans, x
  elif sh[idx] == 0:
    sh[idx] = idx+1
    sh[x["d"]] = idx+1
    ans += x["m"]
    return sh, ans, x
  else:
    sh, ans, x = aa(sh, sh[idx], M, x, ans)
    sh[idx] = sh[x["d"]]
    idx = sh[idx]
    return sh, ans, x
  
sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  sh, ans, x = aa(sh, idx, M, x, ans)
print(ans)
Problem p02577 (python)

Fixed submission:
def ans(n): 

    aa = 0
    for i in n:
        aa+=int(i)
    return True if aa%9==0 else False
        
  
n = input()

print('Yes' if ans(n) else 'No')

Buggy submission (verdict: Runtime Error):
def ans(n): 
    if (n == 0 or n == 9): 
        return True
    if (n < 9): 
        return False
  
    return ans((int)(n>>3) - (int)(n&7)) 
  
n = input()
print('Yes' if ans(int(n)) else 'No')
Problem p02831 (python)

Fixed submission:
a, b = map(int, input().split())
if a<b: a,b=b,a
c = a*b
while b: a, b = b, a%b
print(c//a)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a<b: a,b=b,a
c = a*b
while b:
    a, b = b, a//b
print(c//b)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a<b: a,b=b,a
c = a*b
while a%b:
    a, b = b, a//b
print(c//b)
Problem p02881 (python)

Fixed submission:
n = int(input())
l = int(n**0.5)
while l:
    if n%l: l-=1
    else: break
print((l-1)+(n//l-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
x, y = 0, 0
for i in range(1, int(n**0.5)):
        if n%i==0: x = i
y = n//x
print(x+y-2)
Problem p03038 (python)

Fixed submission:
from heapq import heappop, heappush

n, m = map(int, input().split())
a = []
for i in map(int, input().split()): heappush(a, i)

ans = []
for b, c in sorted([list(map(int, input().split()))for i in range(m)], key=lambda x:-x[1]):
        for i in range(b):
                if len(a)==0: break
                ans.append(max(c,  heappop(a)))
while len(a): ans.append(heappop(a))
print(sum(ans))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush

n, m = map(int, input().split())
a = []
for i in map(int, input().split()): heappush(a, i)

ans = []
for b, c in sorted([list(map(int, input().split()))for i in range(m)], key=lambda x:-x[1]):
        if len(a)==0: break
        for i in range(b): ans.append(max(c,  heappop(a)))
while len(a): ans.append(heappop(a))
print(sum(ans))
Problem p03209 (python)

Fixed submission:

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

#     1 2 3 4 5 6 7 8 9 0 1 2 3 4
# L0:     p   p       p   p
# L1:   b   p   b   b   p   b
# L2: b           p           b

def rec(n, x):

    if n==0: return 1  # レベル0ではpが１つ
    if x==1: return 0  

    all = (1<<(n+1)) - 3  # 1つ低レベルの総数
    p = (1<<(n)) - 1  # 1つ低レベルのパティ数
    
    # 今レベルは b + rec(n-1) + p + rec(n-1) + b
    if x <= all + 1: return rec(n-1, x-1)  #  低レベル + 1の大きさであれば今レベルから採るpはなし
    if x == all + 2: return p + 1  # 低レベル + 2の大きさであれば、低レベルのp数 + 今レベルの中間のp１つ
    if x <= all * 2 + 2: return p + 1 + rec(n-1, x-all-2)  # 上2つを通過しているので少なくとも低レベル1つと中間のpは食べている. 後は低レベル２つ目のp数に帰着
    if x == all * 2 + 3: return p * 2 + 1  # 低レベル2つまるごと + 中間のp
    return -1000000

print(rec(N, X))

Buggy submission (verdict: Runtime Error):

N = int(input())
X = int(input())

#     1 2 3 4 5 6 7 8 9 0 1 2 3 4
# L0:     p   p       p   p
# L1:   b   p   b   b   p   b
# L2: b           p           b

def rec(n, x):

    if n==0: return 1  # レベル0ではpが１つ
    if x==1: return 0  

    all = (1<<(n+1)) - 3  # 1つ低レベルの総数
    p = (1<<(n)) - 1  # 1つ低レベルのパティ数
    
    # 今レベルは b + rec(n-1) + p + rec(n-1) + b
    if x <= all + 1: return rec(n-1, x-1)  #  低レベル + 1の大きさであれば今レベルから採るpはなし
    if x == all + 2: return p + 1  # 低レベル + 2の大きさであれば、低レベルのp数 + 今レベルの中間のp１つ
    if x <= all * 2 + 2: return p + 1 + rec(n-1, x-all-2)  # 上2つを通過しているので少なくとも低レベル1つと中間のpは食べている. 後は低レベル２つ目のp数に帰着
    if x == all * 2 + 3: return p * 2 + 1  # 低レベル2つまるごと + 中間のp
    return -1000000

print(rec(N, X))
Problem p03834 (python)

Fixed submission:
s = input()
print(s.replace(",", " "))

Buggy submission (verdict: Runtime Error):
k, s = [int(x) for x in input().split()]
k += 1

count = 0

for x in range(k):
    for y in range(k):
        for z in range(k):
            if x + y + z == s:
                count += 1

print(count)
Problem p02629 (python)

Fixed submission:
N = int(input())
c = 0
P = [N]

alph = {}
p = 1
for i in range(97, 97+26):
    alph[str(p%26)] = chr(i)
    p += 1

ans = []
k = 0
T = N
while(N > 0):
    if k == 0:
        ans.append(alph[str((N // (26**k))%26)])
    else:
        ans.append(alph[str(((N-1)//(26**k)+1)%26)])
    k += 1
    N -= 26**k
print("".join(ans[::-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
T = N
k = 26
c = 0
while(T - k > 0):
    T -= k
    k *= 26
    c += 1

alph = {}
p = 1
for i in range(97, 97+26):
    alph[str(p%26)] = chr(i)
    p += 1
ans = ""
for i in range(c, -1, -1):
    t = N // (26**i)
    ans += alph[str(t)]
    N -= t*(26**i)
print("".join(ans))
Problem p02832 (python)

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

if 1 in A:
    num = 1
    c = 0
    d = len(A)
    for i in range(N):
        if A[i] == num:
            num += 1
            c += 1 
    print(d - c)
else:
    print(-1)

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

if i in A:
    num = 1
    c = len(A)
    while(len(A) > num):
        if A[num-1] == num:
            num += 1
        else:
            del A[num-1]
    print(c - len(A))
else:
    print(-1)