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

Fixed submission:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n = getN()
    lis = getList()
    xo, su = 0, 0
    ans = 0
    l, r = 0, 0
    forward = True
    while True:
        # print(l, r, ans, xo, su)
        if r == n:
            print(ans)
            return
        if forward:
            xo = xo^lis[r]
            su += lis[r]
            if xo == su:

                ans += r - l + 1
                r += 1
            else:
                forward = False
        else:
            xo = xo^lis[l]
            su -= lis[l]
            if xo == su:
                forward = True
                ans += r - l
                r += 1
                l += 1
            else:
                l += 1

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

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

nm_list = [(bin(x)[2:][::-1] + "0" * 20) for x in nums]
lmax = len(nm_list)
accum = [[0] for i in range(21)] #[0]が下位ビット

for i,b in enumerate(nm_list[0][:21]):
    print(accum)
    accum[i][0] += int(b)


for nm in nm_list[1:]:
    for i, b in enumerate(nm[:21]):
        print(i)
        accum[i].append(accum[i][-1] + int(b))

def syakutori():
    ans = 0
    bits = [0]*21
    r = 0
    l = 0
    flag = True
    #尺取り法をする
    while(r < lmax):
        if flag:
            #rを伸ばす
            flag = max([accum[i][r] - accum[i][l] for i in range(21)]) <= 1
            print("a", l, r, flag)
            r += 1
            if flag:
                ans += (r -l)

        else:
            #lを縮める
            flag = max([accum[i][r] - accum[i][l] for i in range(21)]) <= 1
            print("a", l, r, flag)
            l += 1
            if flag:
                ans += (r - l)

    #後処理をする
    while(not flag):
        flag = max([accum[i][r] - accum[i][l] for i in range(21)]) <= 1
        l += 1
        if flag:
            ans += (r - l)

    return ans


print(syakutori())
Problem p03504 (python)

Fixed submission:
import sys
import math
import copy
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def solve():
    n,C = getList()
    li = []

    start = [[0] * 100100 for i in range(31)]
    end = [[0] * 100100 for i in range(31)]
    pt = [0] * 100100

    for i in range(n):
        s, t, c = getList()
        start[c][s] += 1
        end[c][t] += 1
        pt[s] += 1
        pt[t+1] -= 1

    for i in range(100099):
        pt[i+1] += pt[i]

    ans = 0
    for i in range(100100):
        tmp = pt[i]
        for j in range(31):
            if start[j][i] and end[j][i]:
                tmp -= 1
        ans = max(ans, tmp)

    print(ans)






def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n, cc = getMN()
jikan = [0 for i in range(100001)]
for i in range(n):
    s, t, c = getlist()
    jikan[s] += 1
    jikan[t+1] -= 1

accum = [0]
for j in jikan:
    accum.append(accum[-1]+j)

print(max(accum))

Buggy submission (verdict: Runtime Error):
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n, cc = getMN()
jikan = [0 for i in range(10001)]
for i in range(n):
    s, t, c = getlist()
    jikan[s] += 1
    jikan[t+1] -= 1

accum = [0]
for j in jikan:
    accum.append(accum[-1]+j)

print(max(accum))
Problem p03534 (python)

Fixed submission:
from collections import Counter

s = input().strip() + "abc"
c = Counter(s)
v = list(c.values())
if max(v) - min(v) > 1: 
  print("NO")
else:
  print("YES")

Buggy submission (verdict: Runtime Error):
rom collections import Counter

s = input().strip()
c = Counter(s)
v = list(c.values())
if max(v) - min(v) > 1: 
  print("NO")
else:
  print("YES")
Problem p03612 (python)

Fixed submission:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
ans = 0
N = getN()
list = getList()
bind = []
for i, x in enumerate(list):
    if x == i+1:
        bind.append(x)
p = 0
l = len(bind)
while p<l:
    ans += 1
    if p == l-1:
        p += 1
    elif bind[p] + 1 == bind[p+1]:
        p += 2
    else:
        p += 1


print(ans)

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

flag = 0
ans = 0
for i, num in enumerate(nums):
  if i == num:
    if flag:
      ans += 1 
      flag = 0
    else:
      flag = 1
  else:
    if flag == 1:
      ans += 1
      flag = 0
      
if flag == 1:
  ans += 1
  
print(ans)
Problem p03623 (python)

