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

Fixed submission:
from itertools import product

N = int(input())
xy = [[] for i in range(N)]

for i in range(N):
    for j in range(int(input())):
        xy[i].append(list(map(int, input().split())))
        
ans = 0
for bit in product([0,1], repeat=N):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x-1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

N = int(input())
xy = [[] for i in range(N)]

for i in range(N):
    for j i range(int(input())):
        xy[i].append(list(map(int, input().split())))
        
ans = 0
for bit in product([0,1], repeat=N):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x-1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

N = int(input())
xy = [[] for in range(N)]

for i in range(N):
    for j i range(int(input())):
        xy[i].append(list(map(int, input().split())))
        
ans = 0
for bit in product([0,1], repeat=N):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x-1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)
Problem p02899 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
alist = [0]*n

for i in range(n):
    alist[a[i]-1] = str(i+1)

print(" ".join(alist))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
alist = [0]*n

for i in range(1, n+1):
    alist[a[i]-1] =str(i+1)

print(" ".join(alist))
Problem p02983 (python)

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

if r-l >= 673:
    print(0)
    exit()
else:
    ans = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, i*j%2019)
    print(ans)

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

half = int(n/2)

n1 = d[half-1]
n2 = d[half]

if n2-n1 == 0:
    print(0)
    exit()
else: 
    print(n2-n1)
Problem p03031 (python)

Fixed submission:
n, m = map(int, input().split())
q = list()
for i in range(m):
    q.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0

for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1, len(q[i])):
            w = q[i][j]
            if s >>(w-1) & 1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
q = list()
for i in range(m):
    q.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0

for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1, len(q[i]):
            w = q[i][j]
            if s >>(w-1) & 1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
q = list()
for i in range(m):
    q.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0

for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1, q[i][0]):
            w = q[i][j]
            if s >>(w-1) & 1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        res += 1
print(res)
Problem p03078 (python)

Fixed submission:
X, Y, Z, K  = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

l = []
for a in A:
    for b in B:
        l.append(a+b)
l = sorted(l, reverse = True)[:K]

ans = []
for c in C:
    for k in l:
        ans.append(c + k)
        
ans = sorted(ans, reverse = True)
print(*ans[:K], sep="\n")

Buggy submission (verdict: Runtime Error):
X, Y, Z, K  = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

l = []
for a in A:
    for b in B:
        l.append(a+b)
l = sorted(l, reverse = True)[:K]

ans = []
for c in C:
    for k in l:
        ans.append(c + k)
        
ans = sorted(ans, reverse = True)
print(*ans[:K], seq="\n")
Problem p03478 (python)

Fixed submission:
#B
n, a, b = map(int, input().split())
count = 0

for i in range(1, n+1):
    if a <= sum(map(int,list(str(i)))) <= b:
        count += i
        
print(count)

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

for i in range(1, n+1):
    if a <= sum(map(int,list(str(i)))) <= b:
        s += i
        
print(s)
Problem p02621 (python)

Fixed submission:
a = int(input())

print(str(a + (a ** 2) + (a ** 3)))

Buggy submission (verdict: Runtime Error):
a, b = [input() for i in range(2)]

count = 0
out = 0
if a == b:
  print("0")
else:
  c = list(a)
  d = list(b)
  for i in c:
    if i == d[count]:
      pass
    else:
      out = out + 1
    count = count + 1
  print(str(out))
Problem p03574 (python)

Fixed submission:
n,m=map(int,input().split())
b=[]
for i in range(n):
  b.append(input())
ans=[[0]*m for i in range(n)]
d=[-1,0,1]
for i in range(n):
  for j in range(m):
    if b[i][j]=='#':
      for x in d:
        for y in d:
          X=i+x
          Y=j+y
          if 0 <= X < n and 0 <= Y < m:
            ans[X][Y]+=1
