Problem p02609 (python)

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

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")
S_num = int(S,2)
S_min = S_num % (bit_count-1) if bit_count-1!=0 else 0
S_plu = S_num % (bit_count+1)




# calc_dict = {i:-1 for i in range(10000)}
# res_dict =  {i:-1 for i in range(10**4)}

# for i in range(1, 10000):
#     if calc_dict[i]==-1:
#         calc_dict[i] = bin(i).count("1")

#     res_dict[i] = i%calc_dict[i]+1

def mods(temp, count):
    count+=1
    if temp!=0:

#         if temp in res_dict:
#             return count+res_dict[temp]
        
#         if temp not in calc_dict:
#             calc_dict[temp]= bin(temp).count("1") 
        count = mods(temp%bin(temp).count("1") , count)

    return count

for i in range(N):
    if S[i]=="0":
        part = pow(2, (N-i-1), bit_count+1)
        num = (S_plu + part ) % (bit_count+1)
        print(mods(num, 0))
    else:
        if S_num == 2**(N-i-1):
            print(0)
            continue
        part = pow(2, (N-i-1), bit_count-1)
        num = (S_min - part)%(bit_count-1)
        print(mods(num, 0))

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")
S_min = int(S,2) % (bit_count-1) if bit_count-1!=0 else 0
S_plu = int(S,2) % (bit_count+1)
S_num = int(S,2)



calc_dict = {i:-1 for i in range(100000)}
res_dict =  {i:-1 for i in range(100000)}

for i in range(1, 100000):
    if calc_dict[i]==-1:
        calc_dict[i] = bin(i).count("1")

    res_dict[i] = i%calc_dict[i]+1

def mods(temp, count):
    count+=1
    while temp!=0:

        if temp in res_dict:
            return count+res_dict[temp]
        
        if temp in calc_dict:
            calc_dict[temp]=bin(temp).count("1")
        bits = calc_dict[temp]
            
        temp = temp%bits
        count+=1

    return count

for i in range(N):
    if S[i]=="0":
        part = (2**(N-i-1))% (bit_count+1)
        num = (S_plu + part ) % (bit_count+1)
        if num==0:
            print(1)
        else:
            print(mods(num, 0))
    else:
        if S_num == 2**(N-i-1):
            print(0)
            continue
        part = (2**(N-i-1))% (bit_count-1)
        num = (S_min - part)%(bit_count-1)
        if num==0:
            print(1)
        else:
            print(mods(num, 0))

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")
S_min = int(S,2) % (bit_count-1)
S_plu = int(S,2) % (bit_count+1)
S_num = int(S,2)

def mods(temp, count):
    count+=1
    while temp!=0:

#         if temp in res_dict:
#             print(count, temp, res_dict[temp])
#             print("come")
#             print()
#             return count+res_dict[temp]
        
#         if calc_dict[temp]==-1:
        bits = bin(temp).count("1")
            
        temp = temp%bits
        count+=1

    return count

for i in range(len(S)):
    if S[i]=="0":
        part = (2**(N-i-1))% (bit_count+1)
        num = (S_plu + part ) % (bit_count+1)
        if num==0:
            print(1)
        else:
            print(mods(num, 0))
    else:
        if S_num == 2**(N-i-1):
            print(0)
            continue
        part = (2**(N-i-1))% (bit_count-1)
        num = (S_min - part)%(bit_count-1)
        if num==0:
            print(1)
        else:
            print(mods(num, 0))

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

def ran(S, N):
    bit_count = S.count("1")

    #bit数
    calc_dict = {i:-1 for i in range(22000)}
    res_dict =  {i:-1 for i in range(2*(10**5))}

    res_dict = {i:-1 for i in range(1001)}
    res_dict[0]=0

    for i in range(1, 1001):
        if calc_dict[i]==-1:
            calc_dict[i] = bin(i).count("1")

        res_dict[i] = i%calc_dict[i]+1


    bit_count = S.count("1")
    for i in range(len(S)):
        if S[i]=="0":

            bit_count+=1
            num = int(S,2) + 2**(N-i-1)
            if num<=0:
                print(0)
            else:
                print(res_dict[num%bit_count]+1)
            bit_count-=1
        else:

            bit_count-=1
            num = int(S,2) - 2**(N-i-1)
            if num<=0:
                print(0)
            else:
                print(res_dict[num%bit_count]+1)
            bit_count+=1