Fixed submission:
getList = lambda: list(map(int, input().split()))
x,a,b = getList()
if abs(a - x) < abs(b - x):
  print("A")
else:
  print("B")

Buggy submission (verdict: Runtime Error):
getList = lambda: list(map(int, input().split()))
a,b,x = getList()
if abs(a - x) < abs(b = x):
  print("A")
else:
  print("B")
Problem p03626 (python)

Fixed submission:
N = int(input())
upper = list(input())
lower = list(input())
ans = 0

def count(upper, lower, state):
    global ans
    if upper[0] == lower[0]:
        if state == 1:
            ans *= 2
            try:
                count(upper[1:],lower[1:],state=1)
            except:
                return ans
        if state == 2:
            try:
                count(upper[1:], lower[1:], state=1)
            except:
                return ans
    else:
        if state == 1:
            ans *= 2
            try:
                count(upper[2:], lower[2:], state=2)
            except:
                return ans
        if state == 2:
            ans *= 3
            try:
                count(upper[2:], lower[2:], state=2)
            except:
                return ans

if upper[0] == lower[0]:
    ans = 3
    try:
        count(upper[1:], lower[1:], state=1)
    except:
        pass
else:
    ans = 6
    try:
        count(upper[2:], lower[2:], state=2)
    except:
        pass

print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
N = int(input())
upper = list(input())
lower = list(input())
ans = 0

def count(upper, lower, state):
    global ans
    if upper[0] == lower[0]:
        if state == 1:
            ans *= 2
            try:
                count(upper[1:],lower[1:],state=1)
            except:
                return ans
        if state == 2:
            try:
                count(upper[1:], lower[1:], state=1)
            except:
                return ans
    else:
        if state == 1:
            ans *= 2
            try:
                count(upper[2:], lower[2:], state=2)
            except:
                return ans
        if state == 2:
            ans *= 3
            try:
                count(upper[2:], lower[2:], state=2)
            except:
                return ans

if upper[0] == lower[0]:
    ans = 3
    count(upper[1:], lower[1:], state=1)
else:
    ans = 6
    count(upper[2:], lower[2:], state=2)

print(ans%1000000007)
Problem p03633 (python)

Fixed submission:
from fractions import gcd

def lcm(x, y):
    return (x*y) // gcd(x, y)

def getN():
    return int(input())
# print(lcm(10, 20))

n = getN()
ans = 1
for i in range(n):
    t = getN()
    ans = lcm(ans, t)

print(ans)

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return math.gcd(x, y)
 
n = int(input())
ans = int(input())
for i in range(n-1):
  tmp = int(input())
  ans = lcm(ans,tmp)
  
print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
 
n = int(input())
ans = int(input())
for i in range(n-1):
  tmp = int(input())
  ans = lcm(ans,tmp)
  
print(ans)

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n = int(input)
ans = int(input)
for i in range(n-1):
  tmp = int(input)
  ans = lcm(ans,tmp)
  
print(ans)

Buggy submission (verdict: Runtime Error):
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n = int(input)
ans = int(input)
for i in range(n-1):
  tmp = int(input)
  ans = lcm(ans,tmp)
  
print(ans)
Problem p03676 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from collections import deque

class SegTree():
    def __init__(self, n):
        self.value = [0 for i in range(n*2)]

MOD = 10 ** 9 + 7

def getinvmod(n):
    return [pow(i, MOD-2, MOD) for i in range(n+1)]


def main():
    n = getN()
    nums = getList()
    index = [-1 for i in range(n)]

    for i, num in enumerate(nums):
        if index[num - 1] == -1:
            index[num - 1] = i
        else:
            ida = i
            idb = index[num - 1]
            break

    side = n - (ida - idb)

    invmod = getinvmod(n+1)

    # print(invmod)
    #
    # print([(i * iv) % MOD for i, iv in enumerate(invmod)])
    ans = n + 1
    minus = 1
    print((ans - minus)%MOD)
    # print(side, ida, idb,"side")
    for i in range(1, n + 1):
        ans *= (n - i + 1)
        ans *= invmod[i + 1]
        ans %= MOD
        if i <= side:
            minus *= side - i + 1
            minus *= invmod[i]
            minus %= MOD

        else:
            minus = 0

        print((ans - minus) % MOD)
        # print(ans, minus)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from collections import deque

class SegTree():
    def __init__(self, n):
        self.value = [0 for i in range(n*2)]

MOD = 10 ** 9 + 7

def getinvmod(n):
    return [pow(i, MOD-2, MOD) for i in range(n+1)]


def main():
    n = getN()
    nums = getList()
    index = [0 for i in range(n)]

    for i, num in enumerate(nums):
        if index[num - 1] == 0:
            index[num - 1] = i
        else:
            ida = i
            idb = index[num - 1]
            break

    side = n - (ida - idb)

    invmod = getinvmod(n+1)

    # print(invmod)
    #
    # print([(i * iv) % MOD for i, iv in enumerate(invmod)])
    ans = n + 1
    minus = 1
    print((ans - minus)%MOD)
    # print(side, ida, idb,"side")
    for i in range(1, n + 1):
        ans *= (n - i + 1)
        ans *= invmod[i + 1]
        ans %= MOD
        if i <= side:
            minus *= side - i + 1
            minus *= invmod[i]
            minus %= MOD

        else:
            minus = 0

        print((ans - minus) % MOD)
        # print(ans, minus)



if __name__ == "__main__":
    main()
Problem p03737 (python)

Fixed submission:
strs = input().split()
print("".join([a[0].upper() for a in strs]))

Buggy submission (verdict: Runtime Error):
strs = input.split()
print("".join([a[0].upper() for a in strs]))
Problem p03814 (python)

Fixed submission:
s = input()
 
aind = 0
for i , c in enumerate(s):
  if c == "A":
    aind =  i
    break
zind = 0
for i,c in enumerate(s):
  if c == "Z":
    zind = i
    
print(zind-aind + 1)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(n)
aind = 0
for i , c in enumerate(s):
  if c == "A":
    aind =  i
    break
zind = 0
for i,c in enumerate(s):
  if c == "Z":
    zind = i
    
print(zind-aind)
Problem p03818 (python)

Fixed submission:
from collections import defaultdict
def getN():
    return int(input())


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


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

N = getN()
nums = getList()
dup = defaultdict(int)

for n in nums:
    dup[n] += 1

poss = len(dup.keys())
dupdup = 0
for val in dup.values():
    if val % 2 == 0:
        dupdup += 1

if dupdup % 2 == 0:
    print(poss)
else:
    print(poss-1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def getN():
    return int(input())


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


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

N = getN()
nums = getList()
dup = defaultdict(int)

for n in nums:
    dup[n] += 1

poss = len(dup.keys())
dupdup = 0
for val in dup.values():
    if val % 2 == 0:
        dupdup += 1

if dupdup % 2 == 0:
    print(poss)
else:
    print(poss-1)
Problem p03831 (python)

Fixed submission:
n,a,b = map(int,input().split())

nums=list(map(int,input().split()))
tmp=nums[0]
ans=0
for num in nums[1:]:
  if (num-tmp)*a<=b: 
    ans+=(num-tmp)*a
  else:
    ans+=b
  tmp=num

print(ans)

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

nums=list(map(int,input().split))
tmp=nums[0]
ans=0
for num in nums[1:]:
  if (nuw-tmp)*a<=b: 
    ans+=(num-tmp!)*a
  else:
    ans+=b
  tmp=num

print(ans)
Problem p03865 (python)

Fixed submission:
s = input().strip()
l = len(s)
 
if (l + (s[0] == s[-1])) % 2:
  print("First")
else:
  print("Second")

Buggy submission (verdict: Runtime Error):
s = input().strip()
l = len(s)

if (l + s[0] == s[-1]) % 2:
  print("First")
else:
  print("Second")
Problem p04039 (python)

Fixed submission:
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


N,K = input().split()
N = int(N)

d = [int(i) for i in input().split()]

for i in range(100001):
    if i >= N :
        if dig_check(i,d):
            print(i)
            break

Buggy submission (verdict: Runtime Error):
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


N,K = input.split()
N = int(N)

d = [int(i) for i in input.split()]

for i in range(10001):
    if i > N :
        if dig_check(i,d):
            print(i)
            break
Problem p04044 (python)

Fixed submission:
def getlist():
    return list(map(int, input().split()))
  
a,b = getlist()
lis = []
for i in range(a):
  lis.append(input().strip())
  
lis.sort()
print("".join(lis))

Buggy submission (verdict: Runtime Error):
def getlist():
    return list(map(int, input().split()))
  
a,b = getList()
lis = []
for i in range(a):
  lis.append(input().strip())
  
lis.sort()
print("".join(lis))
Problem p02556 (python)

Fixed submission:
N = int(input())
z = []
zz = []
for _ in range(N):
    x, y = map(int, input().split())
    zz.append(x-y)
    z.append(x+y)
z.sort()
zz.sort()
ans = z[-1]-z[0]
ans = max(ans, zz[-1]-zz[0])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
dic = defaultdict(list)
inf = 10**6
N = int(input())
l = []
z = []
xma, xmi, yma, ymi = 0, inf, 0, inf
for _ in range(N):
    x, y = map(int, input().split())
    xma = max(xma, x)
    yma = max(yma, y)
    xmi = min(xmi, x)
    ymi = min(ymi, y)
    l.append([x, y])
    z.append(x+y)
z.sort()
ans = z[-1]-z[0]

for t in l:
    a = t[0]+t[1]
    dic[a].append(t)
for u in dic:
    dic[u].sort()
    b = dic[u][-1][0]-dic[u][0][0]
    ans = max(2*b,ans)
    
l1, l2, l3, l4 = [], [], [], []
for k in l:
    if k[0]==xma:
        l1.append([k[1], k[0]])
    elif k[1]==yma:
        l2.append([k[0], k[1]])
    elif k[0]==xmi:
        l3.append([k[1], k[0]])
    elif k[1]==ymi:
        l4.append([k[0], k[1]])
l1.sort()
l2.sort()
l3.sort()
l4.sort()
print(xma, xmi, yma, ymi)
print(l1, l2, l3, l4)
ans = max(ans, abs(l1[0][1]-l3[-1][1])+abs(l1[0][0]-l3[-1][0]))
ans = max(ans, abs(l1[-1][1]-l3[0][1])+abs(l1[-1][0]-l3[0][0]))
ans = max(ans, abs(l2[0][1]-l4[-1][1])+abs(l2[0][0]-l4[-1][0]))
ans = max(ans, abs(l2[-1][1]-l4[0][1])+abs(l2[-1][0]-l4[0][0]))

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
dic = defaultdict(list)
inf = 10**6
N = int(input())
l = []
z = []
xma, xmi, yma, ymi = 0, inf, 0, inf
for _ in range(N):
    x, y = map(int, input().split())
    xma = max(xma, x)
    yma = max(yma, y)
    xmi = min(xmi, x)
    ymi = min(ymi, y)
    l.append([x, y])
    z.append(x+y)
z.sort()
ans = z[-1]-z[0]

for t in l:
    a = t[0]+t[1]
    dic[a].append(t)
for u in dic:
    dic[u].sort()
    b = dic[u][-1][0]-dic[u][0][0]
    ans = max(2*b,ans)
    
l1, l2, l3, l4 = [], [], [], []
for k in l:
    if k[0]==xma:
        l1.append([k[1], k[0]])
    elif k[0]==yma:
        l2.append([k[0], k[1]])
    elif k[1]==xmi:
        l3.append([k[1], k[0]])
    elif k[1]==ymi:
        l4.append([k[0], k[1]])
l1.sort()
l2.sort()
l3.sort()
l4.sort()
       
ans = max(ans, abs(l1[0][1]-l3[-1][1])+abs(l1[0][0]-l3[-1][0]))
ans = max(ans, abs(l1[-1][1]-l3[0][1])+abs(l1[-1][0]-l3[0][0]))
ans = max(ans, abs(l2[0][1]-l4[-1][1])+abs(l2[0][0]-l4[-1][0]))
ans = max(ans, abs(l2[-1][1]-l4[0][1])+abs(l2[-1][0]-l4[0][0]))

print(ans)
Problem p02585 (python)

Fixed submission:
n, k =map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
roop = []
seen = [0 for  _ in range(n)]
count = 0
for i in range(n):
    if seen[i]>0:
        continue
    else:
        count+=1
        seen[i] = count
        roop.append([c[i]])
        t = i
        while i!=p[t]-1:
            seen[p[t]-1]=count
            roop[-1].append(c[p[t]-1])
            t = p[t]-1
#print(seen)
#print(roop)
ans = max(c)

for i in roop:
    #print(ans)
    
    s = sum(i)
    ii = i+i
    #print(ii)
    if len(i)>=k:
        for j in range(1, k+1):
            temp = sum(ii[:j])
            for l in range(len(i)):
                if l!=0:
                    temp+=ii[l+j-1]
                    temp-=ii[l-1]
                    #temp = sum(ii[l:l+j])
                #print(i, j, l, temp)
                ans  = max(ans, temp)
    else:
        for j in range(1, len(i)+1):
            temp=  sum(ii[:j])
            for l in range(len(i)):
                if l != 0:
                    temp+=ii[l+j-1]
                    temp-=ii[l-1]
                #print(temp)
                if s>0:
                    temp1 = temp+s*((k-j)//len(i))
                else:
                    temp1 = temp
                
                #print(i, j, l, temp)
                ans  = max(ans, temp)
                ans  = max(ans, temp1)
            
print(ans)

Buggy submission (verdict: Runtime Error):
n, k =map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
roop = []
seen = [0 for  _ in range(n)]
count = 0
for i in range(n):
    if seen[i]>0:
        continue
    else:
        count+=1
        seen[i] = count
        roop.append([c[i]])
        t = i
        while i!=p[t]-1:
            seen[p[t]-1]=count
            roop[-1].append(c[p[t]-1])
            t = p[t]-1
#print(seen)
#print(roop)
ans = max(c)

for i in roop:
    #print(ans)
    
    s = sum(i)
    ii = i+i
    #print(ii)
    if len(i)>=k:
        for j in range(1, k+1):
            temp = sum(ii[:j])
            for l in range(len(i)):
                if l!=0:
                    temp+=ii[l+j-1]
                    temp-=ii[l-1]
                    #temp = sum(ii[l:l+j])
                #print(i, j, l, temp)
                ans  = max(ans, temp)
    else:
        for j in range(1, len(i)+1):
            temp=  sum(ii[:j])
            for l in range(len(i)):
                if l != 0:
                    temp+=ii[l+j-1]
                    temp-=ii[l-1]
                #print(temp)
                if s>0:
                    temp1 = temp+s*((k-j)//len(i))
                
                #print(i, j, l, temp)
                ans  = max(ans, temp)
                ans  = max(ans, temp1)
            
print(ans)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = str(input())

one = x.count("1")
X = int(x, 2)

if one==1:
    for i in range(n):
        if x[i]=="1":
            print(0)
        elif i==n-1:
            print(2)
        else:
            print(1)
    
    
elif one>1:
    
    Xp = X % (one+1)
    Xm = X % (one-1)

    def f(x):
        if x==0:
            return 0
        return 1+f(x%bin(x).count("1"))

    for i in range(n):
        
        if x[i]=="0":
            c = pow(2, n-i-1, one+1)
            print(f((Xp+c)%(one+1))+1)
        else:
            c = pow(2, n-i-1, one-1)
            print(f((Xm-c)%(one-1))+1)
else:
    for i in range(n):
        print(1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = str(input())
X = 0
one = 0
for i in range(n):
    X+=int(x[i])*2**(n-i-1)
    if x[i]=="1":
        one+=1


if one>0:
    l = [0, 1]
    for i in range(2,n):
        if i%2==0:
            l.append(1)
        else:
            l.append(l[i%bin(i).count("1")]+1)

    for i in range(n):
        if x[i]=="0":
            print(l[(X+2**(n-i-1))%(one+1)]+1)
        else:
            print(l[(X-2**(n-i-1))%(one-1)]+1)
else:
    for i in range(n):
        if i==n-1:
            print(2)
        else:
            print(1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = str(input())
X = 0
one = 0
for i in range(n):
    X+=int(x[i])*2**(n-i-1)
    if x[i]=="1":
        one+=1

u = X % one

l = [0, 1]
for i in range(2,n):
    if i%2==0:
        l.append(1)
    else:
        l.append(l[i%bin(i).count("1")]+1)

for i in range(n):
    if x[i]=="0":
        print(l[(X+2**(n-i-1))%(one+1)]+1)
    else:
        print(l[(X-2**(n-i-1))%(one-1)]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = str(input())
X = 0
one = 0
for i in range(n):
    X+=int(x[i])*2**(n-i-1)
    if x[i]=="1":
        one+=1

l = [0, 1]
for i in range(2,n):
    if i%2==0:
        l.append(1)
    else:
        c=1
        tem = i
        while tem>1:
            tem//=2
            if tem%2==1:c+=1
        l.append(l[i%c]+1)
for i in range(n):
    if x[i]=="1":
        on=one-1
    else:
        on=one+1
    t=X^(2**(n-i-1))
    print(l[t%on]+1)