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

Fixed submission:
x, y, z = map(int, input().split())

print ( str(z) + " " + str(x) + " " + str(y) )

Buggy submission (verdict: Runtime Error):
x, y, z=int(input(),input(),input())
x,y=y,x
x,z=z,x
print(str(x) + " " + str(y) + " " + str(z) )
Problem p02718 (python)

Fixed submission:
N, M = map(int, input().split())
A = [int(i) for i in input().split()]

S = 0

for k in range (0 , N):
	S += A[k]

m = 0
for j in range (0 , N):
	if A[j] >= (S / ( 4 * M )):
		m = m + 1

if m >= M:
  	print ( "Yes" )
else:
 	print ( "No" )

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

S = 0

for k in range (0 , N):
	S += A[k]

for j in range (0 , N):
  	m = 0
  	if A[j] >= S / ( 4 * M ):
    	m = m + 1
    
if m >= M:
  	print ( "Yes" )
else:
 	print ( "No" )
Problem p02719 (python)

Fixed submission:
N, K = map(int,input().split())
 
if N >= K:
	N %= K
 
if ( K // 2 ) >= N:
	print ( N )
 
else:
    print ( K - N )

Buggy submission (verdict: Runtime Error):
N, K = input().split()

if N >= K:
	N %= K

if ( K / 2 ) >= N:
	print ( N )

else:
    print ( K - N )
Problem p03136 (python)

Fixed submission:
N = int(input())
L = input().split()
max = 0
count = 0

for i in range(N):
  count += int(L[i])
  if max < int(L[i]):
    max = int(L[i])
    
if count > 2*max:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int(inout())
L = input().split()
flag = 0

for i in range(N):
  L[i] = int(L[i])
  total += L[i]

for i in range(N):
  if L[i]*2 >= total:
    print("No")
    flag = 1
    break

if flag == 0:
  print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(inout())
L = int(input().split())
flag = 0

for i in range(N):
  total += L[i]

for i in range(N):
  if L[i]*2 >= total:
    print("No")
    flag = 1
    break

if flag == 0:
  print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(inout())
L = int(input().split())
flag = 0

for i in range(N):
  total += L[i]

for i in range(N):
  if A[i]*2 >= total:
    print("No")
    flag = 1
    break

if flag == 0:
  print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
L = map(int,input().split())
max = 0
count = 0

for i in range(N):
  count += L[i]
  if max < L[i]:
    max = L[i]
    
if count < 2*max:
  print("Yes")
else:
  print("No")
Problem p02724 (python)

Fixed submission:
X = int(input())

ans = 0

num = X // 500
X -= 500 * num
ans += num * 1000

num = X // 5
ans += num * 5

print(ans)

Buggy submission (verdict: Runtime Error):
X= int(input())
ans = X // 500 * 1000
X -= X // 500 * 
ans += (X // 5) * 5
print(ans)
Problem p02758 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left

N = int(input())
XD = [[int(i) for i in input().split()] for _ in range(N)]
XD.sort()
MOD = 998244353

def make():
    edge = [[] for _ in range(N)]
    parent = [-1] * N
    MAXIDX = N
    sorted_X = [X for X,_ in XD]
    for i in range(N-1, -1, -1):
        idx = bisect_left(sorted_X, XD[i][0] + XD[i][1])
        for j in range(i+1, min(idx, MAXIDX)):
            if parent[j] < 0:
                parent[j] = i
        if idx >= MAXIDX:
            MAXIDX = i + 1
    for i,par in enumerate(parent):
        if par < 0:
            continue
        edge[par].append(i)
    
    return parent, edge

parent, edge = make()

def cnt(node):
    if not edge[node]:
        return 2

    res = 1
    for v in edge[node]:
        res = (res * cnt(v)) % MOD
    res += 1

    return res % MOD

def main():
    ans = 1
    for i,par in enumerate(parent):
        if par < 0:
            ans = (ans * cnt(i)) % MOD

    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
N = int(input())
XD = [[int(i) for i in input().split()] for _ in range(N)]
XD.sort()
MOD = 998244353
sorted_X = [X for X,_ in XD]

edge = [[] for _ in range(N)]

from bisect import bisect_left

parent = [-1] * N

for i in range(N-1, -1, -1):
    idx = bisect_left(sorted_X, XD[i][0] + XD[i][1])
    for j in range(i+1, idx):
        if parent[j] < 0:
            parent[j] = i

for i,par in enumerate(parent):
    if par < 0:
        continue
    edge[par].append(i)

def cnt(node):
    if not edge[node]:
        return 2
    
    res = 1
    for v in edge[node]:
        res = (res * cnt(v)) % MOD
    res += 1

    return res % MOD

ans = 1
for i,par in enumerate(parent):
    if par < 0:
        ans = (ans * cnt(i)) % MOD

print(ans)
Problem p02804 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def getComb(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


N,K = map(int,input().split())
A = sorted([int(i) for i in input().split()])

# ref: https://www.planeta.tokyo/entry/5195/
mod = 10**9+7
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)

cmb = [0] * (N-K+1)
for i in range(N-K+1):
    cmb[i] = getComb(i+(K-1),K-1,mod)

sum_max = 0
for i in range(K-1,N):
    sum_max = (sum_max + cmb[i-(K-1)] * A[i]) % mod

sum_min = 0
for i in range(N-K,-1,-1):
    sum_min = (sum_min + cmb[(N-K)-i] * A[i]) % mod

answer = sum_max - sum_min
print(answer % mod)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def getComb(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    # n!/(n-k)!
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    # k!
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    # n!/((n-k)!*k!)
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD

def main():
    N,K = map(int,input().split())
    A = sorted([int(i) for i in input().split()])

    mod = 10**9+7

    cmb = [0] * N
    for i in range(N):
        cmb[i] = getComb(i,K-2,mod)

    answer = 0
    for i in range(N):
        for j in range(i+(K-1), N):
            answer = (answer + cmb[j-i-1] * ((A[j] - A[i]) % mod)) % mod

    print(answer)

if __name__ == "__main__":

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def getComb(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    # n!/(n-k)!
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    # k!
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    # n!/((n-k)!*k!)
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD

def main():
    N,K = map(int,input().split())
    A = sorted([int(i) for i in input().split()])

    mod = 10**9+7

    cmb = [0] * N
    for i in range(N):
        cmb[i] = getComb(i,K-2,mod)

    answer = 0
    for i in range(N):
        for j in range(i+(K-1), N):
            answer = (answer + cmb[j-i-1] * ((A[j] - A[i]) % mod)) % mod

    print(answer)

if __name__ == "__main__":
Problem p02850 (python)

Fixed submission:
import sys
input = sys.stdin.readline
 
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N-1)]

# graph[i]: 頂点iの親と子の集合
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

# 根
root = 1
# parent[i]: 頂点iの親
parent = [0]*(N+1)
# トポロジカル順序
order = []
# 未探索の頂点
stack = [root]

# dfsでparentを求める
while stack:
    # n: 探索する頂点
    n = stack.pop()
    order.append(n)
    for j in graph[n]:
        # jがnの親の場合
        if j == parent[n]:
            continue
        parent[j] = n
        stack.append(j)

# color[i]: 頂点iと親を繋ぐ辺の色
color = [-1] * (N+1)
# dfsで色を塗る
for i in order:
    # 既に使用した色
    ng = color[i]
    # 色
    c = 1
    for j in graph[i]:
        # jがiの親の場合(塗装済みなのでcontinue)
        if j == parent[i]:
            continue
        if c == ng:
            c += 1
        # 頂点iと頂点jの辺に色を塗る
        color[j] = c
        c += 1

# 入力順に辺の色を出力する
answer = [color[a] if parent[a]==b else color[b] for a,b in AB]
print(max(answer))
print("\n".join(map(str,answer)))

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

def main():

    """
    # color: 親と自らを繋ぐ辺の色
    # now: 現在地
    """
    def dfs(color,now):
        # 現在地が葉のとき
        if not now in a:
            return

        # 現在地から伸びる辺のインデックス
        index = [i for i in range(N-1) if now == a[i]]

        # 子ノードに伸びる辺を色塗り
        number = 1
        for i in range(len(index)):
            if number == color:
                number += 1
            K[index[i]] = number
            # 子ノードで色塗り開始
            dfs(number, b[index[i]])
            number += 1

    N = int(input())
    a = [0] * (N-1)
    b = [0] * (N-1)
    for i in range(N-1):
        a[i],b[i] = map(int,input().split())
    # 辺の色
    K = [0] * (N-1)
    dfs(0,1)
    print(len(set(K)))
    for i in K:
        print(i)

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

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            if not i in arr:
                arr.append(i)

    if temp!=1:
        if not temp in arr:
                arr.append(temp)

    return arr

A,B = map(int,input().split())
common = len(set(factorization(A)) & set(factorization(B)))
print(common+1)

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

A,B = map(int,input().split())
GCD = gcd(A,B)

# エラスとてネスの篩
def 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]]

