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

Fixed submission:
print("2018"+input()[4:])

Buggy submission (verdict: Runtime Error):
n,Y = map(int,input().split())
x = -1
y = -1
z = -1

for i in range(Y//10000 + 1):
    for j in range(n-i+1):
        if 9*i + 4*j == Y/1000 - n:
            x = i
            y = j
            z = n-i-j
print(x,y,z)
Problem p03493 (python)

Fixed submission:
a,b,c=input();print(int(a)+int(b)+int(c))

Buggy submission (verdict: Runtime Error):
a,b,c=int(input());print(a+b+c)
Problem p03543 (python)

Fixed submission:
a,b,c,d = input()

if (a == b and b == c) or (b == c and c == d):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
num = list(range(100))
num[0] = 2
num[1] = 1
n = int(input())

for i in range(2,n+1):
    num[i] = num[i-2] + num[i-1]

print(num[n])
Problem p03544 (python)

Fixed submission:
num = list(range(87))
num[0] = 2
num[1] = 1

for i in range(2,87):
    num[i] = num[i-2] + num[i-1]

print(num[int(input())])

Buggy submission (verdict: Runtime Error):
num = list(range(86))
num[0] = 2
num[1] = 1

for i in range(2,86):
    num[i] = num[i-2] + num[i-1]

print(num[int(input())])
Problem p03545 (python)

Fixed submission:
s=input()
n = 2**(len(s)-1)
ans=""

for i in range(n):
    t = ""
    a = str(bin(i))[2:].zfill(len(s)-1)
    for j in range(len(a)):
        if a[j] == "1":
            t += s[j] + "+"
        else:
            t += s[j] + "-"
    t += s[-1]
    if eval(t)==7:
        ans = t + "=7"
        break
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
n = 2**(len(s)-1)
ans=""

for i in range(n):
    t = ""
    a = str(bin(i))[2:].zfill(len(s)-1)
    for j in range(len(a)):
        if a[j] == "1":
            t += s[j] + "+"
        else:
            t += s[j]
    t += s[-1]
    if eval(t)==7:
        ans = t + "=7"
        break
print(ans)
Problem p03565 (python)

Fixed submission:
s = input()
t = input()
num_s = len(s)
num_t = len(t)
idx_t = []

def match(s,i):
	if s[i] in (t[0],'?'):
		for j in range(num_t):
			if s[i+j] not in (t[j],'?'):
				return '!'
		return i
	else:
		return '!'

for i in range(num_s-num_t+1):
	idx = match(s,i)
	if idx != '!':
		idx_t.append(idx)

if len(idx_t) == 0:
	print('UNRESTORABLE')
else:
	s0 = s
	s_l = []
	for i in idx_t:
		if i == 0:
			s1 = t + s0[num_t:]
		elif i != num_s-num_t:
		  s1 = s0[:i] + t + s0[i+num_t:]
		else:
			s1 = s0[:i] + t
		s_l.append(s1)
	ans = min(s_l)
	print(ans.replace('?','a',100))

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
num_s = len(s)
num_t = len(t)
idx_t = []

def match(s,i):
	if s[i] == t[0]:
		for j in range(num_t):
			if s[i+j] not in (t[j],'?'):
				return False
		else:
			return i
	else:
		return False

for i in range(num_s-num_t+1):
	idx = match(s,i)
	if idx != False:
		idx_t.append(idx)

if len(idx_t) == 0:
	print('UNRESTORABLE')
else:
	s0 = s
	s_l = []
	for i in idx_t:
		if i+num_t < num_s:
		  s0 = s0[:i] + t + s0[i+t:]
		else:
			s0 = s0[:i] + t
		s_l.append(s0)
	ans = min(s_l)
	print(ans.replace('?','a',100))
Problem p03578 (python)

Fixed submission:
n=int(input())
d=sorted(map(int,input().split()))
m=int(input())
t=sorted(map(int,input().split()))

d_dic = dict()
t_dic = dict()

for i in range(n):
    d1 = d[i]
    if d1 not in d_dic.keys():
        d_dic[d1] = 1
    else:
        d_dic[d1] += 1

ans = 0

for i in range(m):
    t1 = t[i]
    if t1 in d_dic.keys():
        d_dic[t1] -= 1
        if d_dic[t1] < 0:
            ans = 1
            break
    else:
        ans = 1
        break
    
if ans == 1:
    print("NO")
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
n=int(input())
d=sorted(map(int,input().split()))
m=int(input())
t=sorted(map(int,input().split()))

d_dic = dict()
t_dic = dict()

for i in range(n):
    d1 = d[i]
    if d1 not in d_dic.keys():
        d_dic[d1] = 1
    else:
        d_dic[d1] += 1
for i in range(m):
    t1 = t[i]
    if t1 not in t_dic.keys():
        t_dic[t1] = 1
    else:
        t_dic[t1] += 1

ans = 0

for i in t_dic.keys():
    if t_dic[i] > d_dic[i]:
        ans = 1
        break

if ans == 1:
    print("NO")
else:
    print("YES")
Problem p03633 (python)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

n=int(input())
t0=int(input())
if n==1:
    print(t0)
else:
    t1=int(input())
    t_lcm=lcm(t0,t1)
    for i in range(n-2):
        t2=int(input())
        t_lcm=lcm(t_lcm,t2)
    print(t_lcm)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

n=int(input())
t0=int(input())
t1=int(input())
t_lcm=lcm(t0,t1)
for i in range(n-2):
    t2=int(input())
    t_lcm=lcm(t_lcm,t2)
print(t_lcm)
Problem p03699 (python)

Fixed submission:
n=int(input())
S=sorted([int(input()) for _ in range(n)])
ans=sum(S)
i=0
while S!=[] and ans%10==0:
    for s in S:
        if (ans-s)%10!=0:
            ans-=s
            break
    if ans%10==0:ans-=S.pop(0)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
S=sorted([int(input()) for _ in range(n)])
ans=sum(S)
i=0
while ans%10 == 0:
    ans-=S[i]
    i+=1
print(ans)
Problem p03760 (python)

Fixed submission:
o = list(input())
e = list(input()) + [""]

for x,y in zip(o,e):print(x + y, end = "")

Buggy submission (verdict: Runtime Error):
O = input()
E = input()

for i in range(len(O)):
    print(O[i] + E[i], end="")

Buggy submission (verdict: Runtime Error):
O = input()
E = input()

for i in range(len(a)):
    print(O[i] + E[i], end="")
Problem p03854 (python)

Fixed submission:
s = input()[::-1]
l = [ 'dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
	s1 = l[i][::-1]
	l[i] = s1

n = len(s)
i = 0
t = tuple(l)

while i < n:
	judge = 0
	s_l = []
	for j in (5,6,7):
		if n-i >= j:
			s1 = s[i:i+j]
			if s1 in t:
				i += j
				judge = 1
	
	if judge == 0:
		break

if i == n:
	print('YES')
else:
	print('NO')

Buggy submission (verdict: Runtime Error):
from collections import deque
s = input()
n = len(s)

deque = deque()
deque.append(0)

def str_plus(i):
    s1 = s[i]
    if s1 == "d":
        if s[i:i+5] == "dream":
            if s[i+5:i+7] == "er":
                return [i+5,i+7]
            else:
                return [i+5]
    if s1 == "e":
        if s[i:i+5] == "erase":
            if s[i+5] == "r":
                return [i+5,i+6]
            else:
                return [i+5]

ans = "NO"

while deque:
    i = deque.pop()
    if i == n:
        ans = "YES"
        break
    l = str_plus(i)
    if l != None:
        deque.extend(l)

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
str_l = ["dream", "dreamer", "erase" ,"eraser"]
s = input()
n = len(s)

deque = deque()
deque.append(0)

def str_plus(i):
    s1 = s[i]
    if s1 == "d":
        if s[i:i+5] == "dream":
            if s[i+5:i+7] == "er":
                return [i+5,i+7]
            else:
                return [i+5]
        else:
            return False
    if s1 == "e":
        if s[i:i+5] == "erase":
            if s[i+5] == "r":
                return [i+5,i+6]
            else:
                return [i+5]
        else:
            return False

ans = "NO"

while deque:
    i = deque.pop()
    if i == n:
        ans = "YES"
        break
    l = str_plus(i)
    if l != False and l != None:
        deque.extend(l)

print(ans)
Problem p02687 (python)

Fixed submission:
s=input()
if(s=="ABC"):
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
s=input()
if(s=="ABC"):
  print("ARC")
 else:
  print("ABC")
Problem p03035 (python)

Fixed submission:
line = input().split()
a = int(line[0])
b = int(line[1])


if a >= 0 and a <= 5:
    print(0)
if a >= 6 and a <= 12:
    print(b//2)
if a >= 13 and a <= 100:
    print(b)

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

if a >= 0 and a <= 5:
    print(0)
if a >= 6 and a <= 12:
    print(b//2)
if a >= 16 and a <= 100:
    print(b)

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

if 0 <= a <= 5:
    print(0)
if 6 <= a <= 12:
    print(b//2)
if 16 <= a <= 100:
    print(b)
Problem p02909 (python)

Fixed submission:
s = input()
 
if s == "Sunny":
  	print("Cloudy")
elif s == "Cloudy":
  	print("Rainy")
else:
  	print("Sunny")

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

if s == "Sunny":
  	print("Cloudy")
else if s == "Cloudy":
  	print("Rainy")
else:
  	print("Sunny")
Problem p02910 (python)

Fixed submission:
s = input()
 
for i in range(len(s)):
  if (i % 2 == 0 and s[i] == 'L') or (i % 2 == 1 and s[i] == 'R'):
    print("No")
    exit()

print("Yes")

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

for i in range(s.len()):
  if (i % 2 == 0 and s[i] == 'L') or (i % 2 == 1 and s[i] == 'R'):
    print("No")
    exit()

print("Yes")
Problem p02993 (python)

Fixed submission:
s = input()

flag = False

for i in range(1, 4):
    if s[i - 1] == s[i]:
        flag = True
        break

if flag:
    print("Bad")
else:
    print("Good")

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

flag = False

for i in range(4):
    if s[i] == s[i + 1]:
        flag = True
        break

if flag:
    print("Bad")
else:
    print("Good")
Problem p02994 (python)

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

taste_list = []

dis_min = 1000000000

for i in range(n):
    taste = l + i
    taste_list.append(taste)
    if abs(taste) < abs(dis_min):
        dis_min = taste

print(sum(taste_list) - dis_min)

Buggy submission (verdict: Runtime Error):
n, l = map(int, input().split())
 
total = 0
min_taste = 1000000000
 
for i in range(n):
    taste = l + i
    total += taste
    if abs(taste) < abs(min_taste):
        min_taste = taste
 
print(total - dis_min)
Problem p02690 (python)

Fixed submission:
def main():
    X=int(input())
    start=0
    back=-1
    while(True):
        back=X-pow(start,5)
        if back>0:
            A_back=int(pow(back,1/5))
        else:
            A_back=-int(pow(-back,1/5))

        front=X+pow(start,5)
        if front>0:
            A_front=int(pow(front,1/5))
        else:
            A_front=-int(pow(-front,1/5))
        if(pow(A_back,5)==back):
            A=A_back
            B=-start
            break
        elif(pow(A_front,5)==front):
            A=A_front
            B=start
            break
        else:
            start+=1
    print(A,B)
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    X=int(input())
    start=0
    while(True):
        back=X-pow(start,5)
        A_back=int(pow(back,1/5))

        front=X+pow(start,5)
        A_front=int(pow(front,1/5))
        if(pow(A_back,5)==back):
            A=A_back
            B=-start
            break
        elif(pow(A_front,5)==front):
            A=A_front
            B=start
            break
        else:
            start+=1
    print(A,B)
if __name__=='__main__':
    main()
Problem p02696 (python)

Fixed submission:
def f(A,B,x):
    return (((A*x)//B)-(A*(x//B)))
def main():
    A,B,N=map(int,input().split())
    x=min(N,B-1)
    print(f(A,B,x))
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def f(A,B,x):
    return (((A*x)//B)-(A*(x//B)))
def main():
    A,B,N=map(int,input().split())
    lb=1
    ub=min(B-1,N)
    while(lb<=ub):
        mid=(lb+ub)//2
        if f(A,B,mid)<N:
            lb=mid+1
        elif f(A,B,mid)>N:
            ub=mid-1
        else:
            break
    print(f(A,B,mid))
if __name__=='__main__':
    main()
Problem p02717 (python)

Fixed submission:
numbers = input().split()
numbers = list(map(int, numbers))
a = numbers[0]
b = numbers[1]
c = numbers[2]

temp = a
a = b
b = temp

temp = a
a = c
c = temp

print(str(a) + " " + str(b) + " " + str(c))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
#swapping a and b
temp = a
a = b
b = temp

#swapping a and c
temp = a
a = c
c = temp

print(str(a)+"␣"+str(b)+"␣"+str(c))
Problem p02573 (python)

Fixed submission:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().rstrip().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

def dfs(x):
    stack = [x]
    visited = 0
    checked[x] = 1
    while stack:
        visited += 1
        node = stack.pop()
        for i in graph[node]:
            if checked[i] == 0:
                stack.append(i)
                checked[i] = 1
    return visited
 
n, m = inm()
checked = [0] * (n+1)
graph = {}
for i in range(m):
    a, b = inm()
    if a not in graph:
        graph[a] = set()
    if b not in graph:
        graph[b] = set()
    graph[a].add(b)
    graph[b].add(a)
ans = 1
for i in graph:
    if checked[i] == 0:
        ans = max(ans, dfs(i))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

def dfs(x):
    stack = [x]
    visited = []
    if checked[x] == 1:
        return 0
    while stack:
        node = stack.pop()
        if node not in visited:
            visited.append(node)
            checked[node] = 1
            for i in graph[node]:
                stack.append(i)
                checked[i] = 1
    return len(visited)

n, m = inm()
checked = [0] * (n+1)
graph = {}
for i in range(m):
    a, b = inm()
    if a not in graph:
        graph[a] = []
    if b not in graph:
        graph[b] = []
    graph[a].append(b)
    graph[b].append(a)
ans = 0
for i in range(1, n+1):
    if checked[i] == 0:
        ans = max(ans, dfs(i))
print(ans)
Problem p03246 (python)

Fixed submission:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
if len(set(a)) == n:
    print(n - 2)
elif len(set(a)) == 1:
    print(n//2)
else:
    f = {}
    s = {}
    for i in range(n):
        if i % 2 == 0:
            if a[i] not in f:
                f[a[i]] = 0
            f[a[i]] += 1
        else:
            if a[i] not in s:
                s[a[i]] = 0
            s[a[i]] += 1
    fsum = sum(f.values())
    ssum = sum(s.values())
    f = sorted(f.items(), key=lambda x: x[1], reverse=True)
    s = sorted(s.items(), key=lambda x: x[1], reverse=True)
    if f[0][0] == s[0][0]:
        tmp1 = fsum - f[0][1] + ssum - s[1][1]
        tmp2 = fsum - f[1][1] + ssum - s[0][1]
        print(min(tmp1, tmp2))
    else:
        print(fsum - f[0][1] + ssum - s[0][1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
if len(set(a)) == n:
    print(n - 2)
elif len(set(a)) == 1:
    print(n//2)
else:
    f = {}
    s = {}
    for i in range(n):
        if i % 2 == 0:
            if a[i] not in f:
                f[a[i]] = 0
            f[a[i]] += 1
        else:
            if a[i] not in s:
                s[a[i]] = 0
            s[a[i]] += 1
    fsum = sum(f.values())
    ssum = sum(s.values())
    f = sorted(f.items(), key=lambda x: x[1], reverse=True)
    s = sorted(s.items(), key=lambda x: x[1], reverse=True)
    if f[0][0] == s[0][0]:
        tmp1 = fsum - f[0][1] + ssum - s[0][2]
        tmp2 = fsum - f[0][2] + ssum - s[0][1]
        print(min(tmp1, tmp2))
    else:
        print(fsum - f[0][1] + ssum - s[0][1])
Problem p02609 (python)

Fixed submission:
'''Author- Akshit Monga'''
n=int(input())
x=input()
x=x[::-1]
ans1=0
ans2=0
c=x.count('1')
for i in range(0,n):
    if x[i]=='1':
        ans1=(ans1+pow(2,i,c+1))%(c+1)
        if c!=1:
            ans2=(ans2+pow(2,i,c-1))%(c-1)
to_print=[]
for i in range(0,n):
    if x[i]=='1':
        if c==1:
            to_print.append(0)
            continue
        var=(ans2%(c-1)-pow(2,i,c-1))%(c-1)
        a = 1
        while var:
            var = var % bin(var).count('1')
            a += 1
        to_print.append(a)
    else:
        # print(ans1)
        var = (ans1%(c+1) + pow(2, i, c +1))%(c+1)
        # print(c+1)
        # print(var)
        a = 1
        while var:
            var = var % bin(var).count('1')
            a += 1
        to_print.append(a)
for i in to_print[::-1]:
    print(i)

Buggy submission (verdict: Runtime Error):
'''Author- Akshit Monga'''
n=int(input())
x=input()
x=x[::-1]
ans1=0
ans2=0
c=x.count('1')
for i in range(0,n):
    if x[i]:
        ans1=(ans1+pow(2,i,c+1))%(c+1)
        ans2=(ans2+pow(2,i,c-1))%(c-1)
to_print=[]
for i in range(0,n):
    if x[i]=='1':
        if c==1:
            to_print.append(0)
            continue
        var=(ans2%(c-1)-pow(2,i,c-1))%(c-1)
        a = 1
        while var:
            var = var % bin(var).count('1')
            a += 1
        to_print.append(a)
    else:
        # print(ans1)
        var = (ans1%(c+1) + pow(2, i, c +1))%(c+1)
        # print(c+1)
        # print(var)
        a = 1
        while var:
            var = var % bin(var).count('1')
            a += 1
        to_print.append(a)
for i in to_print[::-1]:
    print(i)
Problem p02553 (python)

Fixed submission:
def get_ints() :
  return list(map(int,input().split()))

a,b,c,d=get_ints()
ans=max(a*c,b*c,a*d,b*d)
print(ans)

Buggy submission (verdict: Runtime Error):
def get_ints() :
  list(map(int,input().split()))

a,b,c,d=get_ints()
ans=max(a*c,b*c,a*d,b*d)
print(ans)
Problem p02586 (python)

Fixed submission:
R, C, K=map(int, input().split())
math=[[0]*C for _ in range(R)]
for _ in range(K):
  r, c, v=map(int, input().split())
  math[r-1][c-1]=v
  
dp=[[[0]*C for __ in range(R)] for _ in range(4)]
if math[0][0]>0:
  dp[1][0][0]=math[0][0]+0
  
for j in range(1, C):
  dp[0][0][j]=dp[0][0][j-1]+0
  dp[1][0][j]=max(dp[1][0][j-1], dp[0][0][j-1]+math[0][j])
  dp[2][0][j]=max(dp[2][0][j-1], dp[1][0][j-1]+math[0][j])
  dp[3][0][j]=max(dp[3][0][j-1], dp[2][0][j-1]+math[0][j])
    
for i in range(1, R):
  dp[0][i][0]=max(dp[0][i-1][0], dp[1][i-1][0], dp[2][i-1][0], dp[3][i-1][0])
  dp[1][i][0]=dp[0][i][0]+math[i][0]
  for j in range(1, C):
    dp[0][i][j]=max(dp[0][i][j-1], max(dp[0][i-1][j], dp[1][i-1][j], dp[2][i-1][j], dp[3][i-1][j]))
    dp[1][i][j]=max(dp[1][i][j-1], dp[0][i][j-1]+math[i][j], max(dp[0][i-1][j], dp[1][i-1][j], dp[2][i-1][j], dp[3][i-1][j])+math[i][j])
    dp[2][i][j]=max(dp[2][i][j-1], dp[1][i][j-1]+math[i][j])
    dp[3][i][j]=max(dp[3][i][j-1], dp[2][i][j-1]+math[i][j])
    
print(max(dp[0][-1][-1], dp[1][-1][-1], dp[2][-1][-1], dp[3][-1][-1]))

Buggy submission (verdict: Runtime Error):
R, C, K=map(int, input().split())
math=[[0]*C for _ in range(R)]
for _ in range(K):
  r, c, v=map(int, input().split())
  math[r-1][c-1]=v
  
dp=[[[0]*C for __ in range(R)] for _ in range(4)]
if math[0][0]>0:
  dp[1][0][0]=math[0][0]+0
  
for j in range(1, C):
  dp[0][0][j]=dp[0][j-1][0]+0
  dp[1][0][j]=max(dp[1][0][j-1], dp[0][0][j-1]+math[0][j])
  dp[2][0][j]=max(dp[2][0][j-1], dp[1][0][j-1]+math[0][j])
  dp[3][0][j]=max(dp[3][0][j-1], dp[2][0][j-1]+math[0][j])
    
for i in range(1, R):
  dp[0][i][0]=max(dp[0][i-1][0], dp[1][i-1][0], dp[2][i-1][0], dp[3][i-1][0])
  dp[1][i][0]=dp[0][i][0]+math[i][0]
  for j in range(1, C):
    dp[0][i][j]=max(dp[0][i][j-1], max(dp[0][i-1][j], dp[1][i-1][j], dp[2][i-1][j], dp[3][i-1][j]))
    dp[1][i][j]=max(dp[1][i][j-1], dp[0][i][j-1]+math[i][j], max(dp[0][i-1][j], dp[1][i-1][j], dp[2][i-1][j], dp[3][i-1][j])+math[i][j])
    dp[2][i][j]=max(dp[2][i][j-1], dp[1][i][j-1]+math[i][j])
    dp[3][i][j]=max(dp[3][i][j-1], dp[2][i][j-1]+math[i][j])
    
print(max(dp[0][-1][-1], dp[1][-1][-1], dp[2][-1][-1], dp[3][-1][-1]))
Problem p02609 (python)

Fixed submission:
def f(n):
  c=0
  while n>0:
    n%=format(n, 'b').count('1')
    c+=1
  return c

N=int(input())
X=input()
nums=[0]+[f(i) for i in range(1, N+1)]

a=0
b=0
for i in range(N):
  if X[i]=='0':
    a+=1
  else:
    b+=1

s=0
t=0
if b>1:
  for i in range(N):
    s=(s+int(X[i])*pow(2, N-1-i, b+1))%(b+1)
    t=(t+int(X[i])*pow(2, N-1-i, b-1))%(b-1)
else:
  for i in range(N):
    s=(s+int(X[i])*pow(2, N-1-i, b+1))%(b+1)
    
if b==1:
  for i in range(N):
    if X[i]=='0':
      tmp=(s+pow(2, N-1-i, b+1))%(b+1)
      print(nums[tmp]+1)
    else:
      print(0)
  exit()

for i in range(N):
  if X[i]=='0':
    tmp=(s+pow(2, N-1-i, b+1))%(b+1)
    print(nums[tmp]+1)
  else:
    tmp=(t-pow(2, N-1-i, b-1))%(b-1)
    print(nums[tmp]+1)

Buggy submission (verdict: Runtime Error):
def f(n):
  if n==0:
    return 0
  c=0
  while n>0:
    n%=format(n, 'b').count('1')
    c+=1
  return c

N=int(input())
X=input()
nums=[f(i) for i in range(N+1)]

a=0
b=0
for i in range(N):
  if X[i]=='0':
    a+=1
  else:
    b+=1

s=0
t=0
for i in range(N):
  s=(s+int(X[i])*pow(2, N-1-i, b+1))%(b+1)
  t=(t+int(X[i])*pow(2, N-1-i, b-1))%(b-1)

for i in range(N):
  if X[i]=='0':
    tmp=(s+pow(2, N-1-i, b+1))%(b+1)
    print(nums[tmp]+1)
  else:
    tmp=(t-pow(2, N-1-i, b-1))%(b-1)
    print(nums[tmp]+1)
Problem p02642 (python)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
A.sort()
B=[1]*(10**6+1)
counter=0

if N==1:
  print(1)
  exit()
  
if N==2:
  if A[0]==A[1]:
    print(0)
  elif A[1]%A[0]==0:
    print(1)
  else:
    print(2)
  exit()
  
for i in range(N):
  if 0<i<N-1 and (A[i]==A[i-1] or A[i]==A[i+1]):
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  elif i==0 and A[i]==A[i+1]:
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  elif i==N-1 and A[i-1]==A[i]:
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  
  if B[A[i]]==1:
    counter+=1
    j=2
    while A[i]*j<=10**6:
      B[A[i]*j]=0
      j+=1
print(counter)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
A.sort()
B=[1]*(10**6+1)
counter=0
for i in range(N):
  if 0<i<N-1 and (A[i]==A[i-1] or A[i]==A[i+1]):
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  elif i==0 and A[i]==A[i+1]:
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  elif i==N-1 and A[i-1]==A[i]:
    if B[A[i]]!=0:
      B[A[i]]=0
      j=2
      while A[i]*j<=10**6:
        B[A[i]*j]=0
        j+=1
    continue
  
  if B[A[i]]==1:
    counter+=1
    j=2
    while A[i]*j<=10**6:
      B[A[i]*j]=0
      j+=1
print(counter)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
A.sort()
B=[1]*(10**6+1)
counter=0
for i in range(N):
  if 0<i<N-1 and (A[i]==A[i-1] or A[i]==A[i+1]):
    continue
  elif i==0 and A[i]==A[i+1]:
    continue
  elif i==N-1 and A[i-1]==A[i]:
    continue
  
  if B[A[i]]==1:
    counter+=1
    j=2
    while A[i]*j<=10**6:
      B[A[i]*j]=0
      j+=1
print(counter)
Problem p02719 (python)

Fixed submission:
N, K=map(int, input().split())
tmp=N%K
print(min(tmp, K-tmp))

Buggy submission (verdict: Runtime Error):
#入力受け取り
N, K=map(int, input().split())

#N=aK+bとした時のbを求める
B=N%K

#bとK-bの小さい方を出力
print(min(b, K-b))