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

Fixed submission:
# E

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

def gcd(a,b):
    if a>b:
        a,b=b,a
    while a%b:
        a,b=b,(a%b)
    return b

def fast_factorization_init(N):
    res=list(range(N))
    for i in range(2,N):
        if i*i>N:
            break
        for j in range(i*i,N,i):
            if res[j]==j:
                res[j]=i
        if res[i]<i:
            continue
    return res            
    
min_factors=fast_factorization_init(10**6+10)
def fast_factorization(n):
    res=[]
    while n>1:
        res.append(min_factors[n])
        n//=min_factors[n]
    return list(set(res))

res2=0
P=[]
for i in range(N):
    if i!=0:
        res1=gcd(A[i],res1)
    else:
        res1=A[0]
    P += fast_factorization(A[i])

if len(set(P))==len(P):
    res2=1

if res2==1:
    print('pairwise coprime')
elif res1==1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
# E

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

def gcd(a,b):
    if a>b:
        a,b=b,a
    while a%b:
        a,b=b,(a%b)
    return b

def fast_factorization_init(N):
    res=list(range(N))
    for i in range(2,N):
        if i*i>N:
            break
        for j in range(i*i,N,i):
            if res[j]==j:
                res[j]=i
        if res[i]<i:
            continue
    return res            
    
min_factors=fast_factorization_init(N)
def fast_factorization(n):
    res=[]
    while n>1:
        res.append(min_factors[n])
        n//=min_factors[n]
    return res

res2=1
P=[]
for i in range(N):
    if i!=0:
        res1=gcd(A[i],res1)
    else:
        res1=A[0]
    fact=fast_factorization(A[i])
    if res2!=0:
        for p in P:
            if A[i]%p==0:
                res2=0
                break
    for p in fact:
        P.append(p)
if res2==1:
    print('pairwise coprime')
elif res1==1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
# E

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

def gcd(a,b):
    if a>b:
        a,b=b,a
    while a%b:
        a,b=b,(a%b)
    return b

def fast_factorization_init(N):
    res=list(range(N))
    for i in range(2,N):
        if i*i>N:
            break
        for j in range(i*i,N,i):
            if res[j]==j:
                res[j]=i
        if res[i]<i:
            continue
    return res            
    
min_factors=fast_factorization_init(10**5)
def fast_factorization(n):
    res=[]
    while n>1:
        res.append(min_factors[n])
        n//=min_factors[n]
    return res

res2=1
P=[]
for i in range(N):
    if i!=0:
        res1=gcd(A[i],res1)
    else:
        res1=A[0]
    fact=fast_factorization(A[i])
    if res2!=0:
        for p in P:
            if A[i]%p==0:
                res2=0
                break
    for p in fact:
        P.append(p)
if res2==1:
    print('pairwise coprime')
elif res1==1:
    print('setwise coprime')
else:
    print('not coprime')
Problem p02585 (python)

Fixed submission:
# ABC175 D
import bisect

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

F=[0]*N