answer = 0
for i in ([1]+primes(GCD)):
    if A%i == B%i == 0:
        answer += 1
print(answer)

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

A,B = map(int,input().split())
GCD = gcd(A,B)

# エラスとてネスの篩
def 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]]

answer = 0
for i in ([1]+primes(GCD)):
    if A%i == B%i == 0:
        answer += 1
print(answer)
Problem p02937 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from bisect import bisect_left


s = input().rstrip("\n")
len_s = len(s)
t = input().rstrip("\n")
len_t = len(t)

alpha = defaultdict(list)
for i in range(len_s):
    alpha[s[i]].append(i)

if not alpha[t[0]]:
    print(-1)
    exit()
else:
    now_index = alpha[t[0]][0]
    answer = now_index + 1

# O(|t|)
for i in range(1,len_t):
    index = alpha[t[i]]
    if not index:
        print(-1)
        exit()
    # O(log(index))
    next_index = bisect_left(index, now_index+1)
    # s[now_index+1:]にt[i]がある場合
    if next_index < len(index):
        answer += index[next_index] - now_index
        now_index = index[next_index]
    else:
        answer += (len_s -1) - now_index + (index[0] + 1)
        now_index = index[0]

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

s = [None] + list(input().rstrip("\n"))
len_s = len(s[1:])
t = list(input().rstrip("\n"))
len_t = len(t)