ran(S,N)

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

def ran(S, N):
    bit_count = S.count("1")

    #bit数
    calc_dict = {i:-1 for i in range(22000)}
    res_dict =  {i:-1 for i in range(2*(10**5))}

    res_dict = {i:-1 for i in range(1001)}
    res_dict[0]=0

    for i in range(1, 1001):
        if calc_dict[i]==-1:
            calc_dict[i] = bin(i).count("1")

        res_dict[i] = i%calc_dict[i]+1


    bit_count = S.count("1")
    for i in range(len(S)):
        if S[i]=="0":

            bit_count+=1
            num = int(S,2) + 2**(N-i-1)
            if num==0:
                print(0)
            else:
                print(res_dict[num%bit_count]+1)
            bit_count-=1
        else:

            bit_count-=1
            num = int(S,2) - 2**(N-i-1)
            if num==0:
                print(0)
            else:
                print(res_dict[num%bit_count]+1)
            bit_count+=1

ran(S,N)

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")

#bit数
calc_dict = {i:-1 for i in range(22000)}
res_dict =  {i:-1 for i in range(2*(10**5))}

res_dict = {i:-1 for i in range(1001)}
res_dict[0]=0

for i in range(1, 1001):
    if calc_dict[i]==-1:
        calc_dict[i] = bin(i).count("1")
    
    res_dict[i] = i%calc_dict[i]+1


bit_count = S.count("1")
for i in range(len(S)):
    if S[i]=="0":

        bit_count+=1
        num = int(S,2) + 2**(N-i-1)
        if num==0 or bit_count==0:
            print(0)
        else:
            print(res_dict[num%bit_count]+1)
        bit_count-=1
    else:

        bit_count-=1
        num = int(S,2) - 2**(N-i-1)
        if num==0 or bit_count==0:
            print(0)
        else:
            print(res_dict[num%bit_count]+1)
        bit_count+=1

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(200000)

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")

#bit数
calc_dict = {i:-1 for i in range(22000)}
res_dict =  {i:-1 for i in range(2*(10**5))}

res_dict = {i:-1 for i in range(1001)}
res_dict[0]=0

for i in range(1, 1001):
    if calc_dict[i]==-1:
        calc_dict[i] = bin(i).count("1")
    
    res_dict[i] = i%calc_dict[i]+1


bit_count = S.count("1")
for i in range(len(S)):
    if S[i]=="0":

        bit_count+=1
        num = int(S,2) + 2**(N-i-1)
        if num==0:
            print(0)
        else:
            print(res_dict[num%bit_count]+1)

#         print(mods(num, bit_count, 0))
        bit_count-=1
    else:

        bit_count-=1
        num = int(S,2) - 2**(N-i-1)
        if num==0:
            print(0)
        else:
            print(res_dict[num%bit_count]+1)
        bit_count+=1

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")

#bit数
calc_dict = {i:-1 for i in range(22000)}
res_dict =  {i:-1 for i in range(2*(10**5))}

res_dict = {i:-1 for i in range(1001)}
res_dict[0]=0

for i in range(1, 1001):
    if calc_dict[i]==-1:
        calc_dict[i] = bin(i).count("1")
    
    res_dict[i] = i%calc_dict[i]+1


bit_count = S.count("1")
for i in range(len(S)):
    if S[i]=="0":

        bit_count+=1
        num = int(S,2) + 2**(N-i-1)
        if num==0:
            print(0)
        else:
            print(res_dict[num%bit_count]+1)

#         print(mods(num, bit_count, 0))
        bit_count-=1
    else:

        bit_count-=1
        num = int(S,2) - 2**(N-i-1)
        if num==0:
            print(0)
        else:
            print(res_dict[num%bit_count]+1)
        bit_count+=1

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")