import sys
for i in range(n):
  for j in range(m):
    if b[i][j]=='#':
      sys.stdout.write('#')
    else:
      sys.stdout.write(str(ans[i][j]))
  sys.stdout.write('\n')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
b=[]
for i in range(n):
  b.append(input())
ans=[[0]*m for i in range(n)]
d=[-1,0,1]
for i in range(n):
  for j in range(m):
    if b[i][j]=='#':
      for x in d:
        for y in d:
          X=i+x
          Y=j+y
          if 0 <= X < n and 0 <= Y < m:
            ans[X][Y]+=1
import sys
for i in range(n):
  for j in range(m):
    if b[i][j]=='#':
      sys.stdout.write('#')
    else:
      sys.stdout.write(ans[i][j])
  sys.stdout.write('\n')
Problem p03591 (python)

Fixed submission:
s = raw_input()
if s[0:4] == "YAKI":
 print "Yes"
else:
 print "No"

Buggy submission (verdict: Runtime Error):
s = input()
if s[0:4] == "YAKI":
 print "Yes"
else:
 print "No"
Problem p03609 (python)

Fixed submission:
a,b=map(int,input().split())
print(a-b if a-b>0 else 0)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
print(a-b if a-b>0 else 0)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
print a-b if a-b>0 else 0

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
print a-b if a-b>0 else 0
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
if s == t[:-1]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s, t = input().split()
if s == t[:-1]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s, t = input().split()
if s == t[:-1]:
  print('Yes')
else:
  print('No')
Problem p02602 (python)

Fixed submission:
n,k=map(int,input().split())
ar=list(map(int,input().split()))
for i in range(k,n):
	if ar[i]>ar[i-k]:
		print("Yes")
	else:
		print("No")

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
ar=list(map(int,input().split()))
for i in range(k,n):
	if ar[i]>ar[i-k]:
		print("Yes")
	else:
		print("No"
Problem p03160 (python)

Fixed submission:
n=int(input())
ab=abs
hr=list(map(int,input().split()))
dp=[-1]*(n+1)
dp[0]=0
dp[1]=ab(hr[1]-hr[0])
for i in range(2,n):
	x=ab(hr[i]-hr[i-2])+dp[i-2]
	y=ab(hr[i]-hr[i-1])+dp[i-1]
	dp[i]=min(x,y)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
hr=list(map(int,input().split()))
dp=[-1]*(n+1)
def cost(i):
	if i>=n-1:
		return 0
	if dp[i]!=-1:
		return dp[i]
	if i<n-2:
		a=abs(hr[i]-hr[i+2])+cost(i+2)
	b=abs(hr[i]-hr[i+1])+cost(i+1)
	if i>=n-2:
		a=b
	x=min(a,b)
	dp[i]=x
	return x
print(cost(0))
Problem p03162 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5 + 9)
from collections import defaultdict
dp=defaultdict(lambda:0)
n=int(input())
ar,br,cr=[0]*n,[0]*n,[0]*n

for i in range(n):
	ar[i],br[i],cr[i]=map(int,input().split())
if n==1:
	print(max(ar[0],br[0],cr[0]))
	exit()
def points(i,pv):
	if dp[(i,pv)] != 0:
		return dp[(i,pv)]
	if pv==1:
		x,y=br[i],cr[i]
		a,b=2,3
	elif pv==2:
		x,y=ar[i],cr[i]
		a,b=1,3
	else:
		x,y=ar[i],br[i]
		a,b=1,2
	if i==n-1:
		return max(x,y)
	ax=points(i+1,a)+x
	by=points(i+1,b)+y
	ans=max(by,ax)
	dp[(i,pv)]=ans
	return ans
p=points(1,1)+ar[0]
q=points(1,2)+br[0]
r=points(1,3)+cr[0]
print(max(p,q,r))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5 + 9)
from collections import defaultdict
dp=defaultdict(lambda:0)
n=int(input())
ar,br,cr=[0]*n,[0]*n,[0]*n
for i in range(n):
	ar[i],br[i],cr[i]=map(int,input().split())
