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

Fixed submission:
import numpy as np

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(q, dtype=int)
r = np.zeros(q, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
solve(n, q, s, l, r)

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

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(n, dtype=int)
r = np.zeros(n, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
solve(n, q, s, l, r)

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

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(n, dtype=int)
r = np.zeros(n, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
print(solve(n, q, s, l, r))
Problem p03160 (python)

Fixed submission:
def solve(n, h):
    dp = [10**10] * n
    dp[n-1] = 0
    for i in range(n-1, -1, -1):
        for k in [1,2]:
            if i+k < n:
                dp[i] = min(dp[i], dp[i+k] + abs(h[i+k] - h[i]))
    return dp[0]

n = input()
h = map(int, raw_input().split())
print(solve(n, h))

Buggy submission (verdict: Runtime Error):
def solve(n, h):
    dp = [-1] * n
    dp[n-1] = 0
    def f(i):
        if dp[i] == -1:
            dp[i] = min(f(i+k) + abs(h[i+k] - h[i]) for k in [1,2] if (i+k) < n)
        return dp[i]
    return f(0)

n = input()
h = map(int, raw_input().split())
print(solve(n, h))
Problem p03241 (python)

Fixed submission:
primes = []
MAX_NUM = 100000
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num, MAX_NUM, num):
            is_prime[j] = False

def do_prime_factorization(x):
    res = {}
    for p in primes:
        if x == 1:
            break
        while x % p == 0:
            x /= p
            if not p in res:
                res[p] = 0
            res[p] += 1
    if x > 1:
        res[x] = 1
    return res.items()

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d < 0:
        return m
    p, num = ps[d]
    res = m
    for i in range(num+1):
        y = x * (p**i)
        res = min(res, f(y, d-1, n, m, ps))
    return res

def solve(n, m):
    ps = do_prime_factorization(m)
    q = f(1, len(ps)-1, n, m, ps)
    p = m // q
    return p

n, m = map(int, raw_input().split())
print(solve(n, m))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000000)

primes = []
MAX_NUM = 100000
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num, MAX_NUM, num):
            is_prime[j] = False

def do_prime_factorization(x):
    ps = []
    i = 0
    n = len(primes)
    while (x > 1) and (i < n):
        p = primes[i]
        while x % p == 0:
            x /= p
            ps.append(p)
        i += 1
    if x > 1:
        ps.append(p)
    res = {}
    for p in ps:
        if not p in res:
            res[p] = 0
        res[p] += 1
    return res

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d >= len(ps):
        return m
    p, num = ps.items()[d]
    res = m
    for i in range(num+1):
        y = x * (p**i)
        res = min(res, f(y, d+1, n, m, ps))
    return res

def solve(n, m):
    ps = do_prime_factorization(m)
    q = f(1, 0, n, m, ps)
    assert m % q == 0, (m, q)
    p = m // q
    return p

n, m = map(int, raw_input().split())
print(solve(n, m))

Buggy submission (verdict: Runtime Error):
primes = []
MAX_NUM = 100000
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num, MAX_NUM, num):
            is_prime[j] = False

def do_prime_factorization(x):
    ps = []
    i = 0
    n = len(primes)
    while (x > 1) and (i < n):
        p = primes[i]
        while x % p == 0:
            x /= p
            ps.append(p)
        i += 1
    if x > 1:
        ps.append(p)
    res = {}
    for p in ps:
        if not p in res:
            res[p] = 0
        res[p] += 1
    return res

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d >= len(ps):
        return m
    p, num = ps.items()[d]
    res = m
    for i in range(num+1):
        y = x * (p**i)
        res = min(res, f(y, d+1, n, m, ps))
    return res

def solve(n, m):
    ps = do_prime_factorization(m)
    q = f(1, 0, n, m, ps)
    assert m % q == 0, (m, q)
    p = m // q
    return p

n, m = map(int, raw_input().split())
print(solve(n, m))
Problem p03390 (python)