#bit数
calc_dict = {i:-1 for i in range(22000)}
res_dict =  {i:-1 for i in range(2*(10**5))}

res_dict = {i:-1 for i in range(1001)}
res_dict[0]=0

for i in range(1, 1001):
    if calc_dict[i]==-1:
        calc_dict[i] = bin(i).count("1")
    
    res_dict[i] = i%calc_dict[i]+1




# def mods(N, m, count):
#     temp = N%m
#     count+=1
#     while temp!=0:

#         if temp in res_dict:
# #             print(count, temp, res_dict[temp])
# #             print("come")
# #             print()
#             return count+res_dict[temp]
        
#         if calc_dict[temp]==-1:
#             calc_dict[temp] = bin(temp).count("1")
            
#         temp = temp%calc_dict[temp]
#         count+=1

#     return count

bit_count = S.count("1")
for i in range(len(S)):
    if S[i]=="0":

        bit_count+=1
        num = int(S,2) + 2**(N-i-1)
#         print(num, bit_count)
        print(res_dict[num%bit_count]+1)
#         print(mods(num, bit_count, 0))
        bit_count-=1
    else:

        bit_count-=1
        num = int(S,2) - 2**(N-i-1)
        print(res_dict[num%bit_count]+1)
#         print(mods(num, bit_count, 0))
        bit_count+=1

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(200000)

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")

#bit数
calc_dict = {i:-1 for i in range(22000)}
res_dict =  {i:-1 for i in range(2*(10**5))}

res_dict = {i:-1 for i in range(1001)}
res_dict[0]=0

for i in range(1, 1001):
    if calc_dict[i]==-1:
        calc_dict[i] = bin(i).count("1")
    
    res_dict[i] = i%calc_dict[i]+1




def mods(N, m, count):
    temp = N%m
    count+=1
    while temp!=0:

        if temp in res_dict:
#             print(count, temp, res_dict[temp])
#             print("come")
#             print()
            return count+res_dict[temp]
        
        if calc_dict[temp]==-1:
            calc_dict[temp] = bin(temp).count("1")
            
        temp = temp%calc_dict[temp]
        count+=1

    return count

bit_count = S.count("1")
for i in range(len(S)):
    if S[i]=="0":

        bit_count+=1
        num = int(S,2) + 2**(N-i-1)
#         print(num, bit_count)
        print(mods(num, bit_count, 0))
        bit_count-=1
    else:

        bit_count-=1
        num = int(S,2) - 2**(N-i-1)
        print(mods(num, bit_count, 0))
        bit_count+=1

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(2000000)

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")

bit_count

#bit数
calc_dict = {i:-1 for i in range(22)}

def mods(N, m, count):
    temp = N%m
    if temp==0:
        return count+1
    
    if calc_dict[temp]==-1:
        calc_dict[temp] = bin(temp).count("1")

    return mods(temp, calc_dict[temp], count+1)

bit_count = S.count("1")
for i in range(len(S)):
    if S[i]=="0":

        bit_count+=1
        num = int(S,2) + 2**(N-i-1)
        print(mods(num, bit_count, 0))
        bit_count-=1
    else:

        bit_count-=1
        num = int(S,2) - 2**(N-i-1)
        print(mods(num, bit_count, 0))
        bit_count+=1

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(2000)

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

bit_count = S.count("1")

bit_count

#bit数
calc_dict = {i:-1 for i in range(22)}

def mods(N, m, count):
    temp = N%m
    if temp==0:
        return count+1
    
    if calc_dict[temp]==-1:
        calc_dict[temp] = bin(temp).count("1")

    return mods(temp, calc_dict[temp], count+1)

bit_count = S.count("1")
for i in range(len(S)):
    if S[i]=="0":

        bit_count+=1
        num = int(S,2) + 2**(N-i-1)
        print(mods(num, bit_count, 0))
        bit_count-=1
    else:

        bit_count-=1
        num = int(S,2) - 2**(N-i-1)
        print(mods(num, bit_count, 0))
        bit_count+=1