Harryxun/stf_run huggingface dataset:
# cook your dish here
import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    #print(x)

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(abs(x[len(x)-k]))
    elif x[0] > 0:
        print(x[k-1])    
    else:
        ass = 10 ** 10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            
            else:
                if i - k + 1 >= 0:
                    ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        if r-k >= 0:
            ans = abs(x[r-k])
        ass = min(ass,ans)
        print(ass)

### FIXED CODE ###

# cook your dish here
import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    #print(x)

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(abs(x[len(x)-k]))
    elif x[0] > 0:
        print(x[k-1])    
    else:
        ass = 10 ** 10
        ans = 10**10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            
            else:
                if i - k + 1 >= 0:
                    ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        if r-k >= 0:
            ans = abs(x[r-k])
        ass = min(ass,ans)
        print(ass)
n,m = map(int,input().split())
listA=[] #appendのために宣言が必要
i=0
a=[]
b=[]
c=[]
while True:
    try:
        if(i%2==0):
          i=i+1
          a1,b1=(list(map(int,input().split())))
          a.append(a1)
          b.append(b1)
          #listA.append(list(map(int,input().split())))
        else:
          i=i+1
          c.append(list(map(int,input().split())))	
    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(listA)
#print(a)
#print(b)
#print(*c)
#偶数はa,b
get_=[]
money=[]
kei=0
for i in range(m):
  get_.extend(c[i])
  kei=kei+a[i]
  if(len(list(set(get_)))==n):
    money.append(kei)
  
print(min(money))

### FIXED CODE ###

import math
a=int(input())
if(a%2==0):
  print(0.5000)
else:
  print(math.floor(a/2+1)/a)
a,b = map(float,raw_input().split(' '))
print((a * b) / 3.305785)

### FIXED CODE ###

a,b = map(float,input().split(' '))
print((a * b) / 3.305785)
N, M = map(int, input().split())
X = list(map(int, input().split()))

if N>M:
  print(0)
else:
  X.sort()
  Y=[]
  for i in range(len(X)-1):
    Y.append([i,X[i+1]-X[i]])
  Y.sort(reverse=True, key=lambda x:x[1])
  ans=0
  old=0
  for i in range(N-1):
    tmp=X[old:Y[i][0]+1]
    ans+=max(tmp)-min(tmp)
    old=Y[i][0]+1
  else:
    tmp=X[old:]
    ans+=max(tmp)-min(tmp)
  print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
X = list(set(map(int, input().split())))
M = len(X)

if N>=M:
  print(0)
else:
  X.sort()
  Y=[]
  for i in range(len(X)-1):
    Y.append([i,X[i+1]-X[i]])
  Y.sort(reverse=True, key=lambda x:x[1])
  Y=Y[:N-1]
  Y.sort()
  ans=0
  old=0
  for i in range(N-1):
    tmp=X[old:Y[i][0]+1]
    ans+=max(tmp)-min(tmp)
    old=Y[i][0]+1
  else:
    if old<len(X):
      tmp=X[old:]
      ans+=max(tmp)-min(tmp)
  print(ans)
