Harryxun/stf_run huggingface dataset:
class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA, self), BridgeEdge(nodeB, self)]
        nodeA.addEdge(self.edges[1])
        nodeB.addEdge(self.edges[0])

class BridgeEdge:
    def __init__(self, node, edge):
        self.edge = edge
        self.node = node
    def another(self):
        return self.edge.edges[1 if self.edge.edges[0] == self else 0]

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
        self.parent = None
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)
    def __repr__(self):
        return str((self.id, None if self.parent is None else self.parent.node.id))

N, M = map(int, input().split())

nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(N)):
    bridges.append(Bridge(nodes[A], nodes[B]))


### FIXED CODE ###

class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA, self), BridgeEdge(nodeB, self)]
        nodeA.addEdge(self.edges[1])
        nodeB.addEdge(self.edges[0])
        self.dir = True
        self.vec = None
    def __repr__(self):
        return str((self.vec, self.dir))

class BridgeEdge:
    def __init__(self, node, edge):
        self.edge = edge
        self.node = node
    def another(self):
        return self.edge.edges[1 if self.edge.edges[0] == self else 0]

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
        self.parent = None
        self.judge = True
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)
    def __repr__(self):
        return str((self.id, None if self.parent is None else self.parent.node.id, self.judge))

N, M = map(int, input().split())

nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(M)):
    bridges.append(Bridge(nodes[A], nodes[B]))

s = [(0, nodes[1])]
idx = 0
while len(s) > 0:
    level, cur = s.pop()

    nxtlevel = level + 1
    for nxt in cur.bridges:
        if nxt.edge.vec is None:
            cur.judge ^= True
            nxt.edge.vec = (cur.id, nxt.node.id)
            if nxt.node.parent is None:
                nxt.node.parent = nxt.another()
                s.append((nxtlevel, nxt.node))

    if len(s) > 0:
        nl = s[-1][0]
    else:
        nl = 1
    while level >= nl:
        if not cur.judge:
            cur.judge ^= True
            cur.parent.node.judge ^= True
            cur.parent.edge.dir ^= True
        level -= 1
        cur = cur.parent.node
  
if all(node.judge for node in nodes[1:]):
    for br in bridges:
        if br.dir:
            print("{} {}".format(br.vec[0], br.vec[1]))
        else:
            print("{} {}".format(br.vec[1], br.vec[0]))
else:
    print("-1")
a = str(input())
oomoji = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
komoji = ["abcdefghijklmnopqrstuvwxyz"]

if a.isupper():
    print("A")
else:
    print("a"a)


### FIXED CODE ###

a = str(input())
oomoji = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
komoji = ["abcdefghijklmnopqrstuvwxyz"]

if a.isupper():
    print("A")
else:
    print("a")
A,B,C,D,E = [int(input()) for _ in range(5)]
a = A % 10
b = B % 10
c = C % 10
d = D % 10
e = E % 10
if a == b == c == d == e == 0:
  print(A+B+C+D+E)
else:
  print(A-a+B-b+C-c+D-d+E-e-max(10-a,10-b,10-c,10-d,10-e)

### FIXED CODE ###

A,B,C,D,E = [int(input()) for _ in range(5)]
a = (10-A) % 10
b = (10-B) % 10
c = (10-C) % 10
d = (10-D) % 10
e = (10-E) % 10
if a == b == c == d == e == 0:
  print(A+B+C+D+E)
else:
  print(A+B+C+D+E+a+b+c+d+e-max(a,b,c,d,e))
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    if N == 3:
        print('Yes')
        print(3)
        print(2, 1, 2)
        print(2, 3, 1)4
        print(2, 2, 3)
    else:
        print('No')
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    K = (1 + (8 * N + 1) ** 0.5) / 2
    if not K.is_integer():
        print('No')
        return
    K = int(K)

    ans = [[] for _ in range(K)]
    num = 1
    for k in range(K):
        for l in range(k + 1, K):
            ans[k].append(num)
            ans[l].append(num)
            num += 1
    print('Yes')
    print(K)
    for row in ans:
        print(K - 1, *row)


if __name__ == '__main__':
    main()
N,Q = map(int,input().split())
aLst = [[int(x) for x in input().split()] for _ in range(N-1)]
pLst = [[int(x) for x in input().split()] for _ in range(Q)]

tmpLst = [[] for _ in range(N+1)]
for i, j in aLst:
    tmpLst[i].append(j)
    tmpLst[j].append(i)

ansLst = [0] * N
for i in range(Q):
    ansLst[pLst[i][0] - 1] += pLst[i][1]

def dfs(v, p, ansLst):
    for i in tmpLst[v]:
        if i == p:
            continue
        ansLst[i - 1] += ansLst[v - 1]
        dfs(i, v, ansLst)


dfs(1, 0, ansLst)

ans = ' '.join(map(str, ansLst))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x
    
q = [(1,0)]
while q:
    x,parent = q.pop()
    value[x] += value[parent]
    for y in graph[x]:
        if y == parent:
            continue
        q.append((y,x))

answer = ' '.join(map(str,value[1:]))
print(answer)
a, b, c, k = map(int, input().split())
if k < a:
  out = k
elif k > a:
  out = a
if k > (a + b):
  out += (k - a - b) * (-1)
print(out)

### FIXED CODE ###

a, b, c, k = map(int, input().split())
out = 0
if k < a:
  out = k
elif k >= a:
  out = a
if k > (a + b):
  out += (k - a - b) * (-1)
print(out)
n = int(input())
A = list(map(int, input().split()))

Cnt = [0 for i in range(10**6 + 7)]
for i in A:
    if Cnt[i] != 0:
        Cnt[i] = 2
        continue
    for j in range(i, 10**6 + 8, i):
        Cnt[j] += 1

ans = 0
for i in A:
    if Cnt[i] == 1:
        ans += 1
    else:
        pass

print(ans)

### FIXED CODE ###

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

Cnt = [0 for i in range(10**6 + 8)]
for i in A:
    if Cnt[i] != 0:
        Cnt[i] = 2
        continue
    else:
        pass
    for j in range(i, 10**6 + 8, i):
        Cnt[j] += 1

ans = 0
for i in A:
    if Cnt[i] == 1:
        ans += 1
    else:
        pass

print(ans)
num = int(input())
data = input().rstrip().split(' ')
count = 0
if data.count('P') > 0 or data.count('W') > 0 or data.count('G') > 0 or data.count('Y') > 0:
  count++
print(count)

### FIXED CODE ###

N = int(input())
s = input().split()
if "Y" in s:
    print("Four")
else:
    print("Three")
from itertools import combinations

int_x = int(input())

answer = int_x

for i in range(1, int_x + 1):
    c = combinations(range(1, int_x + 1), i)
    for w_c in c:
        if sum(w_c) == int_x:
            answer = min(answer, max(w_c))
print(answer)


### FIXED CODE ###

x = int(input())

w = 0
for i in range(1, x + 1):
    w += i
    if w >= x:
        print(i)
        exit(0)
# -*- coding: utf-8 -*-

import sys
import os
import math

m = int(input())
n = int(input())

# Manage people who entered earlier than me in a list
G = [[] for i in range(m)]

for i in range(n):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    G[y].append(x)

printed = [False] * m

while printed.count(False) > 1:
    # Delete node with degree 0
    for i, node in enumerate(G):
        if not printed[i] and len(node) == 0:
            print(i+1)
            printed[i] = True

            # Erase his existence
            for node in G:
                if i in node:
                    node.remove(i)

# cat
i = printed.index(False)
print(i+1)

### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
import os
import math

m = int(input())
n = int(input())

# Manage people who entered earlier than me in a list
G = [[] for i in range(m)]

for i in range(n):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    G[y].append(x)

printed = [False] * m

while printed.count(False) > 1:

    # Delete node with degree 0
    for i, node in enumerate(G):
        if not printed[i] and len(node) == 0:
            print(i+1)
            printed[i] = True

            # Erase his existence
            for node in G:
                if i in node:
                    node.remove(i)

# cat
if False in printed:
    i = printed.index(False)
    print(i+1)
n, m = map(int, input().split())

x = []
y = []
z = []
for i in range(n):
  _x, _y, _z = map(int, input().split())
  x.append(_x)
  y.append(_y)
  z.append(_z)

pm = [1, -1]

ans = 0
for i_x in pm:
  for i_y in pm:
    for i_z in pm:
      values = []
      for i in range(n):
        values.append(x * i_x + y * i_y + z * i_z)
      s = 0
      for value in sorted(values, reverse=True)[:m]:
        s += value
      ans = max(ans, s)
      
print(ans)

### FIXED CODE ###

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

x = []
y = []
z = []
for i in range(n):
  _x, _y, _z = map(int, input().split())
  x.append(_x)
  y.append(_y)
  z.append(_z)

pm = [1, -1]

ans = 0
for i_x in pm:
  for i_y in pm:
    for i_z in pm:
      values = []
      for i in range(n):
        values.append(x[i] * i_x + y[i] * i_y + z[i] * i_z)
      s = 0
      for value in sorted(values, reverse=True)[:m]:
        s += value
      ans = max(ans, s)
      
print(ans)
num_room, num_path = map(int, input().split())

room_paths_dict = {}

start_room_to_paths = set()
result = {}

def solve():
    for i in range(num_path):
        a_room_num, b_room_num = map(int, input().split())
        if a_room_num == 1:
            start_room_to_paths.add(b_room_num)
            continue
        elif b_room_num == 1:
            start_room_to_paths.add(a_room_num)
            continue

        result[a_room_num] = 0
        result[b_room_num] = 0

        if not room_paths_dict.get(a_room_num):
            room_paths_dict[a_room_num] = set()
        if not room_paths_dict.get(b_room_num):
            room_paths_dict[b_room_num] = set()

        room_paths_dict[a_room_num].add(b_room_num)
        room_paths_dict[b_room_num].add(a_room_num)
    if len(start_room_to_paths) == 0:
        print('No')
        return

    def search(room_num):
        targets = []
        for next_room in room_paths_dict[room_num]:
            if result[next_room] == 0:
                result[next_room] = room_num
                targets.append(room_num)

        for t in targets:
            search(t)

    for start_room_to_path in start_room_to_paths:
        result[start_room_to_path] = 1
        search(start_room_to_path)

    if 0 in result.values():
        print('No')
    else:
        print('Yes')
        for key in sorted(result.keys()):
            print(result[key])

solve()



### FIXED CODE ###


from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))
while True:
  H, W = map(int, raw_input().spslit())
  if H = 0 and 'W' = 0:
    break
  print '#'*W
  for l in range(0, H-2):
    print '#' + '.'*(W-2) + '#'
  print '#' * W
  print 

### FIXED CODE ###

while True:
  H, W = map(int, raw_input().split())
  if H == 0 and W == 0:
    break
  print '#'*W
  for l in range(0, H-2):
    print '#' + (W-2)*'.' + '#'
  print '#' * W
  print ''
a,b=input.split()
if ord(a) > ord(b):print('>')
elif a == b:print('=')
else:print('<')

### FIXED CODE ###

a,b=input().split()
if ord(a) > ord(b):print('>')
elif a == b:print('=')
else:print('<')
N=int(input())
ab=[list(map(int, input().split())) for i in range(N-1)]
link=[[] for i in range(N+1)]
for i in range(0, N-1):
  link[ab[i][0]].append([ab[i][1], i])
  link[ab[i][1]].append([ab[i][0], i])
  
out=[0]*(N-1)
def f(num, prenum=0, prec=0):
  postc=1
  for postnum, linknum in link[num]:
    if postnum==prenum:
      continue
    if postc==prec:
      postc+=1
      
    out[linknum]=postc
    f(postnum, num, postc)
    postc+=1
    
f(1)

print(max(out))
for i in range(N-1):
  print(out[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N=int(input())
ab=[list(map(int, input().split())) for i in range(N-1)]
link=[[] for i in range(N+1)]
for i in range(0, N-1):
  link[ab[i][0]].append([ab[i][1], i])
  link[ab[i][1]].append([ab[i][0], i])
  
out=[0]*(N-1)
def f(num, prenum=0, prec=0):
  postc=1
  for postnum, linknum in link[num]:
    if postnum==prenum:
      continue
    if postc==prec:
      postc+=1
      
    out[linknum]=postc
    f(postnum, num, postc)
    postc+=1
    
f(1)

print(max(out))
for i in range(N-1):
  print(out[i])
a,b,k = map(int,input().split())
if a>=k:
  print(str(a-k) + str(b))
elif a+b>=k:
  print(str(0) + str(a+b-k)
elsem
        print(0 0)

### FIXED CODE ###

a,b,k = map(int,input().split())
if a>=k:
  print(str(a-k) + " " + str(b))
elif a+b>=k:
  print("0 " + str(a+b-k))
else:
  print("0 0")
#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    Num = [0] * N
    for a in A:
        Num[a-1] += 1

    l1 = l2 = 0
    for i in range(N-1, -1, -1):
        if l1 == 0:
            if Num[i] >= 2:
                l1 = i+1
                if Num[i] >= 4:
                    l2 = i+1
                    break
        else:
            if Num[i] >= 2:
                l2 = i+1
                break

    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()


### FIXED CODE ###

#
# abc071 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    A.sort(reverse=True)
    l1 = l2 = 0
    for i in range(1, N):
        if l1 == 0:
            if A[i] == A[i-1]:
                l1 = A[i-1]
        else:
            if i < N-1 and A[i+1] == A[i]:
                l2 = A[i]
                break

    print(l1*l2)


if __name__ == "__main__":
    # unittest.main()
    resolve()
d, t, s  = map(int, input().split())
if d =< t * s :
    print("Yes")
else :
    print("No")

### FIXED CODE ###

d, t, s  = map(int, input().split())
if d <= t * s :
    print("Yes")
else :
    print("No")
N, K = map(int,input().split())
S = input()
S = list(S)
S[K] = S[K].lower()
print(S)

### FIXED CODE ###

N, K = map(int,input().split())
S = input()
S = list(S)
S[K-1] = S[K-1].lower()
print(''.join(S))
if a >= 3200:
  print(s)
else:
  print("red")

### FIXED CODE ###

a = int(input())
s = input()
print(s if a >= 3200 else 'red')
def walking():
    x, k, d = map(int, input().split())
    r = 0
    if x > 0 and x > k * d:
        return x - k * d
    elif x < 0 and x < -k * d:
        return x + k * d
    elif x > 0 and x < k * d:
        r = x//d
        if (k - r)%2 == 0:
            return x - r * d
        else:
            return x - (r + 1 ) * d
    elif x < 0 and x < -k * d:
        r = x//d
        if (k + r)%2 == 0:
            return x - r * d
        else:
            return x - (r + 1 ) * d        
    
loc = walking()
print(abs(loc))

### FIXED CODE ###


def walking():
    x, k, d = map(int, input().split())
    x = abs(x)
    r = 0
    if x > k * d:
        return x - k * d
    else:
        r = x//d
        if (k - r)%2 == 0:
            return x - r * d
        else:
            return abs(x - (r + 1 ) * d)
    
loc = walking()
print(loc)
K = int(input())
A,B = map(int,input().split())

for i in range(A, min(A+K,B)):
  if math.floor(B / K == 0):
    print("OK")
else
  print("NG")
               

### FIXED CODE ###

K=int(input())
A,B=map(int,input().split())
 
for i in range(A, B+1):
  if(i>=K and i%K==0):
    print("OK")
    break
else:
  print("NG")
A, B= [int(i) for i in input().split()]

if A>=10orB>=10:
  print(-1)
else:
  print(A*B)
 

### FIXED CODE ###

A, B= [int(i) for i in input().split()]

if A>=10 or B>=10:
  print(-1)
else:
  print(A*B)
K=int(input())
S=input()

n=len(S)

if n<=K:
    print(S)
else:
    for i in range(7):
        print(S[i],end="")
    print("...")

### FIXED CODE ###

K=int(input())
S=input()

n=len(S)

if n<=K:
    print(S)
else:
    for i in range(K):
        print(S[i],end="")
    print("...")
x = int(input())
while True:
	xs = [n for i in range(x) if x % n == 0]
    if len(xs) > 2:
      break
	x += 1
print(x)


### FIXED CODE ###

x = int(input())
while True:
  xs = [i for i in range(1, x + 1) if x % i == 0]
  if len(xs) == 2:
    break
  x += 1
print(x)
import numpy as np

N, M = map(int, input().split())
routes = np.array([list(map(int, input().split())) for _ in range(M)], 'i')
#print(routes)

# i駅まで到達したときの最小コスト（最終電車がjで示される）
dp = [{} for _ in range(N + 1)]
dp[1][0] = 0

for i in range(2, N + 1):
    for (f, t, m) in routes:
        if t != i:
            continue

        if m in dp[f]:
            dp[t][m] = dp[f][m]
        else:
            values = []
            for k, v in dp[f].items():
                if k != m: values.append(v)
            if len(values) > 0:
                dp[t][m] = min(values) + 1

if len(dp[N].values()) > 0:
    print(min(dp[N].values()))
else:
    print(-1)

### FIXED CODE ###

import numpy as np

def many_fomulas(digits):
    mat = np.zeros((len(digits), len(digits)), 'i')

    for i, _ in enumerate(digits):
        if i >= 0:
            mat[i, :i] = 2 ** (i - 1)
        mat[i, i] = 2 ** i

    total = 0
    for i, _ in enumerate(digits):
        for j, v in enumerate(digits):
            total += 10 ** (len(digits) - i - 1) * int(mat[i, j]) * v

    print(total)

#many_fomulas([1, 2, 5])
#many_fomulas([9, 9, 9, 9, 9, 9, 9, 9, 9, 9])
many_fomulas([int(d) for d in input()])
import sys

def cheaperprice(item):
    rawprice=rawprices[item]
    if item not in menus:
        return rawprice
    else:
        indegrients=menus[item]
        combinedprice=0
        for i in indegrients:
            combinedprice+=cheaperprice(i)
        return min(combinedprice,rawprice)


n=0 #how many numbers of lists
flag=0
rawprices={}
menus={}

for line in sys.stdin:
    line=line.strip()
    if n==0:
        if flag==0 and line=='0':
            break
        elif flag!=2:
            n=int(line)
        else:
            print cheaperprice(line)
            rawprices={}
            menus={}
        flag=(flag+1)%3
    else:
        line=line.split(' ')
        if flag==1: #rawprices
            rawprices[line[0]]=int(line[1])
        elif flag==2:
            menus[line[0]]=line[2:]
        n-=1

### FIXED CODE ###

while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        pricelist=[]
        recipedict={}
        costdict={}
        for i in range(n):
            [ii,p]=raw_input().split()
            pricelist.append([ii,int(p)])
            costdict[ii]=1000000000000
        pricelist.sort(key=lambda x:x[1])
        m=int(raw_input())
        for i in range(m):
            rec=raw_input().split()
            o=rec[0]
            k=int(rec[1])
            recipedict[o]=rec[2:]
        query=raw_input()
        while(1):
            cheapest=pricelist.pop(0)
            #if able to make
            if cheapest[0] in recipedict:
                priceifmade=0
                for reqitem in recipedict[cheapest[0]]:
                    priceifmade=priceifmade+costdict[reqitem]
                if priceifmade<cheapest[1]:
                    costdict[cheapest[0]]=priceifmade
                else:
                    costdict[cheapest[0]]=cheapest[1]
            else:
                costdict[cheapest[0]]=cheapest[1]
            for item in recipedict:
                priceifmade=0
                for reqitem in recipedict[item]:
                    priceifmade=priceifmade+costdict[reqitem]
                if priceifmade<costdict[item]:
                    costdict[item]=priceifmade
            if cheapest[0]==query:
                print costdict[cheapest[0]]
                break
n, m = list(map(int, input().split())
print(max(n - sum(list(map(int, input().split()), 0))

### FIXED CODE ###

n, m = list(map(int, input().split()))
print(max(n - sum(list(map(int, input().split()))), -1))
a,b = map(int, input().split())
if a < 6:
    print(0)
else if a < 14:
    print(int(b / 2))
else:
    print(b)

### FIXED CODE ###

a,b = map(int, input().split())
if a >= 13:
    print(b)
    exit()
elif a >= 6:
    print(int(b / 2))
    exit()
else:
    print(0)
N = int(input())
X = input()
def popcount(k):
    return bin(k).count('1')

K = int(X, 2)
one = popcount(K)
K_MOD   = K % one
K_MOD_M = K % (one-1)
K_MOD_P = K % (one+1)
#print('k_mod_m=', K_MOD_M)
#print('k_mod_p=', K_MOD_P)
T = 2**(N-1)
for i in range(N):
    if X[i] == '1':
        pop = one - 1
        k = K_MOD_M - T
    else:
        pop = one + 1
        k = K_MOD_P + T

    if pop == 0:
        print(0)
    else:
        ans = 1
        #print('  ', k, pop, ans)
        k %= pop
        pop = popcount(k)
        while k > 0:
            k %= pop
            pop = popcount(k)
            ans += 1
            #print('  ', k, pop, ans)
        print(ans)
        T //= 2

### FIXED CODE ###

N = int(input())
X = input()
memo = [-1] * (N+1)
memo[0] = 0

def popcount(k):
    return bin(k).count('1')

def calc(k):
    pop = popcount(k)
    #print('  ', k, pop)
    key = k
    if memo[key] < 0:
        k %= pop
        if k == 0:
            memo[key] = 1
        else:
            memo[key] = calc(k) + 1
    return memo[key]

K = int(X, 2)
one = popcount(K)
if one == 0:
    K_MOD = K
elif one == 1:
    K_MOD   = 0
    K_MOD_M = K
else:
    K_MOD   = K % one
    K_MOD_M = K % (one-1)
K_MOD_P = K % (one+1)

T_M = [1]*(N+1)
T_P = [1]*(N+1)
for i in range(1,N+1):
    if one > 1:
        T_M[i] = (T_M[i-1]*2) % (one-1)
    T_P[i] = (T_P[i-1]*2) % (one+1)

for i in range(N):
    if X[i] == '1':
        pop = one - 1
        k = K_MOD_M - T_M[N-i-1]
    else:
        pop = one + 1
        k = K_MOD_P + T_P[N-i-1]

    if pop == 0:
        print(0)
    else:
        k %= pop
        print(calc(k)+1)