def points(i,pv):
	if dp[(i,pv)] != 0:
		return dp[(i,pv)]
	if pv==1:
		x,y=br[i],cr[i]
		a,b=2,3
	elif pv==2:
		x,y=ar[i],cr[i]
		a,b=1,3
	else:
		x,y=ar[i],br[i]
		a,b=1,2
	if i==n-1:
		return max(x,y)
	ax=points(i+1,a)+x
	by=points(i+1,b)+y
	ans=max(by,ax)
	dp[(i,pv)]=ans
	return ans
p=points(1,1)+ar[0]
q=points(1,2)+br[0]
r=points(1,3)+cr[0]
print(max(p,q,r))
Problem p03163 (python)

Fixed submission:
n,W=map(int,input().split())
dp=[0]*(W+1)
dd=dp.copy()
for i in range(n):
	w,v=map(int,input().split())
	for j in range(W):
		cw=j+w
		cv=dp[j]+v
		if cw <=W and dd[cw]<cv:
			dd[cw]=cv
	dp=dd.copy()
print(dp[W])

Buggy submission (verdict: Runtime Error):
import numba as nb 
from collections import defaultdict
n,W=list(map(int,input().split()))
li=[]
wr=[0]*n
vr=[0]*n
dd=defaultdict(lambda:0)
for i in range(n):
	w,v=map(int,input().split())
	wr[i]=w
	vr[i]=v
mw=min(wr)


@nb.njit()
def maxv(i,w):
	if dd[(i,w)]!=0:
		
		return dd[(i,w)]
	if i==n:
		return 0
	if W-w<mw:
		return 0
	if w+wr[i]<=W:
		a=vr[i]+maxv(i+1,w+wr[i])
	else:
		a=0
	b=maxv(i+1,w)
	c=max(a,b)
	dd[(i,w)]=c
	return c
print(maxv(0,0))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n,W=list(map(int,input().split()))
li=[]
wr=[0]*n
vr=[0]*n
dd=defaultdict(lambda:0)
for i in range(n):
	w,v=map(int,input().split())
	wr[i]=w
	vr[i]=v
mw=min(wr)
import numba as nb 

@nb.njit()
def maxv(i,w):
	if dd[(i,w)]!=0:
		
		return dd[(i,w)]
	if i==n:
		return 0
	if W-w<mw:
		return 0
	if w+wr[i]<=W:
		a=vr[i]+maxv(i+1,w+wr[i])
	else:
		a=0
	b=maxv(i+1,w)
	c=max(a,b)
	dd[(i,w)]=c
	return c
print(maxv(0,0))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n,W=list(map(int,input().split()))
li=[]
wr=[0]*n
vr=[0]*n
dd=defaultdict(lambda:0)
for i in range(n):
	w,v=map(int,input().split())
	wr[i]=w
	vr[i]=v
def maxv(i,w):
	if dd[(i,w)]!=0:
		return dd[(i,w)]
	if i==n:
		return 0
	if w+wr[i]>W:
		m=maxv(i+1,w)
		dp[(i,w)]=m
		return m
	a=vr[i]+maxv(i+1,w+wr[i])
	b=maxv(i+1,w)
	c=max(a,b)
	dd[(i,w)]=c
	return c
print(maxv(0,0))
Problem p03165 (python)

Fixed submission:
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for j in range(m+1)] for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,m+1):
		if s[i-1]==t[j-1]:
			dp[i][j]=dp[i-1][j-1]+1
		else:
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])
i=n
j=m
st=""
while dp[i][j]:
	while dp[i-1][j]==dp[i][j]:
		i-=1
	while dp[i][j-1]==dp[i][j]:
		j=j-1
	j-=1
	st+=s[i-1]
	i-=1