print(111 if (int(input())//111)==0 else 111*(int(input())//111+1) )

### FIXED CODE ###

n=int(input())
print(n if n%111==0 else 111*(n//111+1) )
S_input = str(input())
add_str_tuple = ("dream", "dreamer", "erase", "eraser")

def recur_add(T):
    if T == S_input:
        print("YES")
        exit()
    else:
        if S_input.startswith(T):
            for word in add_str_tuple:
                recur_add(T+word)
        else:
            return

recur_add("")
print("NO")

### FIXED CODE ###

import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$", input()) else "NO")
inp = input().split()
l = list(map(int,inp))
l = l.sort()
print(l[0],l[1],l[2])

### FIXED CODE ###

inp = list(map(int,input().split()))
inp.sort()
print(inp[0],inp[1],inp[2])
import sys
import heapq
import bisect
from collections import deque
stdin=sys.stdin

ns=lambda:input().rstrip()
ni=lambda:int(input().rstrip())
nm=lambda:map(int,input().split())
nl=lambda:list(map(int,input().split()))

s=list(ns())
t=list(ns())
d={'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,'i':8,'j':9,'k':10,'l':11,'m':12,'n':13,'o':14,'p':15,'q':16,'r':17,'s':18,'t':19,'u':20,'v':21,'w':22,'x':23,'y':24,'z':25}

order=[[] for _ in range(26)]

for i in range(len(s)):
  order[d[s[i]]].append(i)
  
now=0
ans=0
rep=0
for i in range(len(t)):
  inds=d[t[i]]
  if(order[inds]==0):
    print(-1)
    sys.exit(0)
  index=bisect.bisect_left(order[inds],now)
  if(index==len(order[inds])):
    now=order[inds][0]
    rep+=1
  else:
    now=order[inds][index]


print(rep*len(s)+now+1)

### FIXED CODE ###

import sys
import heapq
import bisect
from collections import deque
stdin=sys.stdin

ns=lambda:input().rstrip()
ni=lambda:int(input().rstrip())
nm=lambda:map(int,input().split())
nl=lambda:list(map(int,input().split()))

s=list(ns())
t=list(ns())
d={'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,'i':8,'j':9,'k':10,'l':11,'m':12,'n':13,'o':14,'p':15,'q':16,'r':17,'s':18,'t':19,'u':20,'v':21,'w':22,'x':23,'y':24,'z':25}

order=[[] for _ in range(26)]

for i in range(len(s)):
  order[d[s[i]]].append(i)
  
now=0
ans=0
rep=0
for i in range(len(t)):
  inds=d[t[i]]
  if(order[inds]==[]):
    print(-1)
    sys.exit(0)
  index=bisect.bisect_left(order[inds],now)
  if(index==len(order[inds])):
    now=order[inds][0]+1
    rep+=1
  else:
    now=order[inds][index]+1


print(rep*len(s)+now)
n=input()
if n%2==0:
  print(n/2)
if not n%2==0:
  print(n/2+1)

### FIXED CODE ###

n=int(input())
if n%2==0:
  print(int(n/2))
if not n%2==0:
  print(int(n/2+1))
def isIncremental(a, b, c): 
    """ 
    a: int
    b: int
    c: int

    returns "Yes" if a < b < c, otherwise "No"

    >>> isIncremental(1, 3, 8)
    'Yes'
    >>> isIncremental(3, 8, 1)
    'No'
    >>> isIncremental(1, 1, 1)
    'No'
    """
    if a >= b:
        return "No"
    elif b >= c:
        return "No"
    else:
        return "Yes"

if __name__ == '__main__':
    ival = input().split(' ')
    print(isIncremental(int(ival[0]), int(ival[1]), int(ival[2]))

### FIXED CODE ###

def isIncremental(a, b, c):
    """
    a: int
    b: int
    c: int

    returns "Yes" if a < b < c, otherwise "No"

    >>> isIncremental(1, 3, 8)
    'Yes'
    >>> isIncremental(3, 8, 1)
    'No'
    >>> isIncremental(1, 1, 1)
    'No'
    """
    if a >= b:
        return "No"
    elif b >= c:
        return "No"
    else:
        return "Yes"

if __name__ == '__main__':
#   import doctest
#   doctest.testmod()

    ival = input().split(' ')
    print(isIncremental(int(ival[0]), int(ival[1]), int(ival[2])))
a,b=map(float,input().split())
b=b.replace(".","")
print(int(a*b/100))

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b.replace(".",""))
print(a*b//100)
import math
import sys
import os
from operator import mul
import numpy as np

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


N = I()
A1 = LI()
A2 = LI()

A1n = np.zeros(N,dtype='int')
A1n = np.array(A1)
A2n = np.zeros(N,dtype='int')
A2n = np.array(A2)

A1_cum = np.zeros(N,dtype='int')
A2_cum = np.zeros(N,dtype='int')
A1_cum = A1n[1:].cumsum()
A2_cum = A2n[:-1].cumsum()
# print(A1_cum)
# print(A2_cum)

# 下に降りる最初の位置
start = N - 2
for i in range(N-1):
    if A1_cum[N-2] - A1_cum[i] < A2_cum[N-2] - A2_cum[i]:
        start = i
        break

ans = A1n[0] + A2n[-1] + A1_cum[start] + (A2_cum[N-2] - A2_cum[start])

print(ans)

### FIXED CODE ###

import math
import sys
import os
from operator import mul
import numpy as np

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


N = I()
A1 = LI()
A2 = LI()

if N == 1:
    print(A1[0]+A2[0])
    exit()

ans = 0
for i in range(N):
    ans = max(ans, sum(A1[:i])+sum(A2[i-1:]))


# A1n = np.zeros(N,dtype='int')
# A1n = np.array(A1)
# A2n = np.zeros(N,dtype='int')
# A2n = np.array(A2)

# A1_cum = np.zeros(N,dtype='int')
# A2_cum = np.zeros(N,dtype='int')
# A1_cum[1:] = A1n[1:].cumsum()
# A2_cum[1:] = A2n[:-1].cumsum()
# # print(A1_cum)
# # print(A2_cum)

# # 下に降りる最初の位置
# start = N - 2
# for i in range(N-1):
#     if A1_cum[N-1] - A1_cum[i] < A2_cum[N-1] - A2_cum[i]:
#         start = i
#         break

# ans = A1n[0] + A2n[-1] + A1_cum[start] + (A2_cum[-1] - A2_cum[start])

# # ans = sum(A1) + sum(A2) - min(A1[-1],A2[0]+A2[1])

print(ans)
import sys
import math
k = int(sys.stdin.readline())
a = 1
t = 0
while a <= k:
  b = 1
  while b <= k:
    c = 1
    while c <= k:
      t += math.gcd(a,b,c)
      c += 1
    b += 1
  a += 1
print(t)


### FIXED CODE ###

import sys
import math
k = int(sys.stdin.readline())
a = 1
t = 0
while a <= k:
  b = 1
  while b <= k:
    c = 1
    while c <= k:
      t += math.gcd(math.gcd(a,b), c)
      c += 1
    b += 1
  a += 1
print(t)
s = int(input())
w = input()
S = ''
for i in range(0,len(w),s):
  S = S+w[i]

### FIXED CODE ###

w = input()
s = int(input())
S = ''
for i in range(0,len(w),s):
  S = S+w[i]
print(S)
N, Q = map(int, input().split())
S = input()
t=[0]*(N+1)
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])
 

### FIXED CODE ###

b = input()
if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
else:
    print('C')
a=int(input())
a>=30:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a=int(input())
if a>=30:
  print('Yes')
else:
  print('No')
N, M, K = map(int, input().split())

flag = False
for n in range(M + 1):
    for m in range(N + 1):
        if n * N + m * (M - n * 2) == K:
            flag = True

if flag:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

S = input()
if S[:4] == 'YAKI':
    print('Yes')
else:
    print('No')
result=[]
N = int(input())
W = list(map(int,input().split()))
for i in range(1:N+1):
  a = W[:i]
  b = W[i+1:N]
  c = sum(a)
  d = sum(b)
  e = abs(c-d)
  result.append(e)
 
print(min(result))


### FIXED CODE ###

N = int(input())
W = list(map(int, input().split()))
i = 0
W_sum = sum(W)
ans_l = []
tmp_l = 0
for i in range(N):
    tmp_l += W[i]
    if((W_sum-tmp_l) - tmp_l < 0):
        ans_l.append(-((W_sum-tmp_l) - tmp_l))
    else:
        ans_l.append((W_sum-tmp_l) - tmp_l)
print(min(ans_l))
n=int(input())
s=input()
s_list=list(s)
c=0
for a in range(n-1):
  if s_list[a]s_list[a+1} ==  #.:
                     c += 1
                     s_list[a+1] =#
print(c)

### FIXED CODE ###

n = int(input())
s = input()
k = 0
si = s.count('.')
m = si
for i in s:
  if i == '#':
    k += 1
  else:
    si -= 1
  m = min(m,k+si)
print(m)
N = int(input())
adj = [[] for _ in range(N)]
for i in range(N - 1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    adj[x].append(y)
    adj[y].append(x)


def dfs(v, p):
    nim = 0
    for u in adj[v]:
        if u == p:
            continue
        nim ^= dfs(u, v)
    if p == -1:
        return nim
    nim += 1
    return nim

res = dfs(0, -1)

if res:
    print("Alice")
else:
    print("Bob")

### FIXED CODE ###

import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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


def dfs(v, p):
    nim = 0
    for u in adj[v]:
        if u == p:
            continue
        nim ^= dfs(u, v)
    if p == -1:
        return nim
    nim += 1
    return nim

res = dfs(0, -1)

if res:
    print("Alice")
else:
    print("Bob")
s=input()
if s+%2==0:
  print(s/2)
  else:
    print((s+1)/2)

### FIXED CODE ###

s=int(input())
if s%2==0:
  print(int(s/2))
else:
  print(int((s+1)/2))
Vx = int(input())

if x < 1200:
  print("ABC")
elif x < 2800:
  print("ARC")
else:
  print("AGC")


### FIXED CODE ###

x = int(input())

if x < 1200:
  print("ABC")
elif x < 2800:
  print("ARC")
else:
  print("AGC")
import copy

H, W, K = map(int, input().split())
tiles = [list(input().split()) for _ in range(H)]
count  = 0

for num in range(2**(H+W)):
  copied_tiles = copy.deepcopy(tiles)
  for i in range(H+W):
    if num>>i&1:
      if i < H:
        for j in range(W):
          copied_tiles[i][j] = 'R'
      else:
        for j in range(H):
          copied_tiles[j][i-H] = 'R'
  black_c = 0
  for i in range(H):
    for j in range(W):
      if copied_tiles[i][j] == '#':
        black_c += 1
  if black_c == K:
    count += 1
print(count)

### FIXED CODE ###

import copy
 
H, W, K = map(int, input().split())
tiles = [list(input()) for _ in range(H)]
count  = 0
 
for num in range(2**(H+W)):
  copied_tiles = copy.deepcopy(tiles)
  for i in range(H+W):
    if num>>i&1:
      if i < H:
        for j in range(W):
          copied_tiles[i][j] = 'R'
      else:
        for j in range(H):
          copied_tiles[j][i-H] = 'R'
  black_c = 0
  for i in range(H):
    for j in range(W):
      if copied_tiles[i][j] == '#':
        black_c += 1
  if black_c == K:
    count += 1
print(count)
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
def myAnswer(N:int,M:int,S:str,T:str) -> int:
   L = lcm(N,M)
   setS = [1]
   for n in range(1,N):
      setS.append(n * L//N + 1)
   setT = [1]
   for m in range(1,M):
      setT.append(m * L//M + 1)
   # print(setS,setT,L)
   for n,i in enumerate(setS):
      for m,j in enumerate(setT):
         if(i == j and S[n] != T[m]):
            # print(i,j,S[n],T[m],n,m)
            return -1
   else:
      return L

def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   S = input()
   T = input()
   print(myAnswer(N,M,S,T))
if __name__ == '__main__':
   main()

### FIXED CODE ###

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
def myAnswer(N:int,M:int,S:str,T:str) -> int:
   a = N//fractions.gcd(N,M)
   b =M // fractions.gcd(N,M)
   # print(a,b)
   for i in range(fractions.gcd(N,M)):
      # print(S[a * i],T[b * i])
      if(S [a * i] != T[b * i]):
         return -1
   else:
      return lcm(N,M)

def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   S = input()
   T = input()
   print(myAnswer(N,M,S,T))
if __name__ == '__main__':
   main()
def dfs(i, j, m):
    '''
    m[i][j]??¨????????£??????????????°????????????????????????
    '''
    m[i][j] = 0
    for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        ni = i + di
        nj = j + dj
        if ni in range(12) and nj in range(12) and m[ni][nj] == 1:
            dfs(ni, nj, m)                

while True:
    m = []
    for i in range(12):
        m.append(list(map(int, list(input()))))
    
    count = 0
    for i in range(12):
        for j in range(12):
            if m[i][j] == 1:
                count += 1
                dfs(i, j, m)
    
    print(count)
    input()

### FIXED CODE ###

def dfs(i, j, m):
    '''
    m[i][j]??¨????????£??????????????°????????????????????????
    '''
    m[i][j] = 0
    for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        ni = i + di
        nj = j + dj
        if ni in range(12) and nj in range(12) and m[ni][nj] == 1:
            dfs(ni, nj, m)                

while True:
    try:
        m = [list(map(int, list(input()))) for _ in range(12)]

        count = 0
        for i in range(12):
            for j in range(12):
                if m[i][j] == 1:
                    count += 1
                    dfs(i, j, m)
        
        print(count)
        input()
    except:
        break
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 ''

### 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 ''
L = int(input())

#頂点の数nを決める
n = 0
while 2**n < L:
    n += 1

rest = L - 2**(n-1)
next_num = 2**(n-1)

m = n
while rest > 0:
    if rest >= 2**(m-2):
        side_lst.append([m-1, n, next_num])
        next_num += 2**(m-2)
        rest -= 2**(m-2)
    m -= 1
    
print(n, len(side_lst)+(n-1)*2)
for i in side_lst:
    print(i[0], i[1], i[2])
    
for i in range(1, n):
    print(i, i+1, i)
    print(i, i+1, 2**(i-1))

### FIXED CODE ###

L = int(input())

n = 0
while 2**n <= L:
    n += 1

side_lst = []
    
rest = L - 2**(n-1)
next_num = 2**(n-1)

m = n
while rest > 0:
    if rest >= 2**(m-2):
        side_lst.append([m-1, n, next_num])
        next_num += 2**(m-2)
        rest -= 2**(m-2)
    m -= 1
    
print(n, len(side_lst)+(n-1)*2)
for i in side_lst:
    print(i[0], i[1], i[2])
    
for i in range(1, n):
    print(i, i+1, 0)
    print(i, i+1, 2**(i-1))
def isPrime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False
    i = 3
    xx = int(pow(x, 0.5))
    while i <= xx:
        if x % i == 0:
            return False
        i += 2
    return True

n = int(input())
rx = int(pow(n, 0.5))
l = rx+1
ps = []
for i in range(n):
    if isPrime(i):
        ps.append(i)
ans = []
i = 0
nn = n
while n != 1:
    if n % ps[i] == 0:
        n //= ps[i]
        ans.append(ps[i])
    else:
        i += 1
print(str(nn)+":", ' '.join(map(str, ans)))

### FIXED CODE ###

n = int(input())
print("{}:".format(n), end='')
x = int(pow(n, 0.5))+1
for i in range(2, x):
    while n % i == 0:
        print(" {}".format(i), end='')
        n //= i
print(' {}'.format(n) if n != 1 else '')
import re

s = input()

regex = re.compile('[ACGT]+')

l = 0

for i in range(len(s)):
    r1 = regex.match(s[:i])
    r2 = regex.match(s[i:])
    if r1:
        l = max(l, len(r1[0]))
    if r2:
        l = max(l, len(r2[0]))

print(l)


### FIXED CODE ###

s = input()

max_count = 0
count = 0

for i in s:
    if i not in ['A', 'C', 'G', 'T']:
        count = 0
        continue
    count += 1
    max_count = max(max_count, count)

print(max_count)
import math
time = 5 * 10**15

num = list(input())
k = int(input())

chk = 0
count = 0
while chk == 0:
    if num[0] == '1':
        num.pop(0)
        count += 1
    else:
        chk = 1

if k <= count:
    print(1)
else:
    print(num[0])


### FIXED CODE ###

import math
time = 5 * 10**15

num = list(input())
k = int(input())

chk = 0
count = 0
while chk == 0:
    if num[0] == '1':
        num.pop(0)
        count += 1
        if len(num)==0:
            break
    else:
        chk = 1

if k <= count:
    print(1)
else:
    print(num[0])
n=int(input())
l=[int(i) for i in input().split()]
s=sum(l)
d={}
for i in range(n):
  if(l[i] in d):
    d[i]+=1
  else:
    d[i]=1
q=int(input())
for w in range(q):
  b,c=(int(i) for i in input().split())
  if(b in d):
    s-=((d[b]*b)+(d[b]*c))
    d[c]=d[b]
    d[b]=0
  print(s)

### FIXED CODE ###

n=int(input())
l=[int(i) for i in input().split()]
s=sum(l)
d={}
for i in range(n):
  if(l[i] in d):
    d[l[i]]+=1
  else:
    d[l[i]]=1
q=int(input())
for w in range(q):
  b,c=(int(i) for i in input().split())
  if(b in d):
    s-=(d[b]*b)
    s+=(d[b]*c)
    if(c in d):
        d[c]+=d[b]
    else:
        d[c]=d[b]
    d[b]=0
  print(s)
n=int(input())
s=[int(c) for c in input()]

pc=sum(s)

resm=[0]*n
resp=[0]*n

jm=1
jp=1

totm=0
totp=0
for i in range(n):
    resm[n-i-1]=jm%(pc-1)
    resp[n-i-1]=jp%(pc+1)

    jm=(2*jm)%(pc-1)
    jp=(2*jp)%(pc+1)

    totm+=resm[n-i-1]*s[n-i-1]
    totm%=pc-1

    totp+=resp[n-i-1]*s[n-i-1]
    totp%=pc+1

def popc(x):
    return sum([int(c) for c in format(x,'b')])

for i in range(n):
    if s[i]==1:
        pcc=pc-1
        cres=(totm+pc-1-resm[i])%(pc-1)
    else:
        pcc=pc+1
        cres=(totp+resp[i])%(pc+1)
    
    if cres==0:
        print(1)
        continue

    cnt=1
    while cres>0:
        cres%=popc(cres)
        cnt+=1
    
    print(cnt)


### FIXED CODE ###

n=int(input())
s=[int(c) for c in input()]

pc=sum(s)

resm=[0]*n
resp=[0]*n

jm=1
jp=1

totm=0
totp=0
for i in range(n):
    if pc-1>0:
        resm[n-i-1]=jm%(pc-1)
        jm=(2*jm)%(pc-1)
        totm+=resm[n-i-1]*s[n-i-1]
        totm%=pc-1
    
    resp[n-i-1]=jp%(pc+1)
    jp=(2*jp)%(pc+1)
    totp+=resp[n-i-1]*s[n-i-1]
    totp%=pc+1

def popc(x):
    return sum([int(c) for c in format(x,'b')])

for i in range(n):
    if s[i]==1:
        pcc=pc-1
        if pcc==0:
            print(0)
            continue
        cres=(totm+pc-1-resm[i])%(pc-1)
    else:
        pcc=pc+1
        cres=(totp+resp[i])%(pc+1)
    
    if cres==0:
        print(1)
        continue

    cnt=1
    while cres>0:
        cres%=popc(cres)
        cnt+=1
    
    print(cnt)
import sys


def input():
    return sys.stdin.readline().rstrip()


def dfs(a, m):
    if max(a) == 0:
        return 0
    if m == 0:
        return sum(a)
    a[a.index(max(a))] //= 2
    return dfs(a, m-1)


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

    print(dfs(A, M))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import heapq


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] *= -1
    heapq.heapify(A)

    for i in range(M):
        maxa = -1 * heapq.heappop(A)
        if maxa == 0:
            print("0")
            exit()
        heapq.heappush(A,  maxa // 2 * (-1))
    print(sum(A) * (-1))


if __name__ == '__main__':
    main()
a,b=input(),split(" ")

print(a+""+b)


### FIXED CODE ###

a,b = input().split()
a = int(a)
b = int(b)
S = a*b
C = 2 * (a+b)

print(str(S) + " " + str(C))
#
from collections import Counter as cn

d = int(input())
l = []
for k in range(d):
  r = input()
   
  l.append(Counter(r))

oi = l[0]

for g in range(1,d):
    oi = oi & l[g]
    
    
print("".join(sorted(oi.elements())))



### FIXED CODE ###

from collections import Counter
 
n = int(input())
l = []
 
for i in range(n):
    s = input()
    l.append(Counter(s))
    
cnt = l[0]
for i in range(1,n):
        cnt = cnt & l[i]
        
print("".join(sorted(cnt.elements())))