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

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
kazu=[0]*(10**6+1)
for i in a:
  for j in range(i,10**6+1, i):
    if j > 10**6+1:
      break
    if kazu[i] >= 2:
      break
    kazu[j] += 1

count = 0
for i in a:
  if kazu[i] == 1:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int, input().split()))
a_set=set(a)
a_uni=list(a_set)

kazu=[0]*(10*6+1)
for i in a_uni:
  for j in range(1,len(a_uni), i):
    kazu[j] += 1

count = 0
for i in a_uni:
  if kazu[i] == 1:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int, input().split()))
a_set=set(a)
a_uni=list(a_set)

kazu=[0]*(10**6)
for i in a_uni:
  for j in range(10**6):
    if i*j >= 10 ** 6:
      break
    kazu[i*j] += 1

count = 0
for i in a_uni:
  if kazu[i] == 1:
    count += 1
print(count)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split)
print(a*b)
Problem p02658 (python)

Fixed submission:
n=int(input())
A = list(map(int, input().split()))
result=1
limit=10**18
flg0=0
flg=0
for i in range(n):
  if A[i] == 0:
    flg0=1
    print('0')
for i in range(n):
  if flg0 == 1:
    break
  result *= A[i]
  if result > limit:
    print('-1')
    flg=1
    break
if flg != 1 and flg0 != 1:
  print(result)

Buggy submission (verdict: Runtime Error):
n=int(input())
A = list(map(int, input().split()))
result=1
limit=10**18
flg0=0
for i in range(n):
  if A[i] == 0:
    flg0=1
    print('0')
for i in range(n):
  if flg0 == 1:
    break
  result *= A[i]
  if result > limit:
    print('-1')
    flg=1
    break
if flg != 1 and flg0 != 1:
  print(result)
Problem p02732 (python)

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

def choose2(n):
  if n <= 1:
    return 0
  return n*(n-1)//2

inp = [0]*(n+1)
for i in range(n):
  inp[a[i]] += 1

total = 0
for i in range(n+1):
  total += choose2(inp[i])

for i in range(n):
  count = total - choose2(inp[a[i]]) + choose2(inp[a[i]]-1)
  print(count)

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

inp = [0]*(n+1)
for i in range(n):
  inp[a[i]] += 1

count = [0] * (n)
for i in range(n):
  if count[a[i]] != 0:
    continue
  
  inp[a[i]] -= 1
  for j in range(1,n):
    if inp[j] <= 0:
      continue
    count[a[i]] += inp[j]*(inp[j]-1) // 2
  inp[a[i]] += 1

for i in range(n):
  print(count[a[i]])
Problem p02888 (python)

Fixed submission:
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    if L[a] + L[b] > L[n-1]:
      count += n - b - 1
      continue
    left = b + 1
    right = n - 1
    while right - left > 0:
      c = (left+right) // 2
      if L[c] < L[a] + L[b]:
        left = c + 1
      else:
        right = c
    count += left - b - 1
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    count += bisect_left(L, L[a]+L[b]) - b - 1

print(count)
Problem p02995 (python)

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

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = calc_div_num(a, b, c)
num_d = calc_div_num(a, b, d)

import numpy as np
lcd = np.lcm(c, d)
num_lcd = calc_div_num(a, b, lcd)

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)

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

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d

import numpy as np
lcd = np.lcd(c,d)
num_lcd = b//lcd - (a-1)//lcd

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)
Problem p02843 (python)

Fixed submission:
M = 100001
dp = {}
dp[100],dp[101],dp[102],dp[103],dp[104],dp[105] = 1,1,1,1,1,1
def isComb(dp,n):
	for i in range(100,106):
		for j in range(i,106):
			if n-i in dp and n-j in dp and dp[n-i]==1 and dp[n-j]==1:
				return 1
			
	return 0


for i in range(106,M):
	if isComb(dp,i):
		dp[i] = 1
	else:
		dp[i] = 0
n = int(input())
if n in dp:
	print(dp[n])
else:
	print(0)
# print(dp[n])

Buggy submission (verdict: Runtime Error):
M = 1000001
dp = {}
dp[100],dp[101],dp[102],dp[103],dp[104],dp[105] = 1,1,1,1,1,1
def isComb(dp,n):
	for i in range(100,106):
		for j in range(i,106):
			if n-i in dp and n-j in dp and dp[n-i]==1 and dp[n-j]==1:
				return 1
			
	return 0


for i in range(106,M):
	if isComb(dp,i):
		dp[i] = 1
	else:
		dp[i] = 0
n = int(input())
print(dp[n])