# s'からtが作れない場合
if (set(s[1:]) & set(t)) != set(t):
    print(-1)
    exit()

for i,x in enumerate(t):
    if i == len_t-1:
        tmp = [j for j,y in enumerate(s) if y == t[-1] and j > t[-2]]
        if tmp:
            t[i] = tmp[0]
        else:
            t[i] = s.index(x)
        break
    else:
        t[i] = s.index(x)

answer = 0
for i in range(len_t):
    if i == len_t-1:
        answer += t[-1]
        break
    if t[i] < t[i+1]:
        continue
    else:
        answer += len_s
    if answer > 10**100 * len_s:
        print(-1)
        exit()

if 1 <= answer <= 10**100 * len_s:
    print(answer)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = [None] + list(input().rstrip("\n"))
len_s = len(s[1:])
t = list(input().rstrip("\n"))

if (set(s[1:]) & set(t)) != set(t):
    print(-1)
    exit()

for i,x in enumerate(t):
    if i == len(t)-1:
        last = [i for i,x in enumerate(s) if x == t[-1] and i > t[-2]]
        if last:
            t[-1] = last[-1]
        else:
            t[i] = s.index(x)
        break

    t[i] = s.index(x)

answer = 0
for i in range(len(t)):
    if i == len(t)-1:
        answer += t[-1]
        break

    if t[i] < t[i+1]:
        continue
    else:
        answer += len_s

print(answer)
Problem p02949 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M,P = map(int,input().split())
edge = []
for i in range(M):
    A,B,C = map(int,input().split())
    edge.append([A-1,B-1,P-C])

def Bellman_Ford(edges, start, N):
    inf = float("inf")
    # dist[i]: 頂点iまでの最短距離
    dist = [inf for i in range(N)]
    dist[start] = 0

    for i in range(N+N):
        for a,b,c in edges:
            if a != inf and dist[b] > dist[a] + c:
                dist[b] = dist[a] + c
                # startからgoalまでに負閉路がある場合
                if i >= N:
                    dist[b] = -inf
        # 一回目のベルマンフォード法の結果
        if i == N-1:
            first_time = dist[-1]
    # (一回目,二回目)
    return first_time, dist[-1]

first,second = Bellman_Ford(edge, 0, N)
if first != second:
    answer = -1
else:
    answer = max(0,-second)

print(answer)

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

N,M,P = map(int,input().split())
edge = [[] for _ in range(M)]
for i in range(M):
    A,B,C = map(int,input().split())
    edge[i].append(A-1,B-1,-(C-P))

def Bellman_Ford(edges, start, N):
    inf = float("inf")
    # dist[i]: 頂点iまでの最短距離
    dist = [inf for i in range(N)]
    dist[start] = 0

    for i in range(N+N):
        for a,b,c in edges:
            if a != inf and dist[b] > dist[a] + c:
                dist[b] = dist[a] + c
                # startからgoalまでに負閉路がある場合
                if i >= N:
                    dist[b] = -float("inf")
        # 一回目のベルマンフォード法の結果
        if i == N-1:
            first_time = dist[-1]
    # (一回目,二回目)
    return (first_time, dist[-1])