print(st[::-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(3009)
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for j in range(m+1)] for i in range(n+1)]
def lcs(i,j):
	if dp[i][j]!=0:
		return dp[i][j]
	if i*j==0:
		return 0
	if s[i-1]==t[j-1]:
		r=lcs(i-1,j-1)+1
	else:
		r=max(lcs(i,j-1),lcs(i-1,j))
	dp[i][j]=r
	return r
		
		

lcs(n,m)

i=n
j=m
st=""
while dp[i][j]:
	while dp[i-1][j]==dp[i][j]:
		i-=1
	while dp[i][j-1]==dp[i][j]:
		j=j-1
	j-=1
	st+=s[i-1]
	i-=1
print(st[::-1])

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for j in range(m+1)] for i in range(n+1)]
def lcs(i,j):
	if dp[i][j]!=0:
		return dp[i][j]
	if i*j==0:
		return 0
	if s[i-1]==t[j-1]:
		r=lcs(i-1,j-1)+1
	else:
		r=max(lcs(i,j-1),lcs(i-1,j))
	dp[i][j]=r
	return r
		
		

lcs(n,m)

i=n
j=m
st=""
while dp[i][j]:
	while dp[i-1][j]==dp[i][j]:
		i-=1
	while dp[i][j-1]==dp[i][j]:
		j=j-1
	j-=1
	st+=s[i-1]
	i-=1
print(st[::-1])

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for j in range(m+2)] for i in range(n+2)]
for i in range(1,n+1):
	for j in range(1,m+1):
		if s[i-1]==t[j-1]:
			dp[i][j]=dp[i-1][j-1]+1
		else:
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])
i=n
j=m
st=""
while i>0 and j>0:
	while dp[i-1][j]==dp[i][j]:
		i-=1
	while dp[i][j-1]==dp[i][j]:
		j=j-1
	j-=1
	st+=s[i-1]
	i-=1
