Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,k=mii()
arr=limii()

b=[10**100]*n
b[0]=0

for i in range(1,n):
    ans=10**100
    for j in range(1,k+1):
        ans = min(ans,b[i-j]+abs(arr[i]-arr[i-j]))
    b[i]= ans

print(b[-1])


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #整数1つinput
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii())
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #文字列1つinput
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

n,k = mii()
arr = limii()
dp = [0]*n
chk=True
cnt=1
while chk:
    q = cnt-k
    if q<0:q=0
    add =[]
    for i in range(q,cnt): 
        add.append(abs(arr[cnt]-arr[i])+dp[i])
    dp[cnt] = min(add)
    if cnt==n-1:
        chk=False
    cnt+=1

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #整数1つinput
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii())
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #文字列1つinput
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

n,w = mii()
wei,val= [0],[0]
for _ in range(n):
    p,q=mii()
    wei.append(p)
    val.append(q)

dp = [[0]*(w+1) for _ in range(n+1)]

for i in range(1,n+1):
    for j in range(1,w+1):
        if wei[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j-wei[i]]+val[i],dp[i-1][j])


print(dp[-1][-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #整数1つinput
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii())
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #文字列1つinput
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

n,w = mii()
wei=[]
val=[]
for i in range(n):
    ww,vv=map(int,input().split())
    wei.append(ww)
    val.append(vv)
#dp[i][j]:i番目まで選んで、価値がj以上となる最小の重さ
dp=[[10**10]*(sum(val)+1) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
    for j in range(sum(val)+1):
        if j>=val[i]:
            dp[i+1][j]=min(dp[i][j-val[i]]+wei[i],dp[i][j])
        else:
            dp[i+1][j]=dp[i][j]
ans=[]
for i in range(sum(val)+1):
    if dp[n][i]<=w:
        ans.append(i)
print(max(ans))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m=mii()
s=ii()
t=ii()

p=gcd(s,t)
if p!=s and p!=t and s[0]==p[0]:
    print(p)
else:
    print(-1)


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m=mii()
s=ss()
t=ss()
if len(s) < len(t):
    s,t=t,s
    n,m=m,n

p=n*m//gcd(n,m)
q=gcd(n,m)
if s[0]==t[0]:

    x,y=n//gcd(n,m),m//gcd(n,m)
    cnt=1

    for i in range(gcd(n,m)-1):
        if s[i*x]==t[i*y]:
            cnt+=1
    if cnt==q:
        print(p)
    else:
        print(-1)

else:
    print(-1)
#print(cnt,y)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

d,g = map(int,input().split())
    
arr = []
    
for i in range(d):
    arr.append(list(map(int,input().split())))
    
ans = 10**10

for i in itertools.product((0,1),repeat=d**2):
    score=0
    num=0
    index=0
    
    for j in range(d):
        if i[j]==1:
            score += (j+1)*100*arr[j][0] + arr[j][1]
            num +=arr[j][0]
        else:
            index = max(j,index)
    
    if g - score <=0:
        ans = min(ans,num)
    
    elif g - score <= (index+1) *100*(arr[index][0]-1):
        num+= -(-(g-score)//(100*(index+1)))
        ans =min(ans,num)

print(ans)

Fixed submission:
d,g = map(int,input().split())
    
arr = []
    
for i in range(d):
    arr.append(list(map(int,input().split())))
    
from itertools import product
from math import ceil
    
ans = 1e09
#各問題を選択するしないを01表記
for c in product([0,1],repeat=d):
    #print(c)
    #スコア
    score = 0
    #解く問題数
    num = 0
    
    ind = 0
    #まず01表記を全て
    for i in range(d):
        #もし01表記で1の場合，完答した場合の点数，問題数を加算
        if c[i] == 1:
            score += arr[i][0]*100*(i+1) + arr[i][1]
            num += arr[i][0]
        #0だった場合，
        else:
            ind = max(i,ind)
    #目標よりも点数が大きかった場合，小さい方を答えにする
    if g - score <= 0:
        ans = min(ans,num)
        #print(0,ans,num,score,ind)
    #もし目標が，点数とind番目の問題を完答してない場合との和より小さい時
    elif g - score <= (arr[ind][0]-1)*100*(ind+1):
        num += ceil((g-score)/(100*(ind+1)))
        ans = min(ans,num)
        #print(1,ans,num,score,ind)
    else:
        pass
#print(2,num,score,ind)
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools

n,m=map(int,input().split())

if n ==2:
    print(1)
    exit()

arr=[[_] for _ in range(n)]

for i in range(n):
    a,b=map(int,input().split())
    
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)
for i in range(n):
    arr[i] = arr[i][1:]
#print("arr",arr)

route=list(itertools.permutations(range(1,n)))
#print("route",route) 
ans=0
for i in route:
    chk0=False
    chk=True
    if i[0] in arr[0]:
        #print(i)
        for j in range(1,n-1):
            if i[j] in arr[i[j-1]]:
                chk0=True
                #print(i[j],arr[j])
                pass
            else:
                chk=False
    if chk==True and chk0==True:
        #print(i)
        ans+=1

print(ans)

Fixed submission:
import itertools

n,m=map(int,input().split())

if n ==2:
    print(1)
    exit()

arr=[[_] for _ in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    #print(a,b)
    
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

#print("arr",arr)

route=list(itertools.permutations(range(1,n)))
#print("route",route) 
ans=0
for i in route:
    chk0=0
    chk=True
    if i[0] in arr[0]:
        chk0 =True
        #print(i)
        for j in range(1,n-1):
            if i[j] in arr[i[j-1]]:
                chk0+=1
                
                pass
            else:
                #print(1,i[j],arr[i[j-1]])
                break
                
    if chk0==n-1:
        
        ans+=1

print(ans)

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

n,m=map(int,input().split())

if n ==2:
    print(1)
    exit()

arr=[[_] for _ in range(n)]

for i in range(n):
    a,b=map(int,input().split())
    
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

#print("arr",arr)

route=list(itertools.permutations(range(1,n)))
#print("route",route) 
ans=0
for i in route:
    chk0=False
    chk=True
    if i[0] in arr[0]:
        #print(i)
        for j in range(1,n-1):
            if i[j] in arr[i[j-1]]:
                chk0=True
                #print(i[j],arr[j])
                pass
            else:
                chk=False
    if chk==True and chk0==True:
        #print(i)
        ans+=1

print(ans)

Fixed submission:
import itertools

n,m=map(int,input().split())

if n ==2:
    print(1)
    exit()

arr=[[_] for _ in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    #print(a,b)
    
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

#print("arr",arr)

route=list(itertools.permutations(range(1,n)))
#print("route",route) 
ans=0
for i in route:
    chk0=0
    chk=True
    if i[0] in arr[0]:
        chk0 =True
        #print(i)
        for j in range(1,n-1):
            if i[j] in arr[i[j-1]]:
                chk0+=1
                
                pass
            else:
                #print(1,i[j],arr[i[j-1]])
                break
                
    if chk0==n-1:
        
        ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

res=Counter(arr)

if len(list(res))%2==0:
    print(len(list(res))-1)
else:
    print(len(list(res)))








Fixed submission:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

res=Counter(arr)

if len(list(res))%2==0:
    print(len(list(res))-1)
else:
    print(len(list(res)))
Buggy python submission (verdict: Runtime Error):
n = int(input())

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

    # divisors.sort()
    return divisors

import math

num = math.factorial(n)

print(len(divi(num))%1000000007)

Fixed submission:
n = int(input())

def fact(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if n == 1:
    print(1)
    exit()

arr = [0 for _ in range(1001)]

for i in range(1,n+1):

    for j in range(len(fact(i))):
        arr[fact(i)[j][0]] += fact(i)[j][1]

ans = 1
for i in range(2,1001):
    if arr[i] > 0:
        ans *= arr[i] +1
    if ans > 1000000007:
        ans % 1000000007

print(ans % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

k,s=mii()

cnt=0

for i in range(0,k+1):
    for j in range(0,k+1):
        for k in range(0,k+1):
            if i+j+k==s:
                cnt+=1
print(cnt)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

k,s=mii()

cnt=0

for i in range(0,k+1):
    for j in range(0,k+1):
        if 0<=s-(i+j)<=k:
            cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

#https://atcoder.jp/contests/cf16-final-open/tasks/codefestival_2016_final_b

n=ii()

if n==1:
    print(1)
    exit()

ans=0
i=0
while ans<n:
    i+=1
    ans+=i
if ans>n:
    p=ans-n

for k in range(1,i+1):
    if k!=p:
        print(k)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

#https://atcoder.jp/contests/cf16-final-open/tasks/codefestival_2016_final_b

n=ii()

if n==1:
    print(1)
    exit()

ans=0
i=0
p=0
while ans<n:
    i+=1
    ans+=i
if ans>n:
    p=ans-n

for k in range(1,i+1):
    if k!=p:
        print(k)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
X=input()

def pop(x): #10進数
    ret=0
    while x>0:
        ret+=x%2
        x//=2
    return ret

def solve(x): #10進数
    ret=0
    while x>0:
        pop_c=pop(x)
        x%=pop_c
        ret+=1
    return ret

mod=X.count("1") #>0
for i in range(N):
    if X[i]=="0":
        tmp="".join([X[:i],"1",X[i+1:]])
        tmp=int(tmp,2)%(mod+1)
        print(solve(tmp)+1)
    else:
        if mod==1:
            print(0)
            continue
        tmp="".join([X[:i],"0",X[i+1:]])
        tmp=int(tmp,2)%(mod-1)
        print(solve(tmp)+1)


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

def pop(x): #10進数
    ret=0
    while x>0:
        ret+=x%2
        x//=2
    return ret

def solve(x): #10進数
    ret=0
    while x>0:
        pop_c=pop(x)
        x%=pop_c
        ret+=1
    return ret

mod=X.count("1") #>0
original_plus=0
original_minus=0
for i in range(N):
    if X[N-1-i]=="1":
        if mod>1:
            original_minus+=pow(2,i,mod-1)
        original_plus+=pow(2,i,mod+1)
original_plus%=mod+1
if mod>1:
    original_minus%=mod-1
for i in range(N):
    if X[i]=="0":
        tmp=original_plus+pow(2,N-1-i,mod+1)
        tmp%=mod+1
        print(solve(tmp)+1)
    else:
        if mod==1:
            print(0)
            continue
        tmp=original_minus-pow(2,N-1-i,mod-1)
        tmp%=mod-1
        print(solve(tmp)+1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
X=input()

def pop(x): #10進数
    ret=0
    while x>0:
        ret+=x%2
        x//=2
    return ret

def solve(x): #10進数
    ret=0
    while x>0:
        pop_c=pop(x)
        x%=pop_c
        ret+=1
    return ret

mod=X.count("1") #>0
for i in range(N):
    if X[i]=="0":
        tmp="".join([X[:i],"1",X[i+1:]])
        tmp=int(tmp,2)%(mod+1)
        print(solve(tmp)+1)
    else:
        if mod==1:
            print(0)
            continue
        tmp="".join([X[:i],"0",X[i+1:]])
        tmp=int(tmp,2)%(mod-1)
        print(solve(tmp)+1)


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

def pop(x): #10進数
    ret=0
    while x>0:
        ret+=x%2
        x//=2
    return ret

def solve(x): #10進数
    ret=0
    while x>0:
        pop_c=pop(x)
        x%=pop_c
        ret+=1
    return ret

mod=X.count("1") #>0
original_plus=0
original_minus=0
for i in range(N):
    if X[N-1-i]=="1":
        if mod>1:
            original_minus+=pow(2,i,mod-1)
        original_plus+=pow(2,i,mod+1)
original_plus%=mod+1
if mod>1:
    original_minus%=mod-1
for i in range(N):
    if X[i]=="0":
        tmp=original_plus+pow(2,N-1-i,mod+1)
        tmp%=mod+1
        print(solve(tmp)+1)
    else:
        if mod==1:
            print(0)
            continue
        tmp=original_minus-pow(2,N-1-i,mod-1)
        tmp%=mod-1
        print(solve(tmp)+1)