first,second = Bellman_Ford(edge, 0, N)
if first != second:
    answer = -1
else:
    answer = max(0,-second)

print(answer)
Problem p02972 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

box = [0] * N

for i in range(N-1, -1, -1):
    # (i+1)の倍数が書かれた箱を探索
    count = 0
    n = i+1
    while n <= N:
        count += box[n-1]
        n += i + 1

    if count % 2 != a[i]:
        box[i] = 1

M = box.count(1)
print(M)

answer = [i+1 for i,x in enumerate(box) if x == 1]
if M > 0:
    print(' '.join(list(map(str,answer))))

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i - 1)
            if i != n // i:
                divisors.append(n//i - 1)
    return divisors

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import numpy as np

N = int(input())
# 1-indexed
a = [int(i) for i in input().split()]

now = [0] * N
for i in range(N-1,-1,-1):
    if now[i] != a[i]:
        div = make_divisors(i+1)
        for j in div:
            now[j] += 1
            now[j] %= 2

print(M)

answer = [i+1 for i,x in enumerate(now) if x == 1]
if answer:
    print(" ".join(list(map(str,answer))))
Problem p03032 (python)

Fixed submission:
from collections import deque
from bisect import insort_left

N,K = map(int,input().split())
V = [int(i) for i in input().split()]

answer = 0
A = 0
while A <= min(N,K):
    B = 0
    while A + B <= min(N,K):
        have = []
        for i in range(A):
            insort_left(have, V[i])
        for i in range(B):
            insort_left(have, V[-(i+1)])

        have = deque(have)

        throw = min(K - (A + B), len(have))
        for _ in range(throw):
            tmp = have.popleft()
            if tmp > 0:
                have.append(tmp)
                break

        answer = max(answer, sum(have))
        B += 1
    A += 1

print(answer)

Buggy submission (verdict: Runtime Error):
from collections import deque
import bisect

N,K = map(int,input().split())
V = [int(i) for i in input().split()]

answer = 0
A = 0
while A <= min(N,K):
    B = 0
    while A + B <= min(N,K):
        have = deque()
        for i in range(A):
            bisect.insort_left(have, V[i])
        for i in range(B):
            bisect.insort_left(have, V[-(i+1)])
        
        throw = min(K - (A + B), len(have))
        for _ in range(throw):
            tmp = have.popleft()
            if tmp > 0:
                have.append(tmp)
                break

        answer = max(answer, sum(have))
        B += 1
    A += 1

print(answer)
Problem p03150 (python)

Fixed submission:
keyence = "keyence"

S = input()

flag = False
for sta in range(len(S)):
    for end in range(sta,len(S)):
        if S[:sta] + S[end:] == keyence:
            flag = True

if flag:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
key = tuple("keyence")

S = input().rstrip("\n")

idx = 0
for i in S:
    if i == key[idx]:
        idx += 1

if idx == len(key):
    print("YES")
else:
    print("NO")

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

key = "keyence"

S = input()

idx = 0
for i in S:
    if i == key[idx]:
        idx += 1

if idx == len(key):
    print("YES")
else:
    print("NO")
Problem p03364 (python)

Fixed submission:
# 解説AC
import numpy as np

def is_symmetric(a):
    """
    対象行列判定 O(N * N)
    """
    return np.array_equal(a, a.T)

def main():
    N = int(input())
    S = [[ord(s) - ord("a") for s in list(input())] for _ in range(N)]

    S = np.array(S)

    ans = 0
    for B in range(N):
        if is_symmetric(np.roll(S, B, axis=1)):
            ans += N

    print(ans)

if __name__ == "__main__":
    main()

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

def is_symmetric(a):
    return np.array_equal(a, a.T)

def main():
    N = int(input())
    S = [[] for _ in range(N)]
    for i in range(N):
        for s in list(input()):
            S[i].append(ord(s) - ord("a"))

    S = np.array(S)

    ans = 0
    for A in range(N):
        for B in range(N):
            if is_symmetric(np.roll(S, (A, B), axis=(0,1))):
                ans += 1

    print(ans)

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

Fixed submission:
import numpy as np
from collections import deque

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

# BFS
def dist_from_X(X:int):
    dist = np.full(N, -1)
    que = deque([X])
    dist[X] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for e in E[v]:
            if dist[e] > -1:
                continue
            dist[e] = d + 1
            que.append(e)
    return dist

Fennec = dist_from_X(0)
Sunuke = dist_from_X(N-1)

cnt = np.count_nonzero(Fennec <= Sunuke)

if cnt > N - cnt:
    print("Fennec")
else:
    print("Snuke")

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc067/tasks/arc078_b

from collections import deque

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

def dist_from_X(X):
    dist = [-1] * N
    
    que = deque([X])
    dist[X] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for e in E[v]:
            if dist[e] > -1:
                continue
            dist[e] = d + 1
            que.append(e)
    
    return dist

Fennec = dist_from_X(0)
Sunuke = dist_from_X(N-1)

cnt = [0,0]
for i,j in zip(Fennec, Sunuke):
    if i <= j:
        cnt[0] += 1
    else:
        cnt[1] += 1

assert cnt[0] != cnt[1]
if cnt[0] > cnt[1]:
    print("Fennec")
else:
    print("Sunuke")
Problem p02615 (python)

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

a=sorted(a,reverse=True)
if n==2:
    print(max(a))
    exit(0)

ans=a[0]
a=a[1:]
from math import floor

for i in range(n-2):
    index=floor(i/2)
    ans+=a[index]

print(ans)

Buggy submission (verdict: Runtime Error):
total = 0

for _ in range(int(input()))
	list1 = list(map(int, input().split()))
	for ele in range(0, len(list1)):
		total = total + list1[ele]
	print(total-min(list1))

Buggy submission (verdict: Runtime Error):
for i in range(int(input())):
	a = list(map(int, input().split()))
	res = -1
	for i in a:
		res+=i
	print(res)
Problem p02618 (python)

Fixed submission:
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

tL = []
for i in range(D):
    tL.append(S[i].index(max(S[i])) + 1)

for t in tL:
    print(t)

Buggy submission (verdict: Runtime Error):
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

tL = []
for i in range(D):
    tL.append(int(input()))

def cal():
    score = 0
    his = [0] * len(C)
    for i in range(D):
        t = tL[i]
        t -= 1
        his[t] = i + 1
        sat = 0
        for j in range(len(C)):
            sat += C[j] * (i - his[j] + 1)
        score += S[i][t] - sat
    return score

def search():
    d, q = map(int, input().split())
    tL[d - 1] = q
    return cal()
    
M = int(input())
for _ in range(M):
    print(search())
Problem p02630 (python)

Fixed submission:
import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    x = dic.get(b)
    if x == None:
        l.append(sum)
        continue
    if b < c:
        sum += (c - b) * x
    else:
        sum -= (b - c) * x
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]