print(st[::-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(3009)
s=input()
n=len(s)
t=input()
m=len(t)
def lcs(x,y):
	if min(x,y)==-1:
		return ""
	if s[x]==t[y]:
		return lcs(x-1,y-1)+s[x]
	a=lcs(x-1,y)
	b=lcs(x,y-1)
	if len(a)>len(b):
		return a
	else:
		return b
print(lcs(n-1,m-1))
Problem p03238 (python)

Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n = int(input())
a = int(input())
b = int(input())
if n == 1:
    print("Hello World")
else:
    print(a+b)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


lst = list(map(int, input().split()))
if lst[0] == 1:
    print("Hello World")
else:
    print(lst[1] + lst[2])
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if((a*b)%2 == 0):
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
if((a*b)%2 == 0):
    print("Even")
else:
    print("Odd")
Problem p02675 (python)

Fixed submission:
b = int(input())
a = b % 10

if a == 2 or a == 4 or a == 5 or a == 7 or a == 9 :
  print("hon")
elif a == 0 or a == 1 or a == 6 or a == 8 :
  print("pon")
elif a == 3 :
  print("bon")

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
b, c, tanshin, choshin = [int(x) for x in stdin.readline().rstrip().split()]
 


choshin12 = choshin * (360 / 60)
if choshin == 0 :
	choshin12 = 360/60
 
tanshin12 = (tanshin * 60 + choshin) * 360 / (12 * 60)
 
rad =  abs( choshin12 - tanshin12 )
 
# 線対称で書いちゃったよ。。。点対称じゃんね
if rad >= 180 :
	rad = 360-rad
 
# 余弦定理とか生まれて初めてです・・・
a = (b ** 2) + (c ** 2) - (2 * b * c * math.cos(math.radians(rad)))
 
# print (math.cos(math.radians(rad)))
 
a = math.sqrt(a)

# print(tanshin)
# print(choshin)
 
# print(tanshin12)
# print(choshin12)
 
# print(rad)
print (a)

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

input_line = input()


if len(input_line) > cnt :
	print(input_line[:cnt] + "...")

else :
	print(input_line)
Problem p02921 (python)

Fixed submission:
# 整数の入力
s = input()
t = input()

cnt = 0
if s[0] == t[0] :
	cnt += 1

if s[1] == t[1] :
	cnt += 1

if s[2] == t[2] :
	cnt += 1

print (cnt)

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

need = 1
tap = a


while tap < b:
	if a == 0 or a == 1 or b < a or b == 0:
		need = 0
		break
	tap += (a - 1)
	need += 1
print (need)
Problem p02841 (python)

Fixed submission:
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())

if D2-D1 == 1:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
n=int(input())
a = n / 1.08
if a-int(a) == 0.00:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
n=int(input())
a = n / 1.08
if a-int(a) == 0.00:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = n / 1.08
if a-int(a) == 0.00:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
n = input()
a = n / 1.08
if float(n%1.08):
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")
Problem p02842 (python)

Fixed submission:
n=int(input())
a = n / 1.08
if a-int(a) == 0.00:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
n =input()
a = n / 1.08
if a-int(a) == 0.00:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
n = input()
a = n / 1.08
if float(n%1.08) ==0:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
print(x,v,n)
if v == n:
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
n = input()
a = n / 1.08
if float(n%1.08) ==0:
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
print(x,v,n)
if v == n:
  print(x)
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
n = input()
a = n / 1.08
if float(n%1.08):
      x = int(a)
else:
      x = int(a) + 1
v = int(x * 1.08)
if v == n:
  print(x)
else:
  print(":(")
Problem p02642 (python)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    MAX = A[-1]
    dp = [1] * (MAX + 5)
    ANS = 0
    for i in range(N):
        if dp[A[i]] == 0:
            continue
        for j in range(MAX+1):
            if A[i]*j > MAX:
                break
            dp[A[i]*j] = 0
        dp[A[i]] = 0
        if i < N-1 and A[i] == A[i+1]:
            continue
        ANS += 1
    print(ANS)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import copy
N = int(input())
A = list(map(int,input().split()))
A.sort()
B = copy.copy(A)
cnt = 0
for i in range(N):
    if A.count(A[i])> 1:
        continue
    for j in range(len(B)):
        if 2 * B[j] > A[i]:
            cnt += 1
            break
        if A[i] % B[j] == 0:
            break
        if j
print(cnt)

Buggy submission (verdict: Runtime Error):
import copy
N = int(input())
A = list(map(int,input().split()))
A.sort()
B = copy.copy(A)
cnt = 0
for i in range(N):
    if A.count(A[i])> 1:
        continue
    for j in range(len(B)):
        if 2 * B[j] > A[i]:
            cnt += 1
            break
        if A[i] % B[j] == 0:
            B.remove(A[i])
            break
        if j
print(cnt)
Problem p02606 (python)

Fixed submission:
L, R, d = [int(x) for x in input().split()]

lst = list(range(d, 101, d))

ret = list(filter(lambda x: L <= x <= R, lst))

# print(ret)
print(len(ret))

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

import functools


def popcount(bits: str):
    return len([elm for elm in bits if elm == '1'])


@functools.lru_cache(maxsize=200000)
def f(num):
    if num == 0:
        return 0
    else:
        pc = popcount('{:b}'.format(num))
        return 1 + f(num % pc)


def reverse_bit(bits: str, digit):
    def toggle(a):
        if a == '1':
            return '0'
        else:
            return '1'

    ret = list(bits)
    ret[digit-1] = toggle(bits[digit-1])
    return ''.join(ret)

def convert(x: str):
    ans = 0
    i = 0
    for elm in list(x)[::-1]:
        if elm == '1':
            ans += 2 ** i
        i += 1
    return ans


for i in range(1, N+1):
    bits = reverse_bit(X, i)
    pc = popcount(bits)
    # print(f'# {bits} {convert(bits)} {pc}')
    print(f(convert(bits)))
Problem p02609 (python)

Fixed submission:
n = int(input())
# for i in range(n):
#     print('0', end='')
# print(flush=True)
s = input()
x = int(s, base=2)
popcount = s.count('1')
y_zero = x % (popcount + 1)
if popcount > 1:
    y_one = x % (popcount - 1)
dp = [-1] * n
dp[0] = 0
 
 
def calc(y):
    if dp[y] != -1:
        return dp[y]
    dp[y] = 1 + calc(y % bin(y).count('1'))
    return dp[y]
 
 
ans = [0] * n
rem_zero = 1
if popcount > 1:
    rem_one = popcount - 2
for i in range(n):
    if s[n - 1 - i] == '0':
        ans[n - 1 - i] = 1 + calc((y_zero + rem_zero) % (popcount + 1))
    elif popcount > 1:
        ans[n - 1 - i] = 1 + calc((y_one + rem_one) % (popcount - 1))
    else:
        ans[n - 1 - i] = 0
    rem_zero = rem_zero * 2 % (popcount + 1)
    if popcount > 1:
        rem_one = rem_one * 2 % (popcount - 1)
for i in range(n):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
# print(flush=True)
s = input()
x = int(s, base=2)
popcount = s.count('1')
y_zero = x % (popcount + 1)
if popcount > 1:
    y_one = x % (popcount - 1)
dp = [-1] * n
dp[0] = 0
 
 
def calc(y):
    if dp[y] != -1:
        return dp[y]
    dp[y] = 1 + calc(y % bin(y).count('1'))
    return dp[y]
 
 
ans = [0] * n
rem_zero = 1
if popcount > 1:
    rem_one = popcount - 2
for i in range(n):
    if s[n - 1 - i] == '0':
        ans[n - 1 - i] = 1 + calc((y_zero + rem_zero) % (popcount + 1))
    elif popcount > 1:
        ans[n - 1 - i] = 1 + calc((y_one + rem_one) % (popcount - 1))
    else:
        ans[n - 1 - i] = 0
    rem_zero = rem_zero * 2 % (popcount + 1)
    if popcount > 1:
        rem_one = rem_one * 2 % (popcount - 1)
for i in range(n):
    print(ans[i])
Problem p02641 (python)

Fixed submission:
X, N = [int(i) for i in input().split()]
if N == 0:
# if False:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    # if not X in Ps:
    #     print(X)

    # print(f'{X} {sorted(Ps)}')
    diff = 0
    while True:
        a = X - diff
        if a not in Ps:
            print(a)
            break
        a = X + diff
        if a not in Ps:
            print(a)
            break
        diff += 1

Buggy submission (verdict: Runtime Error):
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    # coords = set(range(min(Ps), max(Ps)+1))
    # for p in Ps:
    #     coords.remove(p)
    # if X in coords:
    #     print(X)
    # else:
    #     ret = [ (v, abs(X-v)) for v in coords ]
    #     minval = min(ret, key=lambda elm: elm[1])[0]
    #     print(
    #         min([ elm[0] for elm in ret if minval == elm[0] ])
    #     )
    coords = list(range(1, 101))
    if not X in Ps:
        print(X)
    i = X - 1
    diff = 0
    while True:
        if not coords[i - diff] in Ps:
            print(coords[i - diff])
            break
        if not coords[i + diff] in Ps:
            print(coords[i + diff])
            break
        diff += 1

Buggy submission (verdict: Runtime Error):
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = [int(i) for i in input().split()]
    coords = set(range(min(Ps), max(Ps)+1))
    for p in Ps:
        coords.remove(p)
    if X in coords:
        print(X)
    else:
        ret = [ (v, abs(X-v)) for v in coords ]
        minval = min(ret, key=lambda elm: elm[1])[0]
        print(
            min([ elm[0] for elm in ret if minval == elm[0] ])
        )