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

Fixed submission:
n, k= input().split()
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
for i in range(len(n)):
    first=int(n[i])
    k=find(first)
    if k==first:
        fin+=str(k)
    else:
        if k!=10:
            fin=str(k)+str(find(0))*(len(n)-i-1)
        else:
            fin=str(find(1))+str(find(0))*len(n)
        break

print(fin)

Buggy submission (verdict: Runtime Error):
n, k= input().split()
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
for i in range(len(n)):
    first=int(n[i])
    k=find(first)
    if k==first:
        fin+=str(k)
    else:
        if k!=10:
            fin+=str(k)
            i+=1
        else:fin+=str(find(1))
        fin+=str(find(0))*(len(n)-i)
        break

p

Buggy submission (verdict: Runtime Error):
n, k= map(int,input().split())
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]
for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]
def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x
fin=""
remain=0

if n==0:
    fin=str(find(0))

while n>0 or remain>0:
    last=n%10
    k=find(last+remain)
    remain=0
    if k!=10:
        fin=str(k)+fin
    else:
        remain+=1
        fin=str(find(0))+fin
    n//=10
print(fin)
Problem p02700 (python)

Fixed submission:
A, B, C, D = map(int, input().split())

# while A > 0 and B > 0:
#     print(A, C)
#     C -= B
#     if B <= 0:
#         print("Yes")
#         break
#     A -= D
#     if A <= 0:
#         print("No")
#         break

import math
# print(math.ceil(A / D), math.ceil(C / B))
if math.ceil(A / D) >= math.ceil(C / B):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
list = {input() for _ in range(N)}
print(len(list))
Problem p02714 (python)

Fixed submission:
N = int(input())
S = input()

count = 0

R_count = [0] * (N+1)
R = 0
G_count = [0] * (N+1)
G = 0
B_count = [0] * (N+1)
B = 0

for i, s in enumerate(reversed(list(S))):
    if s == 'R':
        R += 1
    if s == 'G':
        G += 1
    if s == 'B':
        B += 1

    R_count[N - i - 1] = R
    G_count[N-i-1] = G
    B_count[N-i-1] = B
# print(R_count)
# print(G_count)
# print(B_count)

for i in range(0, N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        if (S[i] == 'R' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'R'):
            count += B_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'B':
                count -= 1
        elif (S[i] == 'R' and S[j] == 'B') or (S[i] == 'B' and S[j] == 'R'):
            count += G_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'G':
                count -= 1
        if (S[i] == 'B' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'B'):
            count += R_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'R':
                count -= 1
print(count)

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

count = 0

for i in range(0, N-2):
    if S[i] == S[j]:
        continue
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if i -j == j - k:
                continue
            if S[i] != S[j] and S[k] != S[j] and S[i] != S[k]:
                count += 1
print(count)
Problem p02804 (python)

Fixed submission:
import heapq

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

from operator import mul
from functools import reduce

MOD = 10 ** 9 + 7

def mpow(a, n):
    if n == 0: return 1
    if n == 1: return a % MOD
    if n % 2 == 1: return (a % MOD * mpow(a, n - 1) % MOD) % MOD
    t = mpow(a, n // 2)
    return (t * t) % MOD

fac = [1] * (n + 1)
inv_fac = [1] * (n + 1)
for i in range(n):
    fac[i + 1] = (fac[i] * (i + 1)) % MOD
inv_fac[n] = mpow(fac[n], MOD - 2)
for i in range(n, 0, -1):
    inv_fac[i - 1] = (inv_fac[i] * i) % MOD

def cmb(n, r):
    if n == 0 and r == 0: return 1
    if n < r or n < 0: return 0
    return (fac[n] * (inv_fac[r] * inv_fac[n - r]) % MOD) % MOD

A.sort()

# cmb_list = {}
# cmb_list[(K - 1, K - 1)] = cmb(K - 1, K - 1)
# for i in range(K, n):
#     cmb_list[(i, K-1)] = cmb_list[(i-1, K-1)] * i // (i - (K - 1))

max_f = 0
min_f = 0

for idx in range(n):
    a = heapq.heappop(A)
    if idx >= K - 1:
        max_f += cmb(idx, K - 1) * a
        # print("max", cmb(idx, K-1), idx, K-1, a)

    if n - (idx + 1) >= K - 1:
        min_f += cmb(n - (idx + 1), K - 1) * a
        # print("min", cmb(N-(idx+1), K-1), N-(idx+1), K-1, a)

print((max_f - min_f) % (10**9+7))

Buggy submission (verdict: Runtime Error):
import heapq

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

from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

heapq.heapify(A)

cmb_list = {}
cmb_list[(K - 1, K - 1)] = cmb(K - 1, K - 1)
for i in range(K, N):
    cmb_list[(i, K-1)] = int(cmb_list[(i-1, K-1)] * i / (i - (K - 1)))
# print(cmb_list)

# print(A)

max_f = 0
min_f = 0


for idx in range(N):
    a = heapq.heappop(A)
    if idx >= K-1:
        max_f += cmb_list[(idx, K-1)]*a
        # print("max", cmb(idx, K-1), idx, K-1, a)

    if N-(idx+1) >= K - 1:
        min_f += cmb_list[(N-(idx+1), K-1)]*a
        # print("min", cmb(N-(idx+1), K-1), N-(idx+1), K-1, a)

print((max_f - min_f) % (10**9+7))

Buggy submission (verdict: Runtime Error):
import heapq

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

from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

heapq.heapify(A)

cmb_list = {}
cmb_list[(K - 1, K - 1)] = cmb(K - 1, K - 1)
cmb_val = cmb(K - 1, K - 1)
for i in range(K, N):
    cmb_val = cmb_val * i / (i - (K - 1))
    cmb_list[(i, K-1)] = int(cmb_val)
# print(cmb_list)

# print(A)

max_f = 0
min_f = 0


for idx in range(N):
    a = heapq.heappop(A)
    if idx >= K-1:
        max_f += cmb_list[(idx, K-1)]*a
        # print("max", cmb(idx, K-1), idx, K-1, a)

    if N-(idx+1) >= K - 1:
        min_f += cmb_list[(N-(idx+1), K-1)]*a
        # print("min", cmb(N-(idx+1), K-1), N-(idx+1), K-1, a)

print((max_f - min_f) % (10**9+7))
Problem p02844 (python)

Fixed submission:
N = int(input())
S = list(input())
visited = {}

count = 0

for i, s in enumerate(S):
    if s in visited:
        continue
    visited[s] = []
    for j, s2 in enumerate(S[i+1:N-1]):
        # print(s, s2, S[i + j + 2:N])
        if s2 in visited[s]:
            continue
        count += len(set(S[i + j + 2:N]))
        visited[s].append(s2)
        # print(s, s2, set(S[j + 1:N]))
print(count)

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

ans_list = {}


for i in range(N):
    if i in i_set:
        continue
    i_set.append(i)
    for j in range(i+1, N):
        if not S[j + 1:N] or S[i] + S[j] in S_set:
            continue
        ans_list[S[i] + S[j]] = S[j + 1:N]
        S_set.add(S[i] + S[j])
count = 0
# print(ans_list)
ans_len_list = [len(set(value)) for value in ans_list.values()]
print(sum(ans_len_list))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(input())
i_set = set()

ans_list = {}


for i in range(N):
    if i in i_set:
        continue
    i_set.add(i)
    for j in range(i+1, N):
        if not S[j + 1:N] or S[i] + S[j] in S_set:
            continue
        ans_list[S[i] + S[j]] = S[j + 1:N]
        S_set.add(S[i] + S[j])
count = 0
# print(ans_list)
ans_len_list = [len(set(value)) for value in ans_list.values()]
print(sum(ans_len_list))
Problem p02900 (python)

Fixed submission:
import fractions

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

f = fractions.gcd(A, B)

kouyakusuu = []

if f % 2 == 0:
    kouyakusuu.append(2)
    while f % 2 == 0:
        f = f / 2

i = 3
while i*i <= f:
    if f % i == 0:
        kouyakusuu.append(i)
        while f % i == 0:
            f = f / i
    i += 2
if f != 1:
    kouyakusuu.append(f)
print(len(kouyakusuu)+1)

Buggy submission (verdict: Runtime Error):
from math import gcd as bltin_gcd
import itertools

def coprime2(a, b):
    return bltin_gcd(a, b) == 1

A, B = map(int, input().split())
koyakusuu_list = []

def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors

for a in make_divisors(A):
    if a == 1:
        koyakusuu_list.append(1)
    elif B % a == 0:
        flag = 0
        for kouyakusuu in koyakusuu_list:
            if coprime2(a, kouyakusuu):
                continue
            else:
                flag += 1
        if flag == 0:
            koyakusuu_list.append(a)

print(len(set(koyakusuu_list)))

Buggy submission (verdict: Runtime Error):
from math import gcd as bltin_gcd
import itertools

def coprime2(a, b):
    return bltin_gcd(a, b) == 1

A, B = map(int, input().split())
koyakusuu_list = []

def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors

for a in make_divisors(A):
    if a == 1:
        koyakusuu_list.append(1)
    elif B % a == 0:
        flag = 0
        for kouyakusuu in koyakusuu_list:
            if coprime2(a, kouyakusuu):
                continue
            else:
                flag += 1
        if flag == 0:
            koyakusuu_list.append(a)

print(len(set(koyakusuu_list)))

Buggy submission (verdict: Runtime Error):
from math import gcd as bltin_gcd
import itertools

def coprime2(a, b):
    return bltin_gcd(a, b) == 1

A, B = map(int, input().split())
koyakusuu_list = []
for a in range(1, A+1):
    if a == 1:
        koyakusuu_list.append(1)
    elif B % a == 0 and A % a == 0:
        flag = 0
        for kouyakusuu in koyakusuu_list:
            if coprime2(a, kouyakusuu):
                continue
            else:
                flag += 1
        if flag == 0:
            koyakusuu_list.append(a)

print(len(set(koyakusuu_list)))

Buggy submission (verdict: Runtime Error):
from math import gcd as bltin_gcd
import itertools

def coprime2(a, b):
    return bltin_gcd(a, b) == 1

A, B = map(int, input().split())
koyakusuu_list = []
for a in range(1, A+1):
    if a == 1:
        koyakusuu_list.append(1)
    elif B % a == 0 and A % a == 0:
        flag = 0
        for kouyakusuu in koyakusuu_list:
            if coprime2(a, kouyakusuu):
                continue
            else:
                flag += 1
        if flag == 0:
            koyakusuu_list.append(a)

print(len(set(koyakusuu_list)))
Problem p02924 (python)

Fixed submission:
N = int(input())

print(N*(N-1)//2)

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

print(sum(list(range(N))))
Problem p02945 (python)

Fixed submission:
A, B = map(int, input().split())
print(max([A + B, A - B, A * B]))

Buggy submission (verdict: Runtime Error):
a = int(input())
s = input()
    if a >= 3200:
        print(s)
    else:
        print("red")
Problem p02958 (python)

Fixed submission:
N = input()
P = list(map(int, input().split()))
flag = 0
for idx, p in enumerate(P):
    if p != idx + 1:
        flag += 1

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

Buggy submission (verdict: Runtime Error):
N = input()
P = list(map(int, input().split()))
sort_P = sorted(P)
new_P = []
for idx, p in enumerate(P):
    new_P.append(sort_P[idx] - p)
new_new_P = set(new_P)
new_new_P.remove(0)
if len(new_new_P) > 2:
    print("NO")
else:
    print("YES")
Problem p02983 (python)

Fixed submission:
import heapq

L, R = map(int, input().split())

if R - L >= 2019:
    print(0)
else:
    answer = 5000
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            if (i * j) % 2019 < answer:
                answer = (i * j) % 2019
    print(answer)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())

answer = 5000
for i in range(L, R+1):
    for j in range(i+1, R+1):
        if (i*j)%2019 < answer:
            answer = (i*j)%2019
print(answer
Problem p03006 (python)

Fixed submission:
import itertools
import collections

N = int(input())
x_y = [list(map(int, input().split())) for _ in range(N)]

count = collections.defaultdict(int)
for i in itertools.combinations(x_y, 2):
    count[(i[0][0]-i[1][0], i[0][1]-i[1][1])] += 1
    count[(i[1][0]-i[0][0], i[1][1]-i[0][1])] += 1
if not count:
    print(N)
else:
    print(N-max(count.values()))

Buggy submission (verdict: Runtime Error):
import itertools
import collections

N = int(input())
x_y = [list(map(int, input().split())) for _ in range(N)]

count = collections.defaultdict(int)
for i in itertools.combinations(x_y, 2):
    count[(i[0][0]-i[1][0], i[0][1]-i[1][1])] += 1
    count[(i[1][0]-i[0][0], i[1][1]-i[0][1])] += 1

print(N-max(count.values()))

Buggy submission (verdict: Runtime Error):
import itertools
import collections

N = int(input())
x_y = [list(map(int, input().split())) for _ in range(N)]

count = collections.defaultdict(int)
for i in itertools.combinations(x_y, 2):
    count[(i[0][0]-i[1][0], i[0][1]-i[1][1])] += 1
    count[(i[1][0]-i[0][0], i[1][1]-i[0][1])] += 1

print(N-max(count.values()))
Problem p03043 (python)

Fixed submission:
import math

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

answer = 0

for i in range(1, N+1):
    if K > i:
        answer += (1/N) * (1/2)**(math.ceil(math.log2(K/i)))
    else:
        answer += (1 / N) 
print(answer)

Buggy submission (verdict: Runtime Error):
import math

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

answer = 0

for i in range(1, N+1):
    if K > i:
        answer += (1/N) * (1/2)**(math.ceil(math.log2(K/i)))
    else:
        answer += (1 / N) 
print(answer)
Problem p03086 (python)

Fixed submission:
S = input()

ans = 0
ACGT = ("A", "C", "G", "T")

count = 0
count_list = [0]
for s in S:
    if s not in ACGT:
        count_list.append(count)
        count = 0
        continue
    else:
        count += 1
count_list.append(count)
print(max(count_list))

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

ACGT = ['A', 'C', 'G', 'T']

count_list = []
count = 0
max_count = 0
for s in S:
    if s in ACGT:
        count += 1
    else:
        count_list.append(count)
        # max_count = max(max_count, count)
        count = 0
print(max(count_list))

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

ACGT = ['A', 'C', 'G', 'T']

count_list = []
count = 0
max_count = 0
for s in S:
    if s in ACGT:
        count += 1
    else:
        count_list.append(count)
        # max_count = max(max_count, count)
        count = 0
print(max(count_list))

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

ans = 0
ACGT = ("A", "C", "G", "T")

count = 0
count_list = []
for s in S:
    if s not in ACGT:
        count_list.append(count)
        count = 0
        continue
    else:
        count += 1
print(max(count_list))
Problem p03087 (python)

Fixed submission:
import collections

N, Q = map(int, input().split())
S = input()

new_S = S.replace("AC", "12")


count_one_list = [0] * len(S)
for i in range(len(S)-1):
    if new_S[i] == '1' and i == 0:
        count_one_list[i+1] += 1
    elif new_S[i] == '1':
        count_one_list[i+1] = count_one_list[i] + 1
    else:
        count_one_list[i+1] = count_one_list[i]
# count_one_list = [new_S[:i].count('1') for i in range(len(S))]
# print(count_one_list)

for i in range(Q):
    left, right = map(int, input().split())
    count_one = count_one_list[right-1] - count_one_list[left-1]
    print(count_one)

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

    for i in range(Q):
        left, right = map(int, input().split())
        print(len(S[left-1:right].split("AC"))-1)
Problem p03274 (python)

Fixed submission:
N, K = map(int, input().split())
X = list(map(int, input().split()))
# print(X)
ans = float("inf")
for left in range(0, N-K+1):

    right = left+K

    minus = 0
    plus = 0

    if X[left] < 0:
        minus = min(minus, X[left])
    if X[right-1] > 0:
        plus = max(plus, X[right-1])

    ans = min(ans, 2*abs(minus)+plus, abs(minus)+2*plus)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))
# print(X)
ans = float("inf")
for left in range(0, N-K+1):

    right = left+K

    # print(X[left:right])

    # print(X[left:right], X[left], X[left-1])

    if right-1 < N and X[right-1] < 0 and X[right] < 0:
        continue

    if left-1 >= 0 and X[left] > 0 and X[left-1] > 0:
        break

    # print(X[left:right])
    minus = 0
    plus = 0
    for x in X[left:right]:
        if x < 0:
            minus = min(minus, x)
        elif x > 0:
            plus = max(plus, x)

    ans = min(ans, 2*abs(minus)+plus, abs(minus)+2*plus)

print(ans)
Problem p03309 (python)

Fixed submission:
from statistics import mean, median, variance, stdev

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

A2 = [a-(idx+1) for idx, a in enumerate(A)]
# print(A2, sum(A2), median(A2))

center = median(A2)

ans = 0
for a in A2:
    ans += abs(a-center)
print(int(ans))

Buggy submission (verdict: Runtime Error):
from statistics import mean, median, variance, stdev

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

A2 = [a-(idx+1) for idx, a in enumerate(A)]
# print(A2, sum(A2), median(A2))

center = median(A2)

ans = 0
for a in A2:
    ans += abs(a-center)
print(int(ans))
Problem p03544 (python)

Fixed submission:
N = int(input())

Li_2 = 2
Li_1 = 1
Li = Li_2 + Li_1
for i in range(N-1):
    Li = Li_2 + Li_1
    Li_2 = Li_1
    Li_1 = Li

if N == 1:
  print(1)
else:
  print(Li)

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

Li_2 = 2
Li_1 = 1

for i in range(N-1):
    Li = Li_2 + Li_1
    Li_2 = Li_1
    Li_1 = Li
print(Li)
Problem p03612 (python)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
count = 0
for i, p in enumerate(P):
    if p == i+1 and i == N-1:
        count += 1
    elif p == i+1:
        count += 1
        P[i] = P[i+1]
        P[i+1] = p

print(count)

Buggy submission (verdict: Runtime Error):
N = input()
A = list(map(int, input().split()))
count = 0
for i, a in enumerate(A[:-1]):
  if a == i+1:
    count += 1
    A[i+1] = a
    
peint(count)
Problem p03633 (python)

Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]
import fractions
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for i in range(N)]
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(T))
Problem p02609 (python)

Fixed submission:
def popcount(x):
    xb = bin(x)
    return xb.count("1")
def solve(x, count_1):
    temp = x %count_1
    if(temp == 0):
        return 1
    else:
        return 1 + solve(temp, popcount(temp))
n = int(input())
x = input()
x_b = int(x, 2)
mod = x.count("1")
xm1 = x_b %(mod+1)
if(mod != 1):
    xm2 = x_b %(mod-1)
for i in range(n):
    if(x[i] == "0"):
        mi = (((pow(2, n-1-i, mod+1) + xm1) % (mod+1)))
        if(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))
    else:
        if(mod == 1):
            print(0)
        else:
            mi = ((xm2-pow(2, n-1-i, mod-1)) % (mod-1))
            if((x_b - xm2 == 0)):
                print(0)
            elif(mi == 0):
                print(1)
            else:
                print(1 + solve(mi, popcount(mi)))

Buggy submission (verdict: Runtime Error):
def popcount(x):
    xb = bin(x)
    return xb.count("1")
def solve(x, count_1):
    temp = x %count_1
    if(temp == 0):
        return 1
    else:
        return 1 + solve(temp, popcount(temp))
n = int(input())
x = input()
x_b = int(x, 2)
mod = x.count("1")
xm1 = x_b %(mod+1) 
xm2 = x_b %(mod-1)
for i in range(n):
    if(x[i] == "0"):
        mi = (((pow(2, n-1-i, mod+1) + xm1) % (mod+1)))
        if(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))
    else:
        mi = ((xm2-pow(2, n-1-i, mod-1)) % (mod-1))
        if((x_b - xm2 == 0)):
            print(0)
        elif(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))

Buggy submission (verdict: Runtime Error):
def popcount(x):
    xb = bin(x)
    return xb.count("1")
def solve(x, count_1):
    temp = x %count_1
    if(temp == 0):
        return 1
    else:
        return 1 + solve(temp, popcount(temp))
n = int(input())
x = input()
x_b = int(x, 2)
mod = x.count("1")
xm1 = x_b %(mod+1) 
xm2 = x_b %(mod-1)
for i in range(n):
    if(x[i] == "0"):
        mi = (((2**(n-1-i))%(mod+1) + xm1) % (mod+1))
        if(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))
    else:
        mi = ((xm2-(2**(n-1-i))%(mod-1)) % (mod-1))
        if((x_b - xm2 == 0)):
            print(0)
        elif(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))

Buggy submission (verdict: Runtime Error):
def popcount(x):
    xb = bin(x)
    mod = 0
    for i in list(xb):
        if(i == "1"):
            mod+=1
    return mod
def solve(x, count_1):
    temp = x %count_1
    if(temp == 0):
        return 1
    else:
        return 1 + solve(temp, popcount(temp))
n = int(input())
x = input()
x_b = int(x, 2)
mod = 0
for i in list(x):
    if(i == "1"):
        mod+=1
for i in range(n):
    if(x[i] == "0"):
        mi = ((x_b+ 2**(n-1-i))%(mod+1))
        if(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))
    else:
        mi = ((x_b- 2**(n-1-i))%(mod-1))
        if(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))
Problem p02630 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
numl = [0] * 100005
resl = []
suma = sum(a)
for i in range(n):
    numl[a[i]]+=1
for i in range(q):
    b, c = map(int, input().split())
    bn = numl[b]
    suma += (c - b)* bn
    resl.append(suma)
    numl[b] -= bn
    numl[c] += bn
for i in resl:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
numl = [0] * 100000
suma = sum(a)
for i in range(n):
    numl[a[i]]+=1
for i in range(q):
    b, c = map(int, input().split())
    bn = numl[b]
    suma += (c - b)* bn
    print(suma)
    numl[c] += bn