Buggy submission (verdict: Runtime Error):
M = 100001
dp = {}
dp[100],dp[101],dp[102],dp[103],dp[104],dp[105] = 1,1,1,1,1,1
def isComb(dp,n):
	for i in range(100,106):
		for j in range(i,106):
			if n-i in dp and n-j in dp and dp[n-i]==1 and dp[n-j]==1:
				return 1
			
	return 0


for i in range(106,M):
	if isComb(dp,i):
		dp[i] = 1
	else:
		dp[i] = 0
n = int(input())
print(dp[n])
Problem p02536 (python)

Fixed submission:
class Tree:
    def __init__(self, N):
        self.N = N
        self.nodes = [ Node(i) for i in range(N) ]

    def get_root(self, node):
        if node.parent is None:
            return node
        root = self.get_root(node.parent)
        node.parent = root
        return root

    def merge(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)

        if root1.ID == root2.ID:
            return

        root1.parent = root2

    def get_root_count(self):
        count = 0
        for n in self.nodes:
            if n.parent is None:
                count += 1
        return count

class Node:
    def __init__(self, ID):
        self.ID = ID
        self.parent = None

def main():
    N, M = map(int, input().split())
    tree = Tree(N)
    for i in range(M):
        A, B = map(int, input().split())
        A, B = A-1, B-1
        tree.merge(tree.nodes[A], tree.nodes[B])
    print(tree.get_root_count() - 1)


main()

Buggy submission (verdict: Runtime Error):
class Tree:
    def __init__(self, N):
        self.N = N
        self.nodes = [ Node(i) for i in range(N) ]

    def get_root(self, node):
        if node.parent is None:
            return node
        root = self.get_root(node.parent)
        node.parent = root
        return root

    def merge(self, n1, n2):
        node1 = self.nodes[n1]
        node2 = self.nodes[n2]

        root1 = self.get_root(node1)
        root2 = self.get_root(node2)

        if root1.ID == root2.ID:
            return

        root1.parent = root2

    def get_root_count(self):
        count = 0
        for n in self.nodes:
            if n.parent is None:
                count += 1
        return count

class Node:
    def __init__(self, ID):
        self.ID = ID
        self.parent = None

def main():
    N, M = map(int, input().split())
    tree = Tree(N)
    for i in range(M):
        A, B = map(int, input().split())
        tree.merge(A, B)
    print(tree.get_root_count() - 1)


main()
Problem p02615 (python)

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

sortA = sorted(A)