Fixed submission:
q=int(raw_input())
for i in range(q):
	a,b=map(int,raw_input().split())
	p=int((a*b-1)**0.5)
	if p*p>a*b-1:
		p=p-1
	r=p*2-1
	if p*p+p>a*b-1:
		r=r-1
	if a==b:
		r=r+1
	print r

Buggy submission (verdict: Runtime Error):
import numpy as np
def f(a, b):
    if a > b:
        a, b = b, a
    t = int(np.sqrt(a*b - 1))
    l = (a*b-1) / (b+1)
    r = (a*b-1) / (b-1)
    if a == b:
        return 2*t
    if (a+1) == b:
        return 2*t-2
    if t*(t+1) < a*b:
        return 2*t-1
    return 2*t-2

q = input()
for i in range(q):
    a, b = map(int, raw_input().split())
    print f(a,b)
Problem p03493 (python)

Fixed submission:
print len(filter(lambda c: c=="1", raw_input()))

Buggy submission (verdict: Runtime Error):
import numpy as np
n = input()
a = map(int, raw_input().split())
max_i = np.argmax(a)
min_i = np.argmin(a)
ans = []
if abs(a[max_i]) >= abs(a[min_i]):
    for i in range(n):
        ans.append((max_i, i))
    for i in range(n-1):
        ans.append((i, i+1))
else:
    for i in range(n):
        ans.append((min_i, i))
    for i in range(n-1, 0, -1):
        ans.append((i, i-1))
print len(ans)
for x, y in ans:
    print (x+1), (y+1)

Buggy submission (verdict: Runtime Error):
import numpy as np
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    M = len(numbers)
    if M <= K:
        return 0
    dp = np.full((M+1, M+1), N, dtype=int)
    dp[0,:] = 0
    for i, n in enumerate(numbers.values()):
        for j in range(M+1):
            if j > 0:
                dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
            else:
                dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
    return min(dp[M,:K+1])

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
print solve(N, K, A)
Problem p03495 (python)

Fixed submission:
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    if len(numbers) <= K:
        return 0
    return N - sum(sorted(numbers.values(), key=lambda x: -x)[:K])
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
print solve(N, K, A)

Buggy submission (verdict: Runtime Error):
import numpy as np
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    M = len(numbers)
    if M <= K:
        return 0
    dp = np.full((M+1, M+1), N, dtype=int)
    dp[0,:] = 0 
    for i, n in enumerate(numbers.values()):
        for j in range(M+1):
            if j > 0:           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
            else:                           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
    return min(dp[M,:K+1])                          
                                                        
N, K = map(int, raw_input().split())                            
A = map(int, raw_input().split())                                           
print solve(N, K, A)

Buggy submission (verdict: Runtime Error):
import numpy as np
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    M = len(numbers)
    if M <= K:
        return 0
    dp = np.full((M+1, M+1), N, dtype=in
    dp[0,:] = 0 
    for i, n in enumerate(numbers.values()):
        for j in range(M+1):
            if j > 0:           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
            else:                           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
    return min(dp[M,:K+1])                          
                                                        
N, K = map(int, raw_input().split())                            
A = map(int, raw_input().split())                                           
print solve(N, K, A)

Buggy submission (verdict: Runtime Error):
import numpy as np
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    M = len(numbers)
    if M <= K:
        return 0
    dp = np.full((M+1, M+1), N)
    dp[0,:] = 0
    for i, n in enumerate(numbers.values()):
        for j in range(M+1):
            if j > 0:
                dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
            else:
                dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
    return min(dp[M,:K+1])

if __name__ == "__main__":
    N, K = map(int, raw_input().split())
    A = map(int, raw_input().split())
    print solve(N, K, A)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
numbers = {}
for a in A:
    numbers[a] = numbers.get(a, 0) + 1
M = len(numbers)
dp = np.full((M+1, M+1), N)
dp[0,:] = 0
for i, n in enumerate(numbers.values()):
    for j in range(M+1):
        if j > 0:
            dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
        else:
            dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
print min(dp[M,:K+1])
Problem p03599 (python)

Fixed submission:
EPS = 1E-8
def solve(a, b, c, d, e, f):
    threshold = e / (100 + e) + EPS
    best = -1
    for x in range(0, f+1, 100*a):
        for y in range(x, f+1, 100*b):
            if y == 0:
                continue
            for z in range(y, f+1, c):
                for w in range(z, f+1, d):
                    p = w - y
                    cur = p / w
                    if best < cur <= threshold:
                        best = cur
                        solution = (w, p)
    return "%d %d" % solution

a, b, c, d, e, f = map(int, input().split())
print(solve(a, b, c, d, e, f))

Buggy submission (verdict: Runtime Error):
def solve(a, b, c, d, e, f):
    S = set()
    for x in range(0, f, 100*a):
        for y in range(0, f, 100*b):
            z = x + y
            if 0 < z <= f:
                S.add(z)
    T = set()
    for x in range(0, f, c):
        for y in range(0, f, d):
            z = x + y
            if z <= f:
                T.add(z)
    threshold = e / (100 + e)
    best = 0
    solution = None
    for x in S:
        for y in T:
            z = x + y
            cur = y / z
            if (best < cur <= threshold) and (z <= f):
                best = cur
                solution = (z, y)
    return "%d %d" % solution

a, b, c, d, e, f = map(int, input().split())
print(solve(a, b, c, d, e, f))
Problem p03609 (python)

Fixed submission:
X, t = map(int, raw_input().split())
print max(X-t, 0)

Buggy submission (verdict: Runtime Error):
print max(X-t, 0)
Problem p03646 (python)

Fixed submission:
def f(k):
    n = 50
    a = [k//n + n-1] * n
    for i in range(k%n):
        for j in range(n):
            if i == j:
                a[j] += n
            else:
                a[j] -= 1
    return a

def solve(k):
    a = f(k)
    print(len(a))
    print(" ".join(map(str, a)))

solve(k=int(input()))

Buggy submission (verdict: Runtime Error):
def f(k):
    if k == 0:
        return [0,0]
    elif k == 1:
        return [2,0]
    elif k == 2:
        return [2,1]
    else:
        return [k//2, k-k//2]
def solve(k):
    a = f(k)
    print(len(a))
    print(" ".join(map(str, a))
solve(k=int(input()))

Buggy submission (verdict: Runtime Error):
def solve(k):
    print(2)
    print(f"0 {k}")
solve(k=int(input()))
Problem p03682 (python)

Fixed submission:
import numpy as np

def solve(n, x, y):
    def dist(i, j):
        return min(abs(x[i]-x[j]), abs(y[i]-y[j]))
    que = []
    for p in map(np.argsort, [x, y]):
        for i in range(n-1):
            u, v = p[i], p[i+1]
            que.append((u, v, dist(u, v)))
    parent = [i for i in range(n)]
    def find(i):
        if parent[i] == i:
            return i
        else:
            j = find(parent[i])
            parent[i] = j
            return j
    ans = 0
    for u, v, d in sorted(que, key=lambda _: _[2]):
        u = find(u)
        v = find(v)
        if u != v:
            ans += d
            if u > v:
                u, v = v, u
            parent[v] = u
    return ans

n = int(input())
x = np.zeros(n, dtype=int)
y = np.zeros(n, dtype=int)
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))

Buggy submission (verdict: Runtime Error):
import numpy as np
def solve(n, x, y):
    def dist(i, j):
        return min(abs(x[i]-x[j]), abs(y[i]-y[j]))
    que = []
    for v in [x, y]:
        p = np.argsort(v)
        for i in range(n-1):
            u, v = p[i], p[i+1]
            que.append((u, v, dist(u, v)))
    parent = {i: i for i in range(n)}
    def find(i):
        if parent[i] == i:
            return i
        else:
            j = find(parent[i])
            parent[i] = j
            return j
    ans = 0
    for u, v, d in sorted(que, key=lambda _: _[2]):
        u = find(u)
        v = find(v)
        if u != v:
            ans += d
            parent[u] = v
    return ans

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))

Buggy submission (verdict: Runtime Error):
from collections import deque
import numpy as np
def solve(n, x, y):
    def dist(i, j):
        return min(abs(x[i]-x[j]), abs(y[i]-y[j]))
    que = []
    for v in [x, y]:
        p = np.argsort(v)
        for i in range(n-1):
            u, v = p[i], p[i+1]
            que.append((u, v, dist(u, v)))
    parent = {i: i for i in range(n)}
    def find(i):
        if parent[i] == i:
            return i
        else:
            j = find(parent[i])
            parent[i] = j
            return j
    que = deque(sorted(que, key=lambda _: _[2]))
    ans = 0
    while que:
        u, v, d = que.popleft()
        u = find(u)
        v = find(v)
        if u != v:
            ans += d
            parent[u] = v
    return ans

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
print(solve(n, x, y))
Problem p03777 (python)

Fixed submission:
a, b = raw_input().split()
print "H" if (a == "H" and b == "H") or (a == "D" and b == "D") else "D"

Buggy submission (verdict: Runtime Error):
W, a, b = map(int, raw_input().split())
print min(abs(b-a-W), abs(b-a), abs(b+W-a), abs(b-a))
Problem p03778 (python)

Fixed submission:
W, a, b = map(int, raw_input().split())
if (a+W-b) * (a-b-W) < 0:
    print 0
else:
    print min(abs(b-a-W), abs(b-a), abs(b+W-a), abs(b-a))

Buggy submission (verdict: Runtime Error):
print min(abs(b-a-W), abs(b-a), abs(b+W-a), abs(b-a))
Problem p03853 (python)

Fixed submission:
H, W = map(int, raw_input().split())
for i in range(H):
    s = raw_input()
    print s
    print s

Buggy submission (verdict: Runtime Error):
H, W = map(int, raw_input().split())
for i in range(W):
    s = raw_input()
    print s
    print s
Problem p03880 (python)

Fixed submission:
def solve(n, a):
    """
    References
    ----------
    [1]. 足跡-sokuseki-, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://wk1080id.hatenablog.com/entry/2018/08/17/234023
    [2]. iroiro, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://xxxasdfghjk999.hatenablog.jp/entry/2018/11/01/235259
    [3]. Yang33, 競プロにおけるNim、Grundy数とNimK, http://yang33-kassa.hatenablog.com/entry/2017/12/21/202812
    """
    x = 0
    for i in range(n):
        x ^= a[i]
    b = [a[i] ^ (a[i] - 1) for i in range(n)]
    mapping = {2**k-1: 0 for k in range(31)}
    for y in b:
        mapping[y] += 1
    ans = 0
    for k in range(30, 0, -1):
        y = 2**k - 1
        z = 2**(k-1)
        if (x & z) > 0 and (mapping[y] > 0):
            ans += 1
            mapping[y] -= 1
            x ^= y
    return ans if x == 0 else -1

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

Buggy submission (verdict: Runtime Error):
def solve(n, a):
    """
    References
    ----------
    [1]. 足跡-sokuseki-, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://wk1080id.hatenablog.com/entry/2018/08/17/234023
    [2]. iroiro, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://xxxasdfghjk999.hatenablog.jp/entry/2018/11/01/235259
    [3]. Yang33, 競プロにおけるNim、Grundy数とNimK, http://yang33-kassa.hatenablog.com/entry/2017/12/21/202812
    """
    x = 0
    for i in range(n):
        x ^= a[i]
    b = [a[i] ^ (a[i] - 1) for i in range(n)]
    mapping = {2**k-1: 0 for k in range(30)}
    for y in b:
        mapping[y] += 1
    ans = 0
    for k in range(30, 0, -1):
        y = 2**k - 1
        z = 2**(k-1)
        if (x & z) > 0 and (mapping[y] > 0):
            ans += 1
            mapping[y] -= 1
            x ^= y
    return ans if x == 0 else -1

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))
Problem p04013 (python)

Fixed submission:
N, A = map(int, raw_input().split())
x = [v - A for v in map(int, raw_input().split())]
dp = {}
def dfs(i, W):
    if i < 0:
        return int(W == 0)
    if (i, W) in dp:
        return dp[i, W]
    dp[i, W] = dfs(i-1, W) + dfs(i-1, W-x[i])
    return dp[i, W]
print dfs(N-1, 0) - 1

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

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())
dp = np.full((N+1, A+1, (N+1)*(A+1)), -1)
def dfs(i, t, W):
    if t == 0:
        return int(W == 0)
    if i < 0:
        return 0
    if dp[i, t, W] > -1:
        return dp[i, t, W]
    dp[i, t, W] = dfs(i-1, t, W) + dfs(i-1, t-1, W-x[i])
    return dp[i, t, W]
print sum([dfs(N-1, T, T*A) for T in range(1, N+1)])
Problem p04016 (python)

Fixed submission:
import numpy as np
def f(b, n):
    s = 0
    while n > 0:
        s += n % b
        n //= b
    return s

INF = 10**15
def solve(n, s):
    if n == s:
        return n+1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m+1):
        if f(b, n) == s:
            return b
    best = INF
    for p in range(1, m+10):
        q = s - p
        b = (n - q) // p
        if (b > p) and (b > q) and (f(b, n) == s):
            best = min(best, b)
    return -1 if (best == INF) else best

n = int(input())
s = int(input())
print(solve(n, s))

Buggy submission (verdict: Runtime Error):
import numpy as np
def f(b, n):
    s = 0
    while n > 0:
        s += n % b
        n //= b
    return s

INF = int("inf")
def solve(n, s):
    if n < s:
        return -1
    if n == s:
        return n+1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m+1):
        if f(b, n) == s:
            return b
    best = INF
    for p in range(1, m+1):
        q = s - p
        if (n - q) % p != 0:
            continue
        b = (n - q) // p
        if (b > 1) and (f(b, n) == s):
            best = min(best, s)
    return -1 if (best == INF) else best

n = int(input())
s = int(input())
print(solve(n, s))

Buggy submission (verdict: Runtime Error):
import numpy as np
def f(b, n):
    if n < b:
        return n
    else:
        n2 = n // b
        if n2 == n:
            return -1
        else:
            return f(b, n2) + (n % b)

def solve(n, s):
    if s == n:
        return n + 1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m):
        if f(b, n) == s:
            return b
    for p in range(1, m):
        q = s - p
        if (n - q) % p != 0:
            continue
        b = (n - q) // p
        if f(b, n) == s:
            return b
    return -1

n = int(input())
s = int(input())
print(solve(n, s))
Problem p04020 (python)

Fixed submission:
def solve(n, a):
    res, total = 0, 0
    for x in a:
        if x == 0:
            res += total // 2
            total = 0
        else:
            total += x
    return res + total // 2

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

Buggy submission (verdict: Runtime Error):
def solve(n, a):
    res = 0
    for i in range(n-1):
        b = min(a[i], a[i+1])
        res += b
        a[i] -= b
        a[i+1] -= b
        if a[i] > 0:
            res += a[i] // 2
    if a[-1] > 0:
        res += a[i] // 2
    return res

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))
Problem p02609 (python)

Fixed submission:
#2回目以降のあまりを計算
def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

N = int(input())
S = input()

#入力を数値に変換
X = int(S, 2)

#元のbit数をカウント
pcx = S.count("1")
#bit数は-1, +1のみなので予め計算しておく
#カウントが0ならば0にしておく
pc1 = X % (pcx - 1) if pcx > 1 else 0
pc2 = X % (pcx + 1)

for i, y in enumerate(S):
    k = N - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

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

for i in range(N):
    x = X.copy()
    cnt = 0
    x[i] = str(int(x[i])^1)
    n = int("".join(x), 2)

    while n>0:
        n = n%popcnt3(n)
        cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

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

for i in range(N):
    x = X.copy()
    cnt = 0
    x[i] = str(int(x[i])^1)
    n = int("".join(x), 2)

    while n>0:
        n = n%popcnt3(n)
        cnt += 1
    print(cnt)