Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
import copy
  
N = int(input())  
A = np.zeros(N)

for i in range(N):
    A[i] = int(input())

B = copy.deepcopy(A)

for i in range(N):
    B = np.delete(A, i)
    print(int(np.max(B)))
    B = copy.deepcopy(A)

### FIXED CODE ###

import numpy as np
import copy
  
N = int(input())  
A = np.zeros(N)

for i in range(N):
    A[i] = int(input())

ans = int(np.max(A))
K = np.where(A == ans)[0]
k = np.where(A == ans)[0][0]

if K.size > 1:
    for i in range(N):
        print(ans)
        
else:
    for i in range(N):
        if i == k:
            B = np.delete(A, i)
            print(int(np.max(B)))
    
        else:
            print(ans)
### BUGGY CODE ###

N = int(input())
record = [0] * 1000000

b = 1
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(b,N+1):
            sum = i**2 + j**2 + k**2 + i*j + i*k +j*k
            if sum >= N: break
            if i==j==k: record[sum] += 1
            else: record[sum] += 3
        b += 1

for num in record[1:N+1]:
    print(num)

### FIXED CODE ###


n = int(input())

ans = [0 for _ in range(n+1)]
x = 1
y = 1
z = 1

while True:
    f = x * x + y * y + z * z + x * y + y * z + z * x
    if f > n:
        if z > 1:
            y += 1
            z = 1
        elif y > 1:
            x += 1
            y = 1
        else:
            break
    else:
        ans[f] += 1
        z += 1

for i in range(1, n+1):
    print(ans[i])
### BUGGY CODE ###

from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
As = sorted(map(int, input().split()))