result = 0
for i in range(1, N):
    result += sortA[N - (i // 2) - 1]

print(result)

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

sortA = sorted(A)

min_val = sortA[0]
min_count = 1
for i in range(1, N):
    if sortA[i] == min_val:
        min_count += 1
    break

mins = sortA[:min_count]
larges = sortA[min_count:]

result = sum(larges[1:])

if len(mins) < len(larges):
    result += sum(larges[len(larges)-len(mins)-1:-1])
elif len(mins) == len(larges):
    result += sum(larges[len(larges)-len(mins)-1:-1])
    result += larges[0]
else:
    result += sum(larges[len(larges)-len(mins)-1:-1])
    result += larges[0]
    rem_mins_count = len(mins) - len(larges)
    result += rem_mins_count * min_val

print(result)
Problem p02641 (python)

Fixed submission:
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return

    P = list(map(int, input().split()))

    if not X in P:
        print(X)
        return
    
    for i in range(1, 10000):
        if not X-i in P:
            print(X-i)
            return
        if not X+i in P:
            print(X+i)
            return

main()

Buggy submission (verdict: Runtime Error):
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return

    P = list(map(int, input().split()))

    P_exist = [False] * (101)
    for p in P:
        P_exist[p] = True

    if not P_exist[X]:
        print(X)
        return
    
    for i in range(1, 200):
        if (not P_exist[X-i]) and (not P_exist[X+i]):
            print(X-i)
            return
        if not P_exist[X-i]:
            print(X-i)
            return
        if not P_exist[X+i]:
            print(X+i)
            return

main()
Problem p02694 (python)

Fixed submission:
X = int(input())

n = 100
year_count = 0

while n < X:
    n += n // 100
    year_count += 1

print(year_count)

Buggy submission (verdict: Runtime Error):
year = 0 # 答え
money = 100 # 初期値の100円

# x円以上になるまでループを回す
while money < x:
    money *= 1.01
    money = int(money)
    year += 1

print(year)
Problem p03292 (python)

Fixed submission:
a,b,c = map(int, input().split())
d = abs(a-b)
e = abs(a-c)
g = abs(b-c)
if d >= e and d >= g:
  print(e+g)
elif e >= d and e >= g:
  print(d+g)
else:
  print(d+e)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = len(a)
a_list = list(a)
b_list = list(b)
for i in range(101):
  tmp = a_list[0]
  for j in range(c-1):
    a_list[j] = a_list[j+1]
  a_list[c-1] = tmp
  if a_list == b_list:
    print("Yes")
    exit()
print("No")
Problem p02647 (python)

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

for _ in range(K):
    flag = True
    for a in A:
        if a != N: flag = False
    if flag: break

    imos = [0] * (N+1)
    for i in range(N):
        l = max(i-A[i],0)
        r = min(i+A[i],N-1)
        imos[l] += 1
        imos[r+1] += -1
    
    for i in range(N):
        imos[i+1] += imos[i]
    
    A = imos[:N]

for a in A[:N]:
    print(a, end=" ")
print()

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

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

for _ in range(min(K,100)):
    imos = np.zeros(N+1,int)
    for i in range(N):
        l, r = max(i-A[i],0), min(i+A[i],N-1)
        imos[l] += 1
        imos[r+1] += -1
    
    A = np.cumsum(imos)[:N]

print(' '.join(A.astype(str)))
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)

N, Q = map(int,input().split())
G = [[] for _ in range(N)]
counter = [0] * N

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

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

stack, seen = [0], [False]*N
while stack:
    v = stack.pop()
    seen[v] = True

    for u in G[v]:
        if not seen[u]:
            stack.append(u)
            counter[u] += counter[v]

for c in counter:
    print(c, end = " ")
print("")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

N, Q = map(int,input().split())
G = [[] for _ in range(N)]
counter = [0] * N

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

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

seen = [False]*N

def dfs(v, seen, G, counter):
    seen[v] = True
    for u in G[v]:
        if not seen[u]:
            counter[u] += counter[v]
            dfs(u, seen, G, counter)

dfs(0, seen, G, counter)

for c in counter:
    print(c, end = " ")
print("")
Problem p02974 (python)

Fixed submission:
N, K = map(int,input().split())
MOD = 10**9+7

# dp[i][j][k]:
# ウサギ1~i, カメ1~i (うちj個は相手が未定)まで見ていて，
# 確定している奇妙さがkであるような場合の数
dp = []
for _ in range(55):
    dp.append([[0] * (55*55) for _ in range(55)])

dp[0][0][0] = 1

for i in range(N+1):
    for j in range(N+1):
        for k in range(N*N+1):
            if k-2*j < 0 or i-1 < 0: continue

            dp[i][j][k] += (2*j+1) * dp[i-1][j][k-2*j] % MOD
            dp[i][j][k] %= MOD

            dp[i][j][k] += (j+1)*(j+1) * dp[i-1][j+1][k-2*j] % MOD
            dp[i][j][k] %= MOD

            if j > 0:
                dp[i][j][k] += dp[i-1][j-1][k-2*j]
                dp[i][j][k] %= MOD
            
print(dp[N][0][K])

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

N, K = map(int,input().split())
MOD = 10**9+7

# dp[i][j][k]:
# ウサギ1~i, カメ1~i (うちj個は相手が未定)まで見ていて，
# 確定している奇妙さがkであるような場合の数
dp = np.zeros((55,55,55*55), dtype='int64')
dp[0][0][0] = 1

for i in range(N+1):
    for j in range(N+1):
        for k in range(N*N+1):
            if k-2*j < 0 or i-1 < 0: continue

            dp[i][j][k] += (2*j+1) * dp[i-1][j][k-2*j] % MOD
            dp[i][j][k] %= MOD

            dp[i][j][k] += (j+1)*(j+1) * dp[i-1][j+1][k-2*j] % MOD
            dp[i][j][k] %= MOD

            if j > 0:
                dp[i][j][k] += dp[i-1][j-1][k-2*j]
                dp[i][j][k] %= MOD
            
print(dp[N][0][K])

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

N, K = map(int,input().split())
MOD = 10**9+7

# dp[i][j][k]:
# ウサギ1~i, カメ1~i (うちj個は相手が未定)まで見ていて，
# 確定している奇妙さがkであるような場合の数
dp = np.zeros((55,55,55), dtype='int64')
dp[0][0][0] = 1

for i in range(N+1):
    for j in range(N+1):
        for k in range(N+1):
            if k-2*j < 0 or i <= 0: continue

            dp[i][j][k] += (2*j+1) * dp[i-1][j][k-2*j] % MOD
            dp[i][j][k] %= MOD

            dp[i][j][k] += (j+1)*(j+1)*dp[i-1][j+1][k-2*j] % MOD
            dp[i][j][k] %= MOD

            if j > 0:
                dp[i][j][k] += dp[i-1][j-1][k-2*j]
                dp[i][j][k] %= MOD
            
print(dp[N][0][K])
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

MOD = 10**9 + 7
N, K = map(int,input().split())

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

    G[a].append(b)
    G[b].append(a)

# 頂点nowを根とする部分木の色の塗り方 (parが親の時)
#   ただしnowはすでに塗られているとする
def dfs(now, par):
    if K < len(G[now]): return 0

    res = 1

    if par == -1:
        colors = K-1
        for i in range(len(G[now])):
            res *= colors-i
            res %= MOD
    else:
        colors = K-2
        for i in range(len(G[now])-1):
            res *= colors-i
            res %= MOD

    for c in G[now]:
        if c == par: continue
        
        res *= dfs(c, now)
        res %= MOD
    
    return res

print(K * dfs(0,-1) % MOD)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N, K = map(int,input().split())

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

    G[a].append(b)
    G[b].append(a)

# 頂点nowを根とする部分木の色の塗り方 (parが親の時)
#   ただしnowはすでに塗られているとする
def dfs(now, par):
    if K < len(G[now]): return 0

    res = 1

    if par == -1:
        colors = K-1
        for i in range(len(G[now])):
            res *= colors-i
            res %= MOD
    else:
        colors = K-2
        for i in range(len(G[now])-1):
            res *= colors-i
            res %= MOD

    for c in G[now]:
        if c == par: continue
        
        res *= dfs(c, now)
        res %= MOD
    
    return res

print(K * dfs(0,-1) % MOD)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N, K = map(int,input().split())

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

    G[a].append(b)
    G[b].append(a)

# 頂点nowを根とする部分木の色の塗り方 (parが親の時)
#   ただしnowはすでに塗られているとする
def dfs(now, par):
    if K < len(G[now]): return 0

    res = 1

    if par == -1:
        colors = K-1
        for i in range(len(G[now])):
            res *= colors-i
            res %= MOD
    else:
        colors = K-2
        for i in range(len(G[now])-1):
            res *= colors-i
            res %= MOD

    for c in G[now]:
        if c == par: continue
        
        res *= dfs(c, now)
        res %= MOD
    
    return res

print(K * dfs(0,-1) % MOD)
Problem p03682 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)

class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n  # 連結成分の数

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))

N = int(input())
X, Y = [], []
for i in range(N):
    x, y = map(int,input().split())
    X.append([x, i])
    Y.append([y, i])

X.sort()
Y.sort()

edges = []
for i in range(N-1):
    edges.append([X[i+1][0]-X[i][0], X[i][1], X[i+1][1]])
    edges.append([Y[i+1][0]-Y[i][0], Y[i][1], Y[i+1][1]])
edges.sort()

UF = UnionFind(N)
ans = 0
for cost, s, t in edges:
    if UF.same(s,t): continue

    UF.unite(s,t)
    ans += cost
print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n  # 連結成分の数

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))

N = int(input())
X, Y = [], []
for i in range(N):
    x, y = map(int,input().split())
    X.append([x,i])
    Y.append([y,i])

X.sort()
Y.sort()

edges = []
for i in range(N-1):
    edges.append([X[i+1][0]-X[i][0], X[i][1], X[i+1][1]])
    edges.append([Y[i+1][0]-Y[i][0], Y[i][1], Y[i+1][1]])
edges.sort()

UF = UnionFind(N)
ans = 0
for cost, s, t in edges:
    if UF.same(s,t): continue

    UF.unite(s,t)
    ans += cost
print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n  # 連結成分の数

    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))

N = int(input())
X, Y = [], []
for i in range(N):
    x, y = map(int,input().split())
    X.append([x,i])
    Y.append([y,i])

X.sort()
Y.sort()

edges = []
for i in range(N-1):
    edges.append([X[i+1][0]-X[i][0], X[i][1], X[i+1][1]])
    edges.append([Y[i+1][0]-Y[i][0], Y[i][1], Y[i+1][1]])
edges.sort()

UF = UnionFind(N)
ans = 0
for cost, s, t in edges:
    if UF.same(s,t): continue

    UF.unite(s,t)
    ans += cost
print(ans)
Problem p02952 (python)

Fixed submission:
N = int(input())
ans = 0
for n in range(1,N+1):
    if len(str(n)) % 2 == 1:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
for n in range(1,N+1):
    if len(str(n)) % 2 == 1:
    ans += 1
print(ans)
Problem p03030 (python)

Fixed submission:
N = int(input())
 