def search(n):
    res=[]
    l=0
    m=n
    tmp_res=0
    isloop=0
    if F[n-1]:
        s,L=F[n-1]
    while 1:
        m=P[m-1]
        tmp_res+=C[m-1]
        l+=1
        if F[n-1]==0:
            res.append((tmp_res,l))
        else:
            res.append(tmp_res+s*((K-l)//L) if s>0 and K>=l else tmp_res)
        if m==n:
            isloop=1
            break
        if l==K:
            break
    if F[n-1]==0:
        if isloop:
            s,L=res[-1]
            if not F[n-1]:
                m=n
                while 1:
                    F[m-1]=(s,L)
                    m=P[m-1]
                    if m==n:
                        break
        else:
            s=-1
        p=max([p+s*((K-k)//len(res)) if s>0 and K>=k else p for p,k in res])
    else:
        p=max(res)
    return p

res=-float('inf')
for i in range(N):
    res=max(res,search(i+1))
print(res)

Buggy submission (verdict: Runtime Error):
# ABC175 D
import bisect

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

F=[0]*N

def op(n):
    C_n=[]
    P_n=[]
    m=n
    while 1:
        C_n.append(C[m-1])
        P_n.append(m)
        F[m-1]=1
        m=P[m-1]
        if m==n:
            break
    sum_C_n=sum(C_n)
    C_n=C_n[:]+C_n[:]
    n=len(P_n)
    res=[]
    for k in range(1,min(n+1,K)):
        res_k=[]
        sum_k=sum(C_n[:k])
        p=sum_k
        for i in range(n):
            sum_k+=C_n[i+k]-C_n[i]
            p=max(p,sum_k)
        if K-k>=n and sum_C_n>=0:
                p+=sum_C_n*(K-k)//n
        res.append(p)
    return max(res)
    
res=-float('inf')
while 0 in F:
    n=bisect.bisect_right(F,0)
    res=max(op(n),res)
print(res)

Buggy submission (verdict: Runtime Error):
# ABC175 D
import bisect

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

F=[0]*N

def op(n):
    C_n=[]
    P_n=[]
    m=n
    while 1:
        C_n.append(C[m-1])
        P_n.append(m)
        F[m-1]=1
        m=P[m-1]
        if m==n:
            break
    sum_C_n=sum(C_n)
    C_n=C_n[:]+C_n[:]
    n=len(P_n)
    res=[]
    for k in range(1,min(n+1,K)):
        res_k=[]
        for i in range(n):
            res_k.append(sum(C_n[i:i+k]))
        p=max(res_k)
        if K-k>=n and sum_C_n>=0:
                p+=sum_C_n*(K-k)//n
        res.append(p)
    return max(res)
    
res=-float('inf')
while 0 in F:
    n=bisect.bisect_right(F,0)
    res=max(op(n),res)
print(res)
Problem p02642 (python)

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

F=[0]*(10**6+11)
# 0:OK/未調査 1:NG 2:調査した頂点 3:二度調査した頂点

for a in A:
    if F[a]==1:
        continue
    if F[a]==2:
        F[a]=1
        continue
    elif F[a]==0:
        F[a]=2
    k=2*a
    while k<=10**6+1:
        F[k]=1
        k+=a
            
res=0
for a in A:
    if F[a]==2:
        res+=1
print(res)

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

F=[0]*(10**6+11)

for a in A:
    if F[a]==2:
        F[a]=1
        continue
    elif F[a]==0:
        F[a]=2
    k=2*a
    while 1:
        F[k]=1
        k+=a
        if not k<=10**6+10:
            break
res=0
for a in A:
    if F[a]==2:res+=1
print(res)
Problem p02658 (python)

Fixed submission:
a,b=open(0);c=1;
for i in sorted(b.split()):
    c*=int(i)
    if c>10**18:print(-1);exit()
print(c)

Buggy submission (verdict: Runtime Error):
a,b=open(0);print([x:=eval(b.replace(*' *')),-1][x>10**18or len(b)>=99])

Buggy submission (verdict: Runtime Error):
a,b=open(0);c=1;
for i in range(int(a)):c*=int(b[2*i])
if c>10**18:print(-1);exit()
print(c)

Buggy submission (verdict: Runtime Error):
a,b=open(0);print([x:=eval(b.replace(*' *')),-1][x>10**18])
Problem p02761 (python)

Fixed submission:
f=lambda:map(int,input().split())
N,M=f()
q=[list(f()) for _ in [0]*M]
res=-1
A=list(range(10**(N-1),10**N))
if N==1:A=[0]+A
for i in A:
    for j in range(M):
        if str(i)[q[j][0]-1]!=str(q[j][1]):
            break
    else:
        res=i
        break
print(res)

Buggy submission (verdict: Runtime Error):
f=lambda:map(int,input().split())
N,M=f()
q=[list(f()) for _ in [0]*M]
res=-1
A=range(10**(N-1),10**N)
if N==1:A+=[0]
for i in A:
    for j in range(M):
        if str(i)[q[j][0]-1]!=str(q[j][1]):
            break
    else:
        res=i
        break
print(res)

Buggy submission (verdict: Runtime Error):
f=lambda:map(int,input().split())
N,M=f()
q=[list(f()) for _ in [0]*M]
res=-1
A=range(10**(N-1),10**N)
if N==1:A+=[0]
for i in :
    for j in range(M):
        if str(i)[q[j][0]-1]!=str(q[j][1]):
            break
    else:
        res=i
        break
print(res)
Problem p02787 (python)

Fixed submission:
# ABC153 E Crested Ibis vs Monster
f=lambda:map(int,input().split())
H,N=f()
# dp[n][h]:=nthまでで体力をh削るときの最小魔力
INF=10**9
dp=[[INF]*(H+1) for _ in [0]*(N+1)]

for i in range(N+1):
    if i!=0:
        a,b=f()
    else:
        a,b=0,0
    for j in range(H+1):
        if i==0:
            if j==0:
                dp[i][j]=0
            else:
                dp[i][j]=INF
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][max(j-a,0)]+b)

print(dp[N][H])

Buggy submission (verdict: Runtime Error):
#E
H,N=map(int,input().split())
A,B=[0]*N,[0]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())
    
memo=[0]*(H+10)
def dpinit(H):
    for i in range(H):
        memo[H]=min([dp(H-A[i])+B[i] for i in range(N)])
    
def dp(H):
    if H<=0:
        return 0
    else:
        if memo[H]==0:
            memo[H]=min([dp(H-A[i])+B[i] for i in range(N)])
        return memo[H]
    
dpinit(int(H//100))
print(dp(H))

Buggy submission (verdict: Runtime Error):
#E
H,N=map(int,input().split())
A,B=[0]*N,[0]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())
    
memo=[0]*(H+10)
def dp(H):
    if H<=0:
        return 0
    else:
        if memo[H]==0:
            memo[H]=min([dp(H-A[i])+B[i] for i in range(N)])
        return memo[H]

print(dp(H))
Problem p02801 (python)

Fixed submission:
N=input()
alp='abcdefghijklmnopqrstuvwxyz'
print(alp[alp.find(N)+1])

Buggy submission (verdict: Runtime Error):
N=input()
alp='abcdefghijklmnopqrstuvwxyz'
print(alp[alp.find(N)+1])
Problem p02838 (python)

Fixed submission:
# ABC 147 D

N=int(input())
A=list(map(int,input().split()))
res=0
p=10**9+7

bits=[0]*71
for a in A:
    j=0
    while a>>j:
        if (a>>j)&1:
            bits[j]+=1
        j+=1

t=0
n=70
while n>=0:
    if bits[n]!=0:
        break
    n-=1

for a in A:
    j=0
    while j<=n:
        if (a>>j)&1:
            res+=((2**j)*(N-bits[j]))%p
        else:
            res+=((2**j)*bits[j])%p
        j+=1
    t=res
print((res*500000004)%p)

Buggy submission (verdict: Runtime Error):
# ABC 147 D

N=int(input())
A=list(map(int,input().split()))
res=0
p=10**9+7

bits=[0]*71
for a in A:
    j=0
    while a>>j:
        if (a>>j)&1:
            bits[j]+=1
        j+=1

t=0
n=70
while 1:
    if bits[n]!=0:
        break
    n-=1

for a in A:
    j=0
    while j<=n:
        if (a>>j)&1:
            res+=((2**j)*(N-bits[j]))%p
        else:
            res+=((2**j)*bits[j])%p
        j+=1
    t=res
print((res*500000004)%p)
Problem p03044 (python)

Fixed submission:
N=int(input())
G=[[] for _ in [0]*(N+1)]
for _ in [0]*(N-1):
    u,v,w=map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w))

c=[0]*(N+1)
stack=[1]
c[1]=1
while stack:
    r=stack.pop()
    for nr,nw in G[r]:
        if c[nr]==0:
            stack.append(nr)
            if nw%2:
                c[nr]=-c[r]
            else:
                c[nr]=c[r]
for i in c[1:]:
    print((i+1)//2)

Buggy submission (verdict: Runtime Error):
N=int(input())
G=[[0]*(N+1) for  _ in [0]*(N+1)]
res=[0]*(N+1)

for i in range(N-1):
    u,v,w=map(int,input().split())
    G[u][v]=w
    G[v][u]=w
    
    
stack=[]
stack.append(1)
res[1]=1
while stack:
    r=stack.pop()
    for k in range(N+1):
        if G[r][k]>0 and res[k]==0:
            stack.append(k)
            if G[r][k]%2:
                res[k]=-res[r]
            else:
                res[k]=res[r]
for i in res[1:]:
    print((i+1)//2)
Problem p03160 (python)

Fixed submission:
#frog
H=10**10
n=int(input())
h=list(map(int,input().split()))+[H]*10
dp=[0]*(n+10)
for i in range(1,n+1):
    dp[i]=min([dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])])
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
#frog
n=int(input())
h=[10**10]+list(map(int,input().split()))+[10**10]*10
def dp(i):
    if i<=1:
        return 0
    else:
        return min([dp(i-1)+abs(h[i]-h[i-1]),dp(i-2)+abs(h[i]-h[i-2])])
print(dp(n))
Problem p03241 (python)

Fixed submission:
#112D
N,M=map(int,input().split())
B=int((M**(1/2))//1)
A=[M//i for i in range(1,int((M**(1/2)+1)//1))]+list(range(1,B))
A.sort(reverse=True)
for i in A:
    flag=M-N*i
    if flag%i==0 and flag>=0:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
#112D
N,M=map(int,input().split())
for i in list(range(1,M//N+1))[::-1]:
    flag=M-N*i
    if flag%i==0 and flag>=0:
        print(i)
        break
Problem p03282 (python)

Fixed submission:
#C
S=input()
K=int(input())
num='23456789'
if S[0]!='1':
    print(int(S[0]))
else:
    n=1
    while True:
        if n==len(S):
            n-=1
            break
        elif S[n]!='1':
            break
        n+=1
    if K-1<n:
        print(1)
    else:
        print(int(S[n]))

Buggy submission (verdict: Runtime Error):
#C
S=input()
K=int(input())
num='23456789'
if S[0]!='1':
    print(1)
else:
    n=1
    while True:
        if n==len(S):
            n-=1
            break
        elif S[n]!='1':
            break
        n+=1
if K-1<n:
    print(1)
else:
    print(int(S[n]))

Buggy submission (verdict: Runtime Error):
#C
S=input()
K=int(input())
num='23456789'
if S[0]!='1':
    print(1)
else:
    n=1
    while True:
        if n==len(S):
            n-=1
            break
        elif S[n]!='1':
            break
        n+=1
if K-1<n:
    print(1)
else:
    print(S[n])
Problem p03290 (python)

Fixed submission:
from math import ceil
D,G=map(int,input().split())
p,c=[0]*D,[0]*D
for i in range(D):
    p[i],c[i]=map(int,input().split())

m=0
mondai=[]
for i in range(2**D,2**(D+1)):
    s=(bin(i))[3:]
    a,b=0,0
    for j in range(D):
        if s[j]=='1':
            a,b=a+p[j],b+100*(j+1)*p[j]+c[j]
        else:
            m=j
    if G<=b:
        mondai.append(a)
    if G-p[m]*100*(m+1)<b<G:
        ad=ceil((G-b)/(100*(m+1)))
        mondai.append((a+ad))
print(min(mondai))

Buggy submission (verdict: Runtime Error):
D,G=map(int,input().split())
p,c=[0]*D,[0]*D
cell=[]
for i in range(D):
    p[i],c[i]=map(int,input().split())
    cell.append([-1]*102)

m=0,0,0
mondai=[]
for i in range(2**D,2**(D+1)):
    s=(bin(i))[3:]
    a,b=0,0
    for j in range(D):
        if s[j]=='1':
            a,b=a+p[j],b+100*(j+1)*p[j]+c[j]
        else:
            m=j
    if G<b:
        mondai.append(a)
    if G-p[m]*100*(m+1)<b<G:
        ad=(G-b)//(100*(m+1))
        mondai.append((a+ad))
print(min(mondai))
Problem p03747 (python)

Fixed submission:
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]==1:
            if 2*T-(X[j]-X[0])>=0:
                col+=(1+(2*T-(X[j]-X[0]))//L)
        else:
            if 2*T-(X[0]-X[j])>=0:
                col-=(1+(2*T-(X[0]-X[j]))//L)

col=col%N
X2=[(X[i]+(3-2*W[i])*T) % L for i in range(N)]
X2_0=X2[0]

X2.sort()

index=[i for i,x in enumerate(X2) if x==X2_0]

if len(index)==1:
    index=index[0]
else:
    if W[0]==1:
        index=index[1]
    else:
        index=index[0]

i=(index-col)%N

X2=X2[i:]+X2[:i]
print(*X2,sep='\n')

Buggy submission (verdict: Runtime Error):
# AGC C Ants on a Circle
f=lambda:map(int,input().split())
N,L,T=f()
X,W=[],[]
for _ in [0]*N:
    x,w=f()
    X.append(x)
    W.append(w)
    
if W[0]==2:
    X[0]+=L
    
col=0
for j in range(N):
    if W[j]==W[0]:
        continue
    else:
        if W[0]>0:
            if 2*T-(X[j]-X[0])>=0:
                col+=1+(2*T-(X[j]-X[0]))//L
            else:
                col+=0
        else:
            col-=max((2*T-X[j]+X[0])//L,0)
col=col%N
X2=[(X[i]+(3-2*W[i])*(T-0.01)) % L for i in range(N)]

ant0=(X2[0],col)

X2.sort()

x=X2.index(ant0[0])


for i in range(x-col-N,x-col):
    print(round(X2[i]))
Problem p03853 (python)

Fixed submission:
i,p=input,print;H,W=map(int,i().split());C=[i() for x in range(H)]
for j in range(H):
    p(C[j]);p(C[j])

Buggy submission (verdict: Runtime Error):
i,p=input,print;H,W=map(int,i().split());for j in range(H):k=i();p(k);p(k)
Problem p03854 (python)

Fixed submission:
s,f=input()[::-1],-1
while f<0:
    if s:
        if s[:5]=='maerd':
            s=s[5:]
        elif s[:5]=='esare':
            s=s[5:]
        elif s[:6]=='resare':
            s=s[6:]
        elif s[:7]=='remaerd':
            s=s[7:]
        else:
            f=0
    else:
        f=1
print(['NO','YES'][f])

Buggy submission (verdict: Runtime Error):
S=input()[::-1]
def a(s):
    if s:
        if s[:5]=='maerd':
            return a(s[5:])
        elif s[:5]=='esare':
            return a(s[5:])
        elif s[:6]=='resare':
            return a(s[6:])
        elif s[:7]=='remaerd':
            return a(s[7:])
        else:
            return False
    else:
        return True
print(a(S))
Problem p04015 (python)

Fixed submission:
import bisect

N,A=map(int,input().split())
x=[i-A for i in map(int,input().split())]

B=max(max(x),abs(min(x)))

dp=[[0]*(2*N*B+1) for _ in [0]*(N+1)]
dp[0][N*B]=1
# dp[n][k]:n番目までの整数でkが作れる場合の数
    
for n in range(1,N+1):
    for k in range(-N*B,N*B+1):
        dp[n][k]+=dp[n-1][k-x[n-1]]+dp[n-1][k]

print(dp[N][N*B]-1)

Buggy submission (verdict: Runtime Error):
import bisect

N,A=map(int,input().split())
x=[i-A for i in map(int,input().split())]


dp=[[0]*(2*N*A+1) for _ in [0]*(N+1)]
dp[0][N*A]=1
# dp[n][k]:n番目までの整数でkが作れる場合の数
    
for n in range(1,N+1):
    for k in range(-N*A,N*A+1):
        dp[n][k]+=dp[n-1][k-x[n-1]]+dp[n-1][k]

print(dp[N][N*A]-1)
Problem p03246 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

evens = Counter(A[::2])
odds = Counter(A[1::2])
evens[0] = 0 # 番兵
odds[0] = 0

e1, e2 = evens.most_common(2)
o1, o2 = odds.most_common(2)

if e1[0] != o1[0]:
  print(N - (e1[1] + o1[1]))
else:
  print(N - max(e1[1] + o2[1], e2[1] + o1[1]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

evens = Counter(A[::2])
odds = Counter(A[1::2])
evens[0] = 0 # 番兵
odds[0] = 0

e1, e2 = evens.most_common(2)
o1, o2 = odds.most_common(2)

if e1[0] != o1[0]:
  print(N - (e1[1] + o1[1]))
else:
  print(N - max(e1[1] + o2[1], e2[1] + o1[1]))
Problem p02536 (python)

Fixed submission:
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)
 
for a,b in ab:
    uf.union(a-1,b-1)

print( uf.group_count() - 1 )

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]

*p, = range(n)
rank = [1]*n
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    rx = rank[px]; ry = rank[py]
    if ry < rx:
        p[py] = px
    elif rx < ry:
        p[px] = py
    else:
        p[py] = px
        rank[px] += 1
    return 1
 
for a,b in ab:
    unite(a,b)

print( len(set(p)) - 1 )
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
cnt1 = x.count('1')
x10 = int(x,2)

if cnt1 > 1:
  x10mod_m = x10 % (cnt1-1)
  x10mod_p = x10 % (cnt1+1)
else:
  x10mod_m = 0
  x10mod_p = 0

ans = []
for i in range(n):
  if x[i] == '1':
    if cnt1 == 1:
      print(0)
      continue
    cntx = cnt1-1
    mod = ( x10mod_m - pow(2,n-1-i,cntx) ) % cntx
  else:
    cntx = cnt1+1
    mod = ( x10mod_p + pow(2,n-1-i,cntx) ) % cntx
    
  cnt = 1
  mod = format(mod, 'b')
  
  while True:
    if mod == '0':
      break
    mod = format( int(mod,2) % mod.count('1'), 'b')
    cnt += 1
  print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
cnt1 = x.count('1')
x10 = int(x,2)

if cnt1 > 1:
  x10mod_m = x10 % (cnt1-1)
  x10mod_p = x10 % (cnt1+1)
else:
  x10mod_m = 0
  x10mod_p = 0

ans = []
for i in range(n):
  add_val = add_val >> 1
  if x[i] == '1':
    if cnt1 == 1:
      print(0)
      continue
    cntx = cnt1-1
    mod = ( x10mod_m - pow(1,n-1-i,cntx) ) % cntx
  else:
    cntx = cnt1+1
    mod = ( x10mod_p + pow(1,n-1-i,cntx) ) % cntx
    
  cnt = 1
  mod = format(mod, 'b')
  
  while True:
    if mod == '0':
      break
    mod = format( int(mod,2) % mod.count('1'), 'b')
    cnt += 1
  print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = str(input())

def ppc(k): #k:2進数 bin
  cnt1 = sum( list(map(int, list(k) ) ) )
  k_10 = int(k, 2) #１０進数
  return format( k_10 % cnt1, 'b') #2adic

for i in range(n):
  ly = list(x)
  if ly[i] == '0':
    ly[i] = '1'
    y = ''.join(ly)
  else:
    ly[i] = '0'
    y = ''.join(ly)
  cnt = 0
  
  while True:
    if y == '0':
      break
    y = ppc(y)
    cnt += 1
  print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = str(input())

def ppc(k): #k:2進数 bin
  cnt1 = sum( list(k) )
  k_10 = int(k, 2) #１０進数
  return format( k_10 % cnt1, 'b') #2adic

for i in range(n):
  ly = list(x)
  if ly[i] == '0':
    ly[i] = '1'
    y = ''.join(ly)
  else:
    ly[i] = '0'
    y = ''.join(ly)
  cnt = 0
  
  while True:
    if y == '0':
      break
    y = ppc(y)
    cnt += 1
  print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = str(input())

def ppc(k): #k:2進数 bin
  cnt1 = sum( [1*(j == "1") for j in k] )
  k_10 = int(k, 2) #１０進数
  return format( k_10 % cnt1, 'b') #2adic

for i in range(n):
  ly = list(x)
  if ly[i] == '0':
    ly[i] = '1'
    y = ''.join(ly)
  else:
    ly[i] = '0'
    y = ''.join(ly)
  cnt = 0
  while True:
    y = ppc(y)
    cnt += 1
    if y == '0':
      break
  print(cnt)
Problem p02548 (python)

Fixed submission:
import math
n = int(input())
ans = 0

for a in range(1, n):
    ans += math.floor((n-1)/a)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import sympy
n = int(input())
ans = 0

for c in range(1,n):
    ab = n - c
    ans += sympy.divisor_count(ab)
        
print(ans)
Problem p02608 (python)

Fixed submission:
n = int(input())
num = [0]*10000

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x - 1
            if a <= 9999:
                num[a] += 1

num = num[:n]

for i in num:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
num = [0]*1000

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x - 1
            if a <= 1001:
                num[a] += 1

num = num[:n]

for i in num:
    print(i)