def check(t):
    "if the number of the pairs (i, j) that satisfies Ai * Aj <= t is < K, return True"
    count = 0
    for i, A in enumerate(As):
        if A > 0:
            index = bisect_right(As, t//A, lo = i+1) - (i+1)
        elif A < 0:
            index = N - bisect_left(As, -((-t)//A), lo = i+1)
        else:
            if t < 0:
                index = 0
            else:
                index = N - i - 1
        count += index
    return (count < K)
        


l = - (10 ** 18 + 10)
r = 10 ** 18 + 10
while r - l > 1:
    mid = (l + r) // 2
    if check(mid):
        l = mid
    else:
        r = mid

print(r)

### FIXED CODE ###

from bisect import bisect_left, bisect_right

N, K = map(int, input().split())
As = sorted(map(int, input().split()))
        
l = - (10 ** 18 + 10)
r = 10 ** 18 + 10
while True:
    mid = (l + r) // 2
    count = 0
    for i, A in enumerate(As):
        if A > 0:
            count += bisect_right(As, mid//A, lo = i+1) - (i+1)
        elif A < 0:
            count += N - bisect_left(As, -((-mid)//A), lo = i+1)
        else:
            if mid >= 0:
                count += N - i - 1
    if count < K:
        l = mid
    else:
        r = mid
    if r - l == 1:
        break

print(r)
### BUGGY CODE ###

k = int(input())
curr = 7
for i in range(k):
  if curr%k:
    curr *= 10
    curr += 7
  else:
    print(i+1)
    break
else:
  print(-1)

### FIXED CODE ###

k = int(input())
curr = 7
for i in range(k):
  if curr%k:
    curr *= 10
    curr += 7
    curr %= k
  else:
    print(i+1)
    break
else:
  print(-1)
### BUGGY CODE ###

from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n,k = readInts()
p = [0]+readInts()
c = [0]+readInts()

ans = -1*float("inf")
for i in range(1,n+1):
  j = p[i]
  t = [0]
  al = set()
  while j not in al:
    t.append(t[-1]+c[j])
    al.add(j)
    j = p[j]
  if t[-1]<=0:
    ans = max(ans, max(t[1:k+1]))
  else:
    kuri =(k-1)//(len(t)-1)
    s = kuri*t[-1]
    re = k -kuri*(len(t)-1)
    ans = max(ans, max(s,s+max(t[:re+1])))

print(ans)


### FIXED CODE ###

from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
p = [0]+readInts()
c = [0]+readInts()

ans = -1*float("inf")
for i in range(1,n+1):
	j = p[i]
	t = [0]
	al = set()
	while j not in al:
		t.append(t[-1]+c[j])
		al.add(j)
		j = p[j]
	if t[-1]<=0:
		ans = max(ans, max(t[1:k+1]))
	else:
		kuri =(k-1)//(len(t)-1)
		s = kuri*t[-1]
		re = k -kuri*(len(t)-1)
		ans = max(ans, max(s,s+max(t[:re+1])))

print(ans)
### BUGGY CODE ###

import collections
S=input()[::-1]
l=len(S)
T=0
A=[0]*2019
A[0]=1
for i in range(l):
    T+=int(S[i])*(10**i)
    T%=2019
    A[T]+=1
ans=0
for cnt in A:
    ans+=cnt*(cnt-1)//2
print(ans)















### FIXED CODE ###

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
### BUGGY CODE ###

from collections import deque


def resolve():
    H, W = map(int, input().split())
    A, white = [], []
    for i in range(H):
        A.append(list(input()))
        if '.' in A[i]:
            for j in range(W):
                if A[i][j] == '.':
                    white.append([i, j])

    dy = [0, 1, 0, -1]
    dx = [1, 0, -1, 0]
    cnt = 0

    # 各白マスから黒マスまでの最短距離を探索し，その最大値を出力
    for sy, sx in white:
        dis = [[float('inf')] * W for _ in range(H)]
        dis[sy][sx] = 0
        q = deque([(sy, sx)])
        update = False
        while q:
            y, x = q.popleft()
            for i in range(4):
                ny = y + dy[i]
                nx = x + dx[i]
                if (1
                        and 0 <= ny < H
                        and 0 <= nx < W
                        and dis[ny][nx] == float('inf')):
                    dis[ny][nx] = dis[y][x] + 1
                    q.append((ny, nx))
                    if A[ny][nx] == '#':
                        cnt = max(dis[ny][nx], cnt)
                        update = True
            if update:
                break
    print(cnt)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

from collections import deque


def resolve():
    H, W = map(int, input().split())
    A, q = [], deque([])
    for i in range(H):
        A.append(list(input()))
        if '#' in A[i]:
            for j in range(W):
                if A[i][j] == '#':
                    q.append((i, j))

    dy = [0, 1, 0, -1]
    dx = [1, 0, -1, 0]
    cnt = -1

    # 1回目で各黒マスを拡張して，2回目以降は拡張した黒マスから拡張してく
    nq = deque([])
    while q:
        y, x = q.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < H and 0 <= nx < W and A[ny][nx] == '.':
                nq.append((ny, nx))
                A[ny][nx] = '#'
        if q == deque([]):
            q = nq
            nq = deque([])
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

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

import bisect

N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    l, r = map(int, input().split())
    print(S[(l - 1):r].count("AC"))


### FIXED CODE ###

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

N, Q = map(int, input().split())
S = input()

S = S.replace("AC", "-+")
Sl = [0]
Sr = [0]
l = 0
r = 0
for i in range(N):
    if S[i] == "-":
        l += 1
    if S[i] == "+":
        r += 1
    Sl.append(l)
    Sr.append(r)

for _ in range(Q):
    l, r = map(int, input().split())
    print(Sr[r] - Sl[l - 1])
### BUGGY CODE ###

N = int(input())
S = input()        

dic = {"":1}
ans = 0

for c in S:
    dic_tmp = dic.copy()
    for k in dic_tmp:
        if not(c in k):    
            ans += dic_tmp[k]   
            ans %= 10**9+7
            dic[k+c] = (dic.get(k+c,0)+dic_tmp[k])%(10**9+7)  
print(ans)      

### FIXED CODE ###

N = int(input())
S = input()        

tmp = []
for a in "abcdefghijklmnopqrstuvwxyz":      
    tmp.append(S.count(a)+1)
    
ans = 1 
for i in tmp:
    ans = ans * i % (10**9+7)
    
print(ans-1)
### BUGGY CODE ###


N = input()
vals = map(int, input().split())
count = 0
is_odd = False
while True:
    for val in vals:
        if val % 2 == 1:
            is_odd = True
    if is_odd:
        break
    count += 1
    vals = map(lambda x: x/2, vals)
print (count)

### FIXED CODE ###

N = int(input())
vals = list(map(int, input().split()))
count = 0
is_odd = False
while True:
    for i in range(0, N):
        if vals[i] % 2 == 1:
            is_odd = True
        vals[i] /= 2
    if is_odd:
        break
    count += 1
print (count)
### BUGGY CODE ###

n = int(input())
cnt = 0
sListSum = 0

sList = ["".join(sorted(list(input()))) for _ in range(n)]
sListSet = list(set(sList))
for i in sListSet:
    cnt = sList.count(i)
    sListSum += int(cnt * (cnt - 1) / 2)
print(sListSum)


### FIXED CODE ###

import sys
import collections
import bisect


def main():
    n = int(input())
    s = [''.join(sorted(list(input()))) for _ in range(n)]
    c = collections.Counter(s)
    cVals = c.values()
    cSum = 0
    for cVal in cVals:
        cSum += cVal * (cVal - 1) // 2
    print(cSum)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = input().split()
N = int(s[0])
K = int(s[1])
A = input().split()

last = 0
for i in range(N):
    if i >= K:
        m1 = 1
        for j in range(K):
            m1 *= int(A[i - j - 1])
        m2 = 1
        for j in range(K):
            m2 *= int(A[i - j - 0])
        print('Yes' if m1 < m2 else 'No')


### FIXED CODE ###

s = input().split()
N = int(s[0])
K = int(s[1])
A = input().split()

for i in range(K, N):
    m1 = int(A[i - K])
    m2 = int(A[i])
    print('Yes' if m1 < m2 else 'No')
### BUGGY CODE ###

n = int(input())
an = []
for _ in range(n):
  an.append(int(input()))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[-2::-1]:
  maxr.insert(0, max(maxr[0], a))

print(maxr[1])
for i in range(1, n-1):
  print(max(maxl[i-1], maxr[i+1]))
print(maxl[n-2])

### FIXED CODE ###

n = int(input())
an = []
for _ in range(n):
  an.append(int(input()))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[:-1][::-1]:
  maxr.append(max(maxr[-1], a))
maxr = maxr[::-1]

print(maxr[1])
for i in range(1, n-1):
  print(max(maxl[i-1], maxr[i+1]))
print(maxl[n-2])
### BUGGY CODE ###

N = int(input())
S = list(input())

delKeta = N-3
ans = []
for V3 in range(10):
    for i in range(N-2):
        if(V3==int(S[i])):
            p1=i
            for V2 in range(10):
                for j in range(p1+1,N-1):
                    if(V2==int(S[j])):
                        p2=j
                        for V1 in range(10):
                            for k in range(p2+1,N):
                                if(V1==int(S[k])):
                                    ans.append(S[k]+S[p2]+S[p1])
                                    break
                        break
            break
                



print(len(set(ans)))



### FIXED CODE ###

N = int(input())
S = list(map(int,input()))
count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)
### BUGGY CODE ###

from collections import deque

string = input()
x = deque()
for s in string:
    x.append(s)

B = int(input())
for i in range(B):
    cmd = input().split()
    if len(cmd) == 1 and cmd[0] == "1":
        x.reverse()
    else:
        _, n, c = cmd
        if n == "1":
            x.appendleft(c)
        else:
            x.append(c)
print("".join(list(x)))


### FIXED CODE ###

from collections import deque

string = input()
x = deque()
for s in string:
    x.append(s)

head_left = True
B = int(input())
for i in range(B):
    cmd = input().split()
    if len(cmd) == 1 and cmd[0] == "1":
        head_left = not head_left
    else:
        _, n, c = cmd
        if (n == "1" and head_left) or (n == "2" and not head_left):
            x.appendleft(c)
        else:
            x.append(c)

if head_left:
    print("".join(list(x)))
else:
    print("".join(reversed(list(x))))
### BUGGY CODE ###

A,B,Q=map(int,input().split())
s=[int(input()) for i in range(A)]
t=[int(input()) for i in range(B)]
for q in range(Q):
    X=int(input())
    x_t=[X-b for b in t]
    l1=min([abs(i) for i in x_t])
    if -l1 in x_t:
        l1=-l1
    x_s=[X-b for b in s]
    l2=min([abs(i) for i in x_s])
    if -l2 in x_s:
        l2=-l2
    print(min(abs(l1)+min([abs(X-l1-b) for b in s]),abs(l2)+min([abs(X-l2-b) for b in t])))



### FIXED CODE ###

import bisect
INF=10**18
A,B,Q=map(int,input().split())
s=[int(input()) for i in range(A)]
t=[int(input()) for i in range(B)]
s=[-INF]+s+[INF]
t=[-INF]+t+[INF]
for q in range(Q):
    X=int(input())
    t1=bisect.bisect_right(t,X)
    s1=bisect.bisect_right(s,X)
    res=INF
    for T in [t[t1],t[t1-1]]:
        for S in [s[s1],s[s1-1]]:
            ans1=abs(X-T)+abs(S-T)
            ans2=abs(X-S)+abs(S-T)
            res=min(res,ans1,ans2)
    print(res)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    x,y,z,k=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    A.sort(reverse=1)
    B.sort(reverse=1)
    C.sort(reverse=1)
    A=A[:k]
    B=B[:k]
    C=C[:k]
    S=[]
    from itertools import product
    for i,j,l in product(range(k),repeat=3):
        if(i>=x or j>=y or l>=z): continue
        S.append(A[i]+B[j]+C[l])
    S.sort(reverse=1)
    for i in range(k):
        print(S[i])
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    x,y,z,k=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    S=[]
    T=[]
    from itertools import product
    for a,b in product(A,B):
        S.append(a+b)
    S.sort(reverse=1)
    S=S[:k]
    for s,c in product(S,C):
        T.append(s+c)
    T.sort(reverse=1)
    for i in range(k):
        print(T[i])
resolve()
### BUGGY CODE ###

n, k = map(int, input().split())
data = [10 ** 9]
for i in range(n):
    a, b = map(int, input().split())
    temp = [a] * b
    data.extend(temp)

rev = sorted(data)
#rev = data.reverse() > 大きい順
ans = rev[k - 1]
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
'''
data = [10 ** 9]
for i in range(n):
    a, b = map(int, input().split())
    temp = [a] * b
    data.extend(temp)

rev = sorted(data)
#rev = data.reverse() > 大きい順
ans = rev[k - 1]
print(ans)

>最大で（１０*＊１０）サイズリストになる。

バケツソートが必要。
（出現回数を格納したリストから、答えを出す。）
'''

data = [0] * (10 ** 5 + 1)
for i in range(n):
    a, b = map(int, input().split())
    data[a] += b

count = 0
for i in range(1, 10 ** 5 + 1):
    count += data[i]
    if (count >= k):
        ans = i
        break

print(ans)
### BUGGY CODE ###

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

#dp配列
# dp=[[float('inf')]*(H+1) for _ in range(N+1)]
# for j in range(H+1):
#     dp[0][j] =0

# for i in range(N):
#     A_i,B_i = map(int,input().split())
#     for a in range(H+1):
#         if A_i<=a:
#             dp[i+1][a] = min(dp[i][a-A_i] + B_i , dp[i][a])
#         else:
#             dp[i+1][a] = dp[i][a]

# print(*dp,sep="\n")

# print(dp[N][H])
dp = [float('inf')]*(H+1)
dp[0] = 0

for i in range(N):
    A_i,B_i = map(int,input().split())
    for j in range(H+1):
        nj = min(j+A_i,H)
        dp[nj] = min(dp[nj],dp[j] + B_i)
# print(*dp,sep="\n")
print(dp[H])

### FIXED CODE ###

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

#dp配列
# dp=[[float('inf')]*(H+1) for _ in range(N+1)]
# for j in range(H+1):
#     dp[0][j] =0

# for i in range(N):
#     A_i,B_i = map(int,input().split())
#     for a in range(H+1):
#         if A_i<=a:
#             dp[i+1][a] = min(dp[i][a-A_i] + B_i , dp[i][a])
#         else:
#             dp[i+1][a] = dp[i][a]

# print(*dp,sep="\n")

# print(dp[N][H])
dp = [float('inf')]*(H+1)
dp[0] = 0

for i in range(N):
    A_i,B_i = map(int,input().split())
    for j in range(H+1):
        nj = min(j+A_i,H)
        dp[nj] = min(dp[nj],dp[j] + B_i)
# print(*dp,sep="\n")
print(dp[H])
### BUGGY CODE ###

from collections import deque
h,w = list(map(int,input().split()))
s = [[x for x in input()] for _ in range(h)]

def find_w():
  for i in range(h):
    for j in range(w):
      if s[i][j] == '.':
        return True

def find_b():
  b = deque([])
  for i in range(h):
    for j in range(w):
      if s[i][j] == '#':
        b.append([i,j])
  return b

dh = [1,0,-1,0]
dw = [0,1,0,-1]

def rev():
  que = find_b()
  for b in que:
    for i in range(4):
      nh = b[0] + dh[i]
      nw = b[1] + dw[i]
      if nh >=0 and nh < h and nw >=0 and nw < w:
        s[nh][nw] = '#'

cnt = 0
while  find_w():
  rev()
  cnt += 1

print(cnt)

### FIXED CODE ###

from collections import deque

h,w = list(map(int,input().split()))
m = [[x for x in input()] for _ in range(h)]
next_que = deque([])
for i in range(h):
  for j in range(w):
    if m[i][j] == '#':
      next_que.append([i,j])


dh = [1,0,-1,0]
dw = [0,1,0,-1]

def bfs(next_que):
  cnt = -1
  while next_que:
    cnt += 1
    que = list(next_que)
    next_que = deque([])
    for cur in que:
      #cur = que.popleft()
      for i in range(4):
        nh = cur[0] + dh[i]
        nw = cur[1] + dw[i]
        
        if nh >= 0 and nh < h and nw >= 0 and nw < w and m[nh][nw] == '.':
          m[nh][nw] = '#'
          next_que.append([nh,nw])
  
  return cnt



cnt = bfs(next_que) 

print(cnt)
### BUGGY CODE ###

# https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035


def div_cost(left, right):
    # 区間[left, right]が一匹にまとまっているとき、それを分解するために必要な最小コスト
    if bl_calculated[left][right]:
        return memo[left][right]
    bl_calculated[left][right] = True
    if left == right:
        memo[left][right] = 0
        return memo[left][right]
    divided_to_alone_cost = INF
    # divided_to_alone_cost: 区間[left, right]を分解してできた2つの区間それぞれをaの各要素まで分解し切るのに必要なコスト
    for mid in range(left, right):
        divided_to_alone_cost = min(divided_to_alone_cost, div_cost(left, mid) + div_cost(mid + 1, right))
    memo[left][right] = divided_to_alone_cost + (c_sum[right] - c_sum[left - 1])
    # (c_sum[right] - c_sum[left - 1]): 区間[left, right]を分解するのにかかるコスト
    return memo[left][right]


INF = float('inf')

N = int(input())
a = list(map(int, input().split()))

c_sum = [0]
for aa in a:
    c_sum.append(c_sum[-1] + aa)
# 累積和c_sum

memo = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
# memo[left][right] = (区間[left, right]に相当するスライムが一匹にまとまっているとき、それを分解するために必要な最小コスト)

bl_calculated = [[False for _ in range(N + 1)] for _ in range(N + 1)]
# memo[left][right]に最小コストが代入済かどうかのBoolean

print(div_cost(1, N))


### FIXED CODE ###

# https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035


def div_cost(left, right):
    # 区間[left, right]が一匹にまとまっているとき、それを分解するために必要な最小コスト
    if bl_calculated[left][right]:
        return memo[left][right]
    bl_calculated[left][right] = True
    if left == right:
        memo[left][right] = 0
        return memo[left][right]
    divided_to_alone_cost = INF
    # divided_to_alone_cost: 区間[left, right]を分解してできた2つの区間それぞれをaの各要素まで分解し切るのに必要なコスト
    for mid in range(left, right):
        divided_to_alone_cost = min(divided_to_alone_cost, div_cost(left, mid) + div_cost(mid + 1, right))
    memo[left][right] = divided_to_alone_cost + (c_sum[right] - c_sum[left - 1])
    # (c_sum[right] - c_sum[left - 1]): 区間[left, right]を分解するのにかかるコスト
    return memo[left][right]


INF = float('inf')

N = int(input())
a = list(map(int, input().split()))

c_sum = [0]
for aa in a:
    c_sum.append(c_sum[-1] + aa)
# 累積和c_sum

memo = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
# memo[left][right] = (区間[left, right]に相当するスライムが一匹にまとまっているとき、それを分解するために必要な最小コスト)

bl_calculated = [[False for _ in range(N + 1)] for _ in range(N + 1)]
# memo[left][right]に最小コストが代入済かどうかのBoolean

print(div_cost(1, N))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
N = int(input())

memo = {0:0,1:1}
def f(price):
    if price in memo:
        return memo[price]
    n = price % 10
    res = min(f(price//10 + 1) + 10-n, f(price//10) + n)
    memo[price] = res
    return res

print(f(N))


### FIXED CODE ###

S = input()
N = list(map(int,S))
L = len(N)

dp = [[0]*2 for i in [0]*(L+1)]
dp[0][1] = 1

for i in range(L):
    n = N[i]
    dp[i+1][0] = min(dp[i][0] + n, dp[i][1] + 10-n)
    if n == 9:
        dp[i+1][1] = dp[i][1]
    else:
        dp[i+1][1] = min(dp[i][0] + n + 1, dp[i][1] + 10 - (n+1))

print(dp[L][0])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]


INF = float("inf")
MOD = 10**9 + 7


def bit_sum(n):
    wa = 0
    while n > 0:
        wa += n & 1
        n >>= 1
    return wa

def bit(n, k):
    return (n >> k) & 1

def main():
    N = INT()
    X = input()
    wa = X.count("1")
    x = 0
    for c in X:
        x <<= 1
        if c == "1":
            x |= 1
    X = x

    for i in range(N):
        count = 0
        x = X ^ (1 << N-i-1)
        while x != 0:
            count += 1
            x %= bit_sum(x)
        print(count)
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]


import time


INF = float("inf")
MOD = 10**9 + 7


def bit_sum(n):
    wa = 0
    while n > 0:
        wa += n & 1
        n >>= 1
    return wa

def bit(n, k):
    return (n >> k) & 1

def main():
    start = time.time()
    N = INT()
    X = input()
    origX = X
    wa = X.count("1")
    x = 0
    px = 0
    nx = 0
    start = time.time()
    for c in X:
        x <<= 1
        px <<= 1
        nx <<= 1
        if c == "1":
            x |= 1
            px |= 1
            nx |= 1
        px %= (wa+1)
        if wa != 1:
            nx %= (wa-1)
        else:
            nx %= wa
    if wa == 1:
        nx = None
    # print(time.time()-start)
    # start = time.time()
    X = x
    table = [None]*(N+1)
    table[0] = 0
    table[1] = 1
    for i in range(1, N+1):
        table[i] = table[i % bit_sum(i)] + 1
    # print(time.time()-start)
    # start = time.time()

    for i, c in enumerate(origX):
        count = 0
        if c == "1":
            if wa == 1:
                print(0)
                continue
            x = (nx-pow(2, N-i-1, wa-1)) % (wa-1)
            print(table[x]+1)
        else:
            x = (px+pow(2, N-i-1, wa+1)) % (wa+1)
            print(table[x]+1)
    # print(time.time()-start)
    return


if __name__ == '__main__':
    main()