city = []
for i in range(N):
    s, p = input().split()
    city.append([s, int(p), i+1])
city.sort(key=lambda city: (city[0], -city[1]))
 
for i in city:
    print(i[2])

Buggy submission (verdict: Runtime Error):
import pandas as pd
import numpy as np
N = int(input())
df = pd.DataFrame(index = range(1,N+1),columns =['name','score'])
for i in range(N):
    name,score = input().split()
    df['name'].iloc[i] = name
    df['score'].iloc[i] = score
for i in df.sort_values(['name','score'],ascending = [True,False]).index:
    print(i)
Problem p03043 (python)

Fixed submission:
N,K = map(int,input().split())
result = 0
for i in range(1,N+1):
    prob = 1
    count = i 
    while count < K:
        prob *= 0.5
        count *= 2
    result += prob /N
print(result)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
result = 0
for i in range(1,N+1):
    prob = 1
    count = i 
    while count < K:
        prob *= 0.5
        count *= 2
    result += prob /N
print(result)
Problem p03447 (python)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())
print((x-a)%b)

Buggy submission (verdict: Runtime Error):
X,A,B = map(int,input().split())
print((X - A)%B)

Buggy submission (verdict: Runtime Error):
X,A,B = map(int,input().split())
print((X - A)%B)
Problem p03943 (python)

Fixed submission:
a =  list(map(int, input().split()))
if any([a[0]+a[1] ==a[2] ,a[0]+a[2] ==a[1] ,a[1]+a[2] == a[0]]):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
if any([a+b ==c,a+c==b,b+c == a]):
    print('Yes')
else:
    print('No')
Problem p02630 (python)

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

B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

d = [0] * (10**5 + 7)
for a in A:
    d[a] += 1
sum_a = sum(A)
for j in range(Q):
    before = d[C[j]]
    d[C[j]] += d[B[j]]
    sum_a -= d[B[j]] * B[j]

    sum_a += (d[C[j]] - before) * C[j]
    d[B[j]] = 0
    print(sum_a)

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

B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

d = [0] * 10
for a in A:
    d[a] += 1
sum_a = sum(A)
for j in range(Q):
    d[C[j]] += d[B[j]]
    sum_a -= d[B[j]] * B[j]

    sum_a += (d[C[j]] - d[B[j]]) * C[j]
    d[B[j]] = 0
    print(sum_a)

Buggy submission (verdict: Runtime Error):
from collections import deque, Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
L = deque()
for _ in range(Q):
    b, c = map(int, input().split())
    L.append([b, c])
d = [0] * 10**5
count = Counter(A)
sum_a = sum(A)
for j in range(Q):
    d[L[j][1]] = count[L[j][0]]

    sum_a -= d[L[j][1]] * L[j][0]
    sum_a += d[L[j][1]] * L[j][1]

    print(sum_a)
Problem p02660 (python)

Fixed submission:
n = int(input())

d = 2
ans = 0
while d * d <= n:
    if (n % d != 0):
        d += 1
        continue
    z = d
    while n % z == 0:
        n //= z
        z *= d
        ans += 1

    while n % d == 0:
        # 残りかすを除去
        n //= d

if (n != 1):
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B = input().split()

print(int(math.floor(float(A) * float(B))))
Problem p02719 (python)

Fixed submission:
import sys
N, K = map(int, input().split())

ans = N % K
ans = min(ans, abs(K-ans))
print(ans)

Buggy submission (verdict: Runtime Error):
while True:
    if ((n-k) > 10000):
        n = n // 100
    else:
        an = abs(n-k)
        if n <= an:
            break
        else:
            n = an
print(n)

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

while True:
    if ((n-k) > 10000):
        n = n // 10000
    else:
        an = abs(n-k)
    if n <= an:
        break
    else:
        n = min(n, an)
print(n)
Problem p02720 (python)

Fixed submission:
from collections import deque

k = int(input())

q =deque([1,2,3,4,5,6,7,8,9])

num = 0

while True:
    x = q.popleft()
    num += 1
    if num == k:
        break
    y = x % 10
    if y != 0:
        q.append(10*x+y-1)
    q.append(10*x+y)
    if y != 9:
        q.append(10*x+y+1)

print(x)

Buggy submission (verdict: Runtime Error):
k= int(input())
runrun = [1,2,3,4,5,6,7,8,9]
for i in range(10, 1000000):
    si = str(i)
    lsi = len(si)
    t =False
    for i in range(lsi-1):
        if abs(int(si[i]) - int(si[i+1])) <= 1:
            t = True
        else:
            t = False
            break
    if t:
        runrun.append(int(si))
print(runrun[k-1])