for s in l:
    print(s)

Buggy submission (verdict: Runtime Error):
import collections as cl
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sum = 0
for i in range(N):
    sum += A[i]
dic = cl.Counter(A)

l = []
for _ in range(Q):
    b, c = map(int, input().split())
    x = dic[b]
    if x == None:
        continue
    if b < c:
        sum += (c - b) * x
    else:
        sum -= (b- c) * x
    l.append(sum)
    if c not in dic:
        dic[c] = dic.pop(b)
    else:
        dic[c] = dic.pop(b) + dic[c]

for s in l:
    print(s)
Problem p03163 (python)

Fixed submission:
import numpy as np
N, W = map(int, input().split())
dp = np.zeros(W + 1, dtype = np.int64)

for _ in range(N):
    w,v = map(int, input().split())
    np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

print(dp[W])

Buggy submission (verdict: Runtime Error):
N, W =map(int, input().split())
weight = [0] * 110
value = [0] * 110
dp = [[0] * (110) for _ in range(10010)]

for i in range(N):
    weight[i], value[i] = map(int, input().split())

for i in range(N):
    for w in range(W + 1):# <= を表現したいときは+1するとよいかも
        if(w >= weight[i]):
            dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w])
        else:
            dp[i + 1][w] = dp[i][w]
#print(weight[:N],value[:N])
print(dp[N][W])
Problem p02640 (python)

Fixed submission:
X,Y=map(int,input().split())
m=(4*X-Y)/2
n=(Y-2*X)/2
if (m.is_integer() and m >=0 ) and (n.is_integer() and n>=0):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
try:
	N, M = map(int,input().split())
	for i in range(1, N+1):
    	f = 2 * i + 4 * (N - i)
    	if f == M:
       		print("Yes")
        	break
	else:
    	print("No")
except EOFError as error: