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

Fixed submission:
import sys
input = sys.stdin.readline
N, W = list(map(int, input().split()))
WV = [list(map(int, input().split())) for _ in range(N)]

DP = [[float("inf")] * (10**5+1)]
for _ in range(N):
    DP.append([float("inf")] * (10**5+1))

DP[0][0] = 0

for n in range(N):
    for v in range(10 ** 5 + 1):
        if v - WV[n][1] >= 0:
            DP[n+1][v] = min(DP[n+1][v], DP[n][v - WV[n][1]] + WV[n][0])
        DP[n+1][v] = min(DP[n+1][v], DP[n][v])

ans = 0
for v in range(10 ** 5 + 1):
    if DP[N][v] <= W:
        ans = v

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, W = list(map(int, input().split()))
WV = [list(map(int, input().split())) for _ in range(N)]

DP = [0] * (W+1)

for n in range(N):
    next = [0] * (W+1)
    for w in range(1, W+1):
        if w < WV[n][0]:
            next[w] = DP[w]
        else:
            next[w] = max(DP[w], DP[w-WV[n][0]]+WV[n][1])
    DP = next

print(DP[W])
Problem p03263 (python)

Fixed submission:
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]

tmp = 0

ans = []

for j in range(H):
    if j % 2 == 0:
        for i in range(W):
            if j == H-1 and i == W-1:
                break
            if A[j][i] % 2 != 0:
                A[j][i] -= 1
                if i == W-1:
                    A[j+1][i] += 1
                    ans.append([j, i, j+1, i])
                else:
                    A[j][i+1] += 1
                    ans.append([j, i, j, i+1])

    else:
        for i in range(W-1, -1, -1):
            if j == H-1 and i == 0:
                break
            if A[j][i] % 2 != 0:
                A[j][i] -= 1
                if i == 0:
                    A[j+1][i] += 1
                    ans.append([j, i, j+1, i])
                else:
                    A[j][i-1] += 1
                    ans.append([j, i, j, i-1])


print(len(ans))
for a in ans:
    a[0] += 1
    a[1] += 1
    a[2] += 1
    a[3] += 1
    print(*a)

Buggy submission (verdict: Runtime Error):
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]

tmp = 0

ans = []

for j in range(H):
    if j % 2 == 0:
        for i in range(W):
            if j == H-1 and i == W-1:
                break
            if A[j][i] % 2 != 0:
                A[j][i] -= 1
                if i == W-1:
                    A[j+1][i] += 1
                    ans.append([j, i, j+1, i])
                else:
                    A[j][i+1] += 1
                    ans.append([j, i, j, i+1])

    else:
        for i in range(W-1, -1, -1):
            if j == H-1 and i == 0:
                break
            if A[j][i] % 2 != 0:
                A[j][i] -= 1
                if i == W-1:
                    A[j+1][i] += 1
                    ans.append([j, i, j+1, i])
                else:
                    A[j][i-1] += 1
                    ans.append([j, i, j, i-1])


for a in ans:
    print(*a)
Problem p03309 (python)

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

for i, a in enumerate(A):
    A[i] = a - (i+1)

tmp = int(statistics.median(A))

ans = 0
for i, a in enumerate(A):
    ans += abs(a - tmp)

print(ans)

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

for i, a in enumerate(A):
    A[i] = a - (i+1)

tmp = int(statistics.median(A))

ans = 0
for i, a in enumerate(A):
    ans += abs(a - tmp)

print(ans)
Problem p03502 (python)

Fixed submission:
N = input()

s = sum(map(int,list(N)))
if int(N) % s == 0:
  print("Yes")
else:
  print("No")

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

s = sum(map(int,list(N)))
if N % s == 0:
  print("Yes")
else:
  print("No")

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

s = sum(list(N))
if N % s == 0:
  print("Yes")
else:
  print("No")
Problem p03846 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
A.sort()
B = []

ans = 1

if len(A) % 2 == 0:
    for i in range(len(A)//2):
        ans *= 2
        ans %= MOD
        B.append(2 * i + 1)
        B.append(2 * i + 1)

else:
    B.append(0)
    for i in range(len(A)//2):
        ans *= 2
        ans %= MOD
        B.append(2 * i + 2)
        B.append(2 * i + 2)

if A == B:
    print(int(ans))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
A.sort()
B = []

if len(A) % 2 == 0:
    ans = 2 ** (len(A)/2)
    for i in range(len(A)//2):
        B.append(2 * i + 1)
        B.append(2 * i + 1)

else:
    ans = 2 ** (len(A)//2)
    B.append(0)
    for i in range(len(A)//2):
        B.append(2 * i + 2)
        B.append(2 * i + 2)

if A == B:
    print(int(ans/MOD))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
A.sort()
B = []

if len(A) % 2 == 0:
    ans = 2 ** (len(A)/2)
    for i in range(len(A)//2):
        B.append(2 * i + 1)
        B.append(2 * i + 1)

else:
    ans = 2 ** (len(A)//2)
    B.append(0)
    for i in range(len(A)//2):
        B.append(2 * i + 2)
        B.append(2 * i + 2)

if A == B:
    print(int(ans))
else:
    print(0)
Problem p02692 (python)

Fixed submission:
import sys

n,a,b,c = map(int,input().split())
d = {'A':a,'B':b,'C':c}

s = []
for _ in range(n):
	s.append(input())

ans = []
for i in range(n):

	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	else:
		if i < n-1 and s[i+1].strip(s[i]) != '' and d[s[i+1].strip(s[i])] == 0:
			string = s[i+1].strip(s[i+1].strip(s[i]))
			d[string] += 1
			d[s[i].strip(string)] -= 1
			ans.append(s[i+1].strip(s[i+1].strip(s[i])))
		else:
			d[s[i][0]] += 1
			d[s[i][1]] -= 1
			ans.append(s[i][0])
print('Yes')
for i in range(len(ans)):
	print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys

n,a,b,c = map(int,input().split())
d = {'A':a,'B':b,'C':c}

s = []
for _ in range(n):
	s.append(input())

ans = []
for i in range(n):

	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	else:
		if i < n-1 and d[s[i+1].strip(s[i])] == 0:
			d[s[i+1].strip(s[i+1].strip(s[i]))] += 1
			ans.append(s[i+1].strip(s[i+1].strip(s[i])))
		else:
			d[s[i][0]] += 1
			ans.append(s[i][0])
print('Yes')
for i in range(len(ans)):
	print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys

n,a,b,c = map(int,input().split())
d = {'A':a,'B':b,'C':c}

s = []
for _ in range(n):
	s.append(input())

ans = []
for i in range(n):

	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	else:
		if i < n-1 and d[s[i+1].strip(s[i])] == 0:
			d[s[i+1].strip(s[i+1].strip(s[i]))] += 1
			ans.append(s[i+1].strip(s[i+1].strip(s[i])))
print('Yes')
for i in range(len(ans)):
	print(ans[i])
Problem p02783 (python)

Fixed submission:
import math

h,a = map(int,input().split())

print(int(math.ceil(h / a)))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
import math
import sys
readlines = sys.stdin.readline

def main():
  n,d,a = map(int,input().split())
  xx = []
  hh = []
  X = []
  H = []
  for _ in range(n):
    tmp = list(map(int,input().split()))
    xx.append(tmp[0])
    hh.append(tmp[1])

  k = zip(xx,hh)
  q = sorted(k)
  for xxx,hhh in q:
    X.append(xxx)
    H.append(hhh)
  X = tuple(X)
  ans = 0
  end = n-1
  while True:
    x = X[end] - d
    start = bisect_left(X,x-d)
    num = math.ceil(H[end] / a)
    ans += num
    H[end] = 0
    e = end
    end = start-1
    for i in range(start,e):
      H[i] -= a * num
      if H[i] > 0:
        end = i
    if end < 0:
      break

  print(ans)
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def dp_all(dp):
  length = len(dp)
  for i in range(length):
    print(dp[i])

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

a = []
b = []

for i in range(N):
  a_dash,b_dash = map(int,input().split())
  a.append(a_dash)
  b.append(b_dash)

#dp[i+1][j] = i番目までの魔法で体力jのモンスターに
#勝つことができる、魔力の最小値
INF = 10**9
dp = [[INF for _ in range(H+1)] for _ in range(N+1)]

for i in range(N+1):
  dp[i][0] = 0

for i in range(N):
  for j in range(H+1):
    if a[i] > j:
      dp[i+1][j] = min(dp[i][j],b[i])
    else:
      dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+ b[i])

print(dp[N][H])
Problem p02823 (python)

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

if (b-a) % 2 == 0:
	ans = (b-a) // 2
else:
	if a-1 < n-b:
		ans = b-1
		x = b-(a-1)-1
		ans = min(ans, a + (x-1) // 2)
	else:
		ans = n-a
		x = a + (n-b) + 1
		ans = min(ans, (n-b) + 1 + (n-x) // 2)

print(ans)

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

if (b-a) % 2 == 0:
	print((b-a) // 2)
else:
	if a-1 < n-b:
		ans = b-1
		x = b-(a-1)-1
		ans = min(ans, a + (x-1) // 2)
	else:
		ans = n-a
		x = a + (n-b) + 1
		ans = min(ans, (n-b) + 1 + (n-x) // 2)

print(ans)
Problem p02843 (python)

Fixed submission:
import sys

x = input()
X = int(x)

if X < 100:
	print(0)
	sys.exit()
elif X >= 100 and X <= 105:
	print(1)
	sys.exit()
elif X % 105 == 0:
	print(1)
	sys.exit()

x1 = int(x[:-2])
x2 = int(x[-2:])

c = int(x2 // 5) + 1

if x1 >= c:
	print(1)
else:
	print(0)

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

x1 = int(x[:-2])
x2 = int(x[-2:])

c = int(x2 // 5) + 1

if x1 >= c:
	print(1)
else:
	print(0)
Problem p02913 (python)

Fixed submission:
n = int(input())
s = input()

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
        	j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
ans = 0
for i in range(n-1):
	tmp = z_algo(s[i:])
	for j,zj in enumerate(tmp):
		if j+1 > zj:
			ans = max(ans,zj)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys #追加

n = int(input())
s = input()

sys.setrecursionlimit(n) #追加

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j] and i != j:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        if A[i] >= N - i - 1:
        	return A[i]
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return 0

ans = 0
for i in range(n-1):
	res = z_algo(s[i:])
	ans = max(ans, res)

print(ans)
Problem p02921 (python)

Fixed submission:
s = input()
t = input()

ans = 0

for i in range(3):
	if s[i] == t[i]:
		ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

n = int(input())
a = []
for _ in range(n):
	a.append(tuple(map(int,input().split())))
a = tuple(a)

play = [0 for _ in range(n)]
flag = [True for _ in range(n)]
count = 0
ans = 0
while True:
	break_flag = True
	for i in range(n):
		if flag[i]:
			num = a[i][play[i]]-1
			if flag[num] and a[num][play[num]]-1 == i:
				play[num] += 1
				play[i] += 1
				flag[num] = False
				flag[i] = False
				break_flag = False
				count += 1
	if break_flag:
		print(-1)
		sys.exit()
		break
	ans += 1
	if count == n*(n-1)//2:
		break
	for i in range(n):
		if play[i] < n-1:
			flag[i] = True
		else:
			flag[i] = False

if ans == 0:
	print(-1)
else:
	print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7) #追加

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

counter = [0 for _ in range(n)]
E = [[] for _ in range(n)]

#辺の定義
#辺E(u,v)の重みがw
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[b].append(a)
  E[a].append(b)

for i in range(q):
	p,x = map(int,input().split())
	counter[p-1] += x

res = 0
#行ったかどうか
color = [-1 for _ in range(n)]

#dfsで色を塗っていく
stack = [0]
color[0] = counter[0]
while stack:
  u = stack.pop()
  for v in E[u]:
    if color[v] == -1:
      stack.append(v)
      color[v] = color[u] + counter[v]

ans = [str(color[i]) for i in range(n)]
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())

class Node(object):
	def __init__(self, num):
		self.num = num #各ノードの数字0〜9
		self.children = []
		self.c = 0
	#heapq.heapify()する際に必要となる比較関数
	def __lt__(self, x):
		return self.value < x.value
	#子どもをセットする
	def setChildren(self, x):
		self.children.append(x)
	def solve(self,x):
		self.c += x
		for child in self.children:
			table[child].solve(x)


table = [Node(i+1) for i in range(n)]
counter = [0 for _ in range(n)]

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

for i in range(q):
	p,x = map(int,input().split())
	counter[p-1] += x

for i in range(n):
	if counter[i] != 0:
		table[i].solve(counter[i])

ans = [str(table[i].c) for i in range(n)]
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
import sys

def search(a,b,c,no,num):
	c[no-1] += num
	for k in range(len(a)):
		if a[k] == no:
			search(a,b,c,b[k],num)

n,q = map(int,input().split())
a = []
b = []
c = [0,0,0,0]

for i in range(n-1):
	a_dash, b_dash = map(int,input().split())
	a.append(a_dash)
	b.append(b_dash)
	#c.append(0)

for i in range(q):
	no,num = map(int,input().split())
	search(a,b,c,no,num)

for i in range(len(c)):
	sys.stdout.write(str(c[i]))
	sys.stdout.write(" ")
Problem p02981 (python)

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

print(min(b,a*n))

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

def p(n, r):
	if n < r:
		return 1
	return math.factorial(n) // math.factorial(n - r)

def main():
	input = sys.stdin.readline
	N,K = map(int,input().split())
	E = [[] for _ in range(N)]
	MOD = 10**9+7
	#辺の定義
	for _ in range(N-1):
	  u,v = map(int,input().split())
	  u -= 1
	  v -= 1
	  E[u].append(v)
	  E[v].append(u)

	if N == 1:
		print(K)
		sys.exit()
	#colorが塗られたかどうか
	color = [-1 for _ in range(N)]
	dp = [-1 for _ in range(N)]
	#dfsで色を塗っていく
	stack = []
	color[u] = 1
	ans = K
	for i,v in enumerate(E[u]):
		stack.append(v)
		ans *= (K-i-1)
		ans %= MOD

	while stack:
		u = stack.pop()
		color[u] = 1
		length = 0
		for v in E[u]:
			if color[v] == -1:
				stack.append(v)
				length += 1
		if dp[length] == -1:
			tmp = 1
			for i in range(K-1-length,K-1):
				tmp *= i
				tmp %= MOD
			#tmp = p(K-2,length) % MOD
			ans *= tmp
			dp[length] = tmp
		else:
			ans *= dp[length]
		ans %= MOD

	#各頂点の色を出力
	print(ans%MOD)

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

Fixed submission:
l,r = map(int,input().split())
n = r - l + 1
if n >= 2019:
	print(0)
else:
	l_to_r = []
	for i in range(l,r+1):
		l_to_r.append(i % 2019)
	ans = []
	for i in range(n-1):
		for j in range(i+1,n):
			ans.append(l_to_r[i] * l_to_r[j] % 2019)
	print(min(ans))

Buggy submission (verdict: Runtime Error):
l,r = map(int,input().split())

if r-l >= 2018:
  print(0)
else:
  ans = 2019
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans = min(ans,(i*j)%2019)

print(ans)
Problem p02985 (python)

Fixed submission:
import math
import sys

def p(n, r):
	if n < r:
		return 1
	return math.factorial(n) // math.factorial(n - r)

def main():
	input = sys.stdin.readline
	N,K = map(int,input().split())
	E = [[] for _ in range(N)]
	MOD = 10**9+7
	#辺の定義
	for _ in range(N-1):
	  u,v = map(int,input().split())
	  u -= 1
	  v -= 1
	  E[u].append(v)
	  E[v].append(u)

	if N == 1:
		print(K)
		sys.exit()
	#colorが塗られたかどうか
	color = [-1 for _ in range(N)]
	dp = [-1 for _ in range(N)]
	#dfsで色を塗っていく
	stack = []
	color[u] = 1
	ans = K
	for i,v in enumerate(E[u]):
		stack.append(v)
		ans *= (K-i-1)
		ans %= MOD

	while stack:
		u = stack.pop()
		color[u] = 1
		length = 0
		for v in E[u]:
			if color[v] == -1:
				stack.append(v)
				length += 1
		if dp[length] == -1:
			tmp = 1
			for i in range(K-1-length,K-1):
				tmp *= i
				tmp %= MOD
			#tmp = p(K-2,length) % MOD
			ans *= tmp
			dp[length] = tmp
		else:
			ans *= dp[length]
		ans %= MOD

	#各頂点の色を出力
	print(ans%MOD)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import math

def p(n, r):
	if n < r:
		return 1
	return math.factorial(n) // math.factorial(n - r)

N,K = map(int,input().split())
E = [[] for _ in range(N)]
MOD = 10**9+7
#辺の定義
#辺E(u,v)の重みがw
for _ in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  E[u].append(v)
  E[v].append(u)

#colorが塗られたかどうか
color = [-1 for _ in range(N)]

#dfsで色を塗っていく
stack = []
color[u] = 1
ans = K
for i,v in enumerate(E[u]):
	stack.append(v)
	ans *= (K-i-1)
	ans %= MOD

while stack:
	u = stack.pop()
	color[u] = 1
	length = len(E[u])
	for v in E[u]:
		if color[v] == -1:
			stack.append(v)
		else:
			length -= 1
	ans *= p(K-2,length) % MOD
	ans %= MOD

#各頂点の色を出力
print(ans%MOD)
Problem p02996 (python)

Fixed submission:
import heapq
import copy
import bisect
from collections import deque

n = int(input())
a = []
b = []
tmp_a = []
tmp_b = []
flag = True

for _ in range(n):
	a_dash,b_dash = map(int,input().split())
	tmp_a.append(a_dash)
	tmp_b.append(b_dash)

k = zip(tmp_b,tmp_a)
sorted_k = sorted(k)
for b_dash,a_dash in sorted_k:
	a.append(a_dash)
	b.append(b_dash)

t = 0
qa = deque(a)
qb = deque(b)

for i in range(n):
	minimum_a = qa.popleft()
	minimum_b = qb.popleft()
	t += minimum_a
	if t > minimum_b:
		flag = False
		break

if flag:
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
import heapq
import copy
import bisect

n = int(input())
a = []
b = []
flag = True

for _ in range(n):
	a_dash,b_dash = map(int,input().split())
	a.append(a_dash)
	b.append(b_dash)

t = 0
a2 = copy.deepcopy(a)
b2 = copy.deepcopy(b)
heapq.heapify(b2)

for i in range(n):
	minimum = heapq.heappop(b2)
	index = bisect.bisect_left(b,minimum)
	for _ in range(n):
		if a2[index] == -1:
			index += 1
		else:
			break
	a2[index] = -1
	t += a[index]
	if t > minimum:
		flag = False
		break

if flag:
	print('Yes')
else:
	print('No')
Problem p03032 (python)

Fixed submission:
from collections import deque
import heapq

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


#a : heapq.heappop(s,v.popleft())
#b : heapq.heappop(s,v.pop())
#c : v.appendleft(heapq.heappop(s))
#d : v.append(heapq.heappop(s))
ans = 0
for i in range(1,min(n,k)+1):
    for j in range(i+1):
        s = []
        heapq.heapify(s)
        res = 0
        num = 0
        for _ in range(j):
            heapq.heappush(s,v[num])
            res += v[num]
            num += 1
        num = 1
        for _ in range(j,i):
            heapq.heappush(s,v[-num])
            res += v[-num]
            num += 1

        for j in range(k-i):
            if len(s) == 0:
                break
            if s[0] < 0:
                res -= heapq.heappop(s)
            else:
                break
        if ans < res:
            ans = res
    #print(i,ans)
print(ans)

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

n,K = map(int,input().split())
v = list(map(int,input().split()))

ans = 0
sum_d = 0
d = []
heapify(d)
# i = 操作回数
# j = 取る回数 (i-j = 捨てる回数)
# k = 左から取る回数 (j-k = 右から取る回数)
for i in range(1,K+1):
	for j in range(math.ceil(i/2),i+1):
		for k in range(j+1):
			#print(i,j,k,j-k,i-j,ans)
			# 左から取る
			for l in range(k):
				heappush(d,v[l])
				sum_d += v[l]
			# 右から取る
			for l in range(j-k):
				heappush(d,v[-l-1])
				sum_d += v[-l-1]
			for l in range(i-j):
				sum_d -= heappop(d)
			ans = max(sum_d,ans)
			sum_d = 0
			d = []
			heapify(d)
print(ans)
Problem p03035 (python)

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

if a <= 5:
    print(0)
elif a > 5 and a <= 12:
    print(b // 2)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
	bc.append(list(map(int,input().split())))

a.sort()
bc = sorted(bc, key=lambda x:x[1])

l = [0 for _ in range(n+1)]
for i in range(1,n+1):
	l[i] = a[i-1]
for i in range(n):
	l[i+1] += l[i]

ans = l[-1]
num = 0
while True:
	if len(bc) == 0:
		break
	tmp = bc.pop()
	b = tmp[0]
	c = tmp[1]
	index = bisect_left(a,c)

	if index == 0:
		break
	if b >= index:
		ans -= l[index+num] - l[num]
		ans += index * c
		break
	else:
		ans -= l[b]
		ans += b * c
		a = a[b:]
		num += b

print(ans)
Problem p03074 (python)

Fixed submission:
import sys

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

zero = []
one = []
string = s[0]
if string == '0':
	flag = True
else:
	flag = False
count = 0
left = 0
right = 0
num = 0
for i in range(n):
	if s[i] == string:
		count += 1
	else:
		if string == '0':
			num = count
			string = '1'
		else:
			one.append(count)
			if num != 0:
				zero.append([num,left,count])
			string = '0'
			left = count
			num = 1
		count = 1

if string == '0':
	zero.append([count,left,0])
else:
	zero.append([num,left,count])
	one.append(count)
#print(zero)
#print(one)
if len(zero) <= k:
	print(len(s))
	sys.exit()
res = 0
for i in range(k):
	res += zero[i][0] + zero[i][1]
res += zero[i][2]
#print(res)
ans = res
for i in range(len(zero)-k):
	res -= zero[i][0] + zero[i][1]
	#print(res)
	res += zero[i+k][0] + zero[i+k][2]
	#print(res)
	ans = max(ans,res)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()

zero = []
one = []
string = s[0]
if string == '0':
	flag = True
else:
	flag = False
count = 0
left = 0
right = 0
num = 0
for i in range(n):
	if s[i] == string:
		count += 1
	else:
		if string == '0':
			num = count
			string = '1'
		else:
			one.append(count)
			if num != 0:
				zero.append([num,left,count])
			string = '0'
			left = count
			num = 1
		count = 1

if string == '0':
	zero.append([num,left,0])
else:
	zero.append([num,left,count])
	one.append(count)
#print(zero)
#print(one)

res = 0
for i in range(k):
	res += zero[i][0] + zero[i][1]
res += zero[i][2]
#print(res)
ans = res
for i in range(len(zero)-k):
	res -= zero[i][0] + zero[i][1]
	#print(res)
	res += zero[i+k][0] + zero[i+k][2]
	#print(res)
	ans = max(ans,res)
print(ans)
Problem p03085 (python)

Fixed submission:
b = input()

if b == 'A':
  print('T')
elif b == 'C':
  print('G')
elif b == 'G':
  print('C')
else:
  print('A')

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

if b == 'A':
  print('A')
elif b == 'C':
  print('T')
elif b == 'G':
  print('C')
else:
  print(G)
Problem p02675 (python)

Fixed submission:
n = int(input())
n %= 10
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    print('hon')
elif n == 0 or n == 1 or n == 6 or n == 8:
    print('pon')
else:
    print('bon')

Buggy submission (verdict: Runtime Error):
n = int(input())
n %= 10
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    print('hon')
elif n == 0 or n == 1 or n == 6 or n == 8:
    print('pon')
else:
    print('bon')2