Problem p02609 (python)

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low if low!=0 else 0) 

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

ans_high=0
for i in range(N):
    if X[i] == "1":
        ans_high+=mod_h[i]
ans_high%=high

ans_low=0
for i in range(N):
    if X[i] == "1":
        ans_low+=mod_l[i]
ans_low%=low if low!=0 else 1
        
for i in range(N):
    if X[i]=="0":
        ans=ans_high
        ans+=mod_h[i]
        ans%=high
    else:
        if low==0:
            print(0)
            continue
        ans=ans_low
        ans-=mod_l[i]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

ans_high=0
for i in range(N):
    if X[i] == "1":
        ans_high+=mod_h[i]
ans_high%=high

ans_low=0
for i in range(N):
    if X[i] == "1":
        ans_low+=mod_l[i]
ans_low%=low
        
for i in range(N):
    if X[i]=="0":
        ans=ans_high
        #high_root
        """
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        """
        ans+=mod_h[i]
        ans%=high
    else:
        ans=ans_low
        """
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        """
        ans-=mod_l[i]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]
X_10=sum([2**i*int(X[N-i-1]) for i in range(N)])

for i in range(N):
    ans=X_10
    if X[i]=="0":
        #high_root
        """
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        """
        ans+=mod_h[i]
        ans%=high
    else:
        """
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        """
        ans-=mod_l[i]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]
X_10=sum([2**i*int(X[N-i-1]) for i in range(N)])

for i in range(N):
    ans=X_10
    if X[i]=="0":
        #high_root
        """
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        """
        ans+=mod_h[i]
        ans%=high
    else:
        """
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        """
        ans-=mod_l[i]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

for i in range(N):
    ans=0
    if X[i]=="0":
        #high_root
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        ans%=high
    else:
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        ans%=low
    
    count=1
    """
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    """
    print(count)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

for i in range(N):
    ans=0
    if X[i]=="0":
        #high_root
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        ans%=high
    else:
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        ans%=low
    """
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    """
    print(count)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

for i in range(N):
    ans=0
    if X[i]=="0":
        #high_root
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        ans%=high
    else:
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

for i in range(N):
    ans=0
    if X[i]=="0":
        #high_root
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        ans%=high
    else:
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)