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

from itertools import product

def sol():
    N = int(input())
    XYP = [tuple(map(int, input().split())) for _ in range(N)]
    XYP.sort(key=lambda xyp: xyp[2], reverse=True)

    X = [x for x, _, _ in XYP]
    Y = [y for _, y, _ in XYP]
    INF = 10**18

    def calcCost(AP, A):
        ret = [[INF] * N for _ in range(1 << N)]
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i, (a, p) in enumerate(AP):
                cost = abs(a)
                for z in useA:
                    cost = min(cost, abs(a - z))
                ret[state][i] = cost * p
        return ret

    costX = calcCost([(x, p) for x, _, p in XYP], X)
    costY = calcCost([(y, p) for _, y, p in XYP], Y)

    ans = [INF] * (N + 1)
    for state in product((0, 1, 2), repeat=N):
        stateX = 0
        stateY = 0
        M = N
        for s in state:
            stateX <<= 1
            stateY <<= 1
            if s == 0: M -= 1
            if s == 1: stateX |= 1
            if s == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
            if cost >= ans[M]:
                break
        else:
            ans[M] = cost

    print(*ans, sep='\n')

sol()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()
### BUGGY CODE ###

import sys
import heapq

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

for _ in range(m):
    b, c = map(int, input().split())
    [heapq.heappushpop(A, c) for i in [0]*b]

print(sum(A))

### FIXED CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))
### BUGGY CODE ###

import math
N = int(input())
for n in range(1, N + 1):
    ans = 0
    x = math.ceil(n ** (1/2))
    for i in range(1, x):
        for j in range(1, x):
            for k in range(1, x):
                if i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i == n:
                    ans += 1
    print(ans)

### FIXED CODE ###

N = int(input())
A = [0] * (N + 1)
for i in range(1, 102):
    for j in range(1, 102):
        for k in range(1, 102):
            t = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + i * k
            if t <= N:
                A[t] += 1
for n in range(1, N + 1):
    print(A[n])
### BUGGY CODE ###

def f(n):
    ans = 0
    for x in range(1, n):
        x2 = x**2
        if x2 > n-2:
            break
        for y in range(1, n):
            y2 = y**2
            if x2 + y2 + x*y > n-1:
                break
            for z in range(1, n):
                judge = x2 + y2 + z**2 + x*y + y*z + z*x
                if judge == n:
                    ans += 1
                elif judge > n:
                    break
    return ans


def main():
    N = int(input())
    for i in range(1, N+1):
        print(f(i))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    ans = [0]*(N+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                a = x*x + y*y + z*z + x*y + y*z + z*x
                if a <= N:
                    ans[a] += 1
    for i in range(1, N+1):
        print(ans[i])


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

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

    uni = sorted(list(set(A)))
    dup = [x for x in set(A) if A.count(x) > 1]
    m = set()

    ans = 0

    for a in uni:
        if a in m: continue

        i = 0
        a_max = uni[len(uni)-1]

        while True:
            m.add(a * i)
            if a*i < a_max:
                i += 1
            else:
                break
        
        if a not in dup:
            ans += 1
 
    print(ans)
 
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    max_a = max(A)
    m = set()
    checked = set()
    duplicated = set()

    for a in A:
        if a in checked:
            duplicated.add(a)
            continue

        i = 2
        while a*i <= max_a:
            m.add(a*i)
            i += 1

        checked.add(a)

    ans = 0
    for a in A:
        if a in duplicated: continue

        if a not in m:
            ans += 1
    
    print(ans)
 
resolve()
### BUGGY CODE ###

import re

a, i = [int(n) for n in input().split()]
s = input()
k = 0
result = []

while k < i:
    ft, et = [int(n) for n in input().split()]
    result.append(len(re.findall("AC", s[ft - 1:et])))
    k += 1

for kekka in result:
    print(kekka)


### FIXED CODE ###

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
s = input()

count = [0]
for i in range(1, n):
    count.append(count[i-1])
    if(s[i-1:i+1] == "AC"):
        count[i] += 1

# print(count)

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

from collections import Counter
import queue

def bfs(d,s,N):
    dist = [None]*N
    q=queue.Queue()
    q.put(s)
    dist[i]=0
    while not q.empty():
        From = q.get()
        for To in d[From]:
            if dist[To-1] == None:
                q.put(To)
                dist[To-1] = dist[From-1]+1
    return dist


N, X, Y = map(int, input().split())
d = [[] for _ in range(N+1)]
d[X].append(Y)
d[Y].append(X)
for i in range(1,N):
    d[i].append(i+1)
    d[i+1].append(i)

ans=[0]*(N+1)

for i in range(N):
    s=i+1
    c=Counter(bfs(d,i+1,N))
    for i,m in c.items():
        ans[i]+=m

for i in range(1,N):
    print(ans[i]//2)

### FIXED CODE ###

from collections import Counter, deque


def bfs(d, s, N):
    dist = [-1]*N
    q = deque()
    q.append(s)
    dist[i] = 0
    while len(q) != 0:
        From = q.popleft()
        for To in d[From]:
            if dist[To-1] == -1:
                q.append(To)
                dist[To-1] = dist[From-1]+1
    return dist


N, X, Y = map(int, input().split())
d = [[] for _ in range(N+1)]
d[X].append(Y)
d[Y].append(X)
for i in range(1, N):
    d[i].append(i+1)
    d[i+1].append(i)

ans = [0]*(N+1)

for i in range(N):
    s = i+1
    c = Counter(bfs(d, i+1, N))
    for i, m in c.items():
        ans[i] += m

for i in range(1, N):
    print(ans[i]//2)
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))
count = 0
mod = 10**9+7
for i in range(n-1):
  for j in range(i+1,n):
    count = count + (l[i]^l[j])%mod
print(count%mod)
  


### FIXED CODE ###

def main():
    import sys 
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    c1 = [0]*60
    c0 = [0]*60
    mod = 10**9+7

    for i in l:
        for j in range(60):
            if (i >> j) & 1:
                c1[j] += 1
            else:
                c0[j] += 1

    ans = 0
    ni = 1
    for i in range(60):
        ans += (c1[i]*c0[i]*ni)%mod
        ans %= mod
        ni = ni*2%mod
    print(ans%mod)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import deque
n, m = map(int, input().split())
p = list(map(int, input().split()))
paths = {}
for _ in range(m):
    x, y = map(int, input().split())
    if not x in paths.keys():
        paths[x] = [y]
    else:
        paths[x].append(y)
    if not y in paths.keys():
        paths[y] = [x]
    else:
        paths[y].append(x)

connected = [None]*(n+1)
path_id = 1
for i in range(1, n+1):
    if connected[i] is None:
        connected[i] = path_id
    else:
        continue

    stack = deque(paths[i]) if i in paths.keys() else []
    while len(stack) > 0:
        j = stack.pop()
        connected[j] = path_id
        for k in paths[j]:
            if connected[k] is None:
                stack.append(k)
    path_id += 1
# print(connected)

ans = 0
for i in range(n):
    if connected[i+1] == connected[p[i]]:
        ans += 1
print(ans)


### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
p = list(map(int, input().split()))
paths = {}
for _ in range(m):
    x, y = map(int, input().split())
    if not x in paths.keys():
        paths[x] = [y]
    else:
        paths[x].append(y)
    if not y in paths.keys():
        paths[y] = [x]
    else:
        paths[y].append(x)

connected = [None]*(n+1)
path_id = 1
for i in range(1, n+1):
    if connected[i] is None:
        connected[i] = path_id
    else:
        continue

    if i in paths.keys():
        stack = deque(paths[i])
        cluster = set([i]+paths[i])
    else:
        stack = []
    while len(stack) > 0:
        j = stack.pop()
        connected[j] = path_id
        for k in paths[j]:
            if connected[k] is None and not k in cluster:
                stack.append(k)
                cluster.add(k)
    path_id += 1
# print(connected)

ans = 0
for i in range(n):
    if connected[i+1] == connected[p[i]]:
        ans += 1
print(ans)
### BUGGY CODE ###

def main():
    n,k=map(int,input().split())
    xy=[list(map(int,input().split())) for i in range(n)]
    x,y=[[xy[i][0],i] for i in range(n)],[[xy[i][1],i] for i in range(n)]
    x.sort()
    y.sort()
    ans=10**18*4
    for i1 in range(n):
        i1_sub=n-i1
        x_sub1=x[i1][0]
        for l1 in range(i1_sub,1,-1):
            x_sub2=x[i1+l1-1][0]
            for i2 in range(n):
                i2_sub=n-i2
                y_sub1=y[i2][0]
                for l2 in range(i2_sub,1,-1):
                    y_sub2=y[i2+l2-1][0]
                    z=[0]*n
                    for i in range(n):
                        if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                            z[i]=1
                    if sum(z)>=k:
                        ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                    else:
                        break
    print(ans)
main()


### FIXED CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort()
y.sort()
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,1,-1):
        for i2 in range(n):
            for l2 in range(n-i2,1,-1):
                x_sub1=x[i1][0]
                x_sub2=x[i1+l1-1][0]
                y_sub1=y[i2][0]
                y_sub2=y[i2+l2-1][0]
                z=[0]*n
                for i in range(n):
                    if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                        z[i]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)
### BUGGY CODE ###

from itertools import accumulate

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

A=[int(x) for x in input().split()]
dp=[[float('inf') for x in range(N)] for y in range(N)]

#dp[0]=min(A)を捕まえる最短時間を調べる。
m=A.index(min(A))
A=A[m:]+A[:m]

#dp[i][j]=A[j]のスライムをi回魔法を唱えて捕まえるための最小時間。
#dp[0][0]=A[0],dp[0][1]=A[1],dp[0][2]=A[2]...で初期化。
for i in range(N):
  dp[0][i]=A[i]

#dp[1][1]=min(A[1],dp[0][0]),dp[1][2]=min(A[2],dp[0][1])...
#dp[i][j]=min(A[i],dp[i-1][j-1])
#最終的には回数ごとのsum+k*xの最小値が答え。
for i in range(1,N):
  for j in range(N):
    dp[i][j]=min(A[j],dp[i-1][j-1])

dp = [list(accumulate(x)) for x in dp]

ans=float('inf')
for i in range(N):
  ans=min(ans,dp[i][N-1]+i*x)

print(ans)

### FIXED CODE ###

N,x=map(int,input().split())
A=[int(x) for x in input().split()]
dp=A[:]

#dp[i]:k回魔法を唱えた時にA[i]を手に入れる最小の時間。
#dp=Aで初期化。その後、１〜Nまでの各ステップでdp[i]はmin(dp[i],A[i-k])で順に更新されていく。
#各回におけるsum(dp)+k*xを算出して最小値が答え。

#ans初期値は魔法を唱えず、全てを入手した数字（sum(A))
ans=sum(A)
for k in range(1,N):
  for i in range(N):
    if dp[i]>A[i-k]:
      dp[i]=A[i-k]
  ans=min(ans,sum(dp)+x*k)

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

import sys
import fractions


def in_ctrl():
    _input = [_.rstrip() for _ in sys.stdin.readlines()]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    K = int(_input[0])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return K


def out_ctrl(s):
    print(s)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


if __name__ == "__main__":
    K = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    #cnt = 0
    ## 全部同じ数字(a=b=c)
    #for a in range(1,K+1):
    #    cnt += a
    ## 1つ同じ数字(a<b=c)
    #for a in range(1,K+1):
    #    for b in range(a+1,K+1):
    #        ans = fractions.gcd(a,b)
    #        cnt += 6*ans
    ## 全部違う数字(a<b<c)
    #for a in range(1,K+1):
    #    for b in range(a+1,K+1):
    #        for c in range(b+1,K+1):
    #            if a !=b and b!=c:
    #                ans = fractions.gcd(a,b)
    #                cnt += 6*fractions.gcd(ans, c)
    #            else:
    #                pass
    cnt = 0
    for a in range(1,K+1):
        cnt += a
        for b in range(a+1,K+1):
            ans = fractions.gcd(a,b)
            cnt += 6*ans
            for c in range(b+1,K+1):
                if a !=b and b!=c:
                    ans = fractions.gcd(a,b)
                    cnt += 6*fractions.gcd(ans, c)
                else:
                    pass    
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

### FIXED CODE ###

import sys
import fractions

def in_ctrl():
    _input = [_.rstrip() for _ in sys.stdin.readlines()]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    K = int(_input[0])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return K


def out_ctrl(s):
    print(s)


if __name__ == "__main__":
    K = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    dict_ = {}
    for a in range(1,K+1):
        cnt += a
        for b in range(a+1,K+1):
            if '{}_{}'.format(a,b) in dict_:
                ans = dict_['{}_{}'.format(a,b)]
            else:
                ans = fractions.gcd(a,b)
                dict_['{}_{}'.format(a,b)] = ans
            cnt += 6*ans
            for c in range(b+1,K+1):
                if '{}_{}'.format(ans,c) in dict_:
                    _ans = dict_['{}_{}'.format(ans,c)]
                else:
                    _ans = fractions.gcd(ans, c)
                    dict_['{}_{}'.format(ans,c)] = _ans
                cnt += 6*_ans
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)
### BUGGY CODE ###



n, k = [int(x) for x in input().split()]

hs = [int(y) for y in input().split()]

dp = [0] * n
inf = 1 << 30

for i in range(1, n):
	smallest = inf
	for j in range(max(0,i-k), i):
		smallest = min(smallest, dp[j] + abs(hs[i] - hs[j]))
	dp[i] = smallest
	
print(dp[n-1])



### FIXED CODE ###

n, k = [int(x) for x in input().split()]

hs = [int(x) for x in input().split()]

dp = [0] * n

for i in range(1, min(k,n)):
	dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[:i], hs[:i])])

if k < n:
	for i in range(k, n):
		dp[i] = min([dpj + abs(hs[i] - hj) for dpj, hj in zip(dp[i-k:i], hs[i-k:i])])

print(dp[-1])
### BUGGY CODE ###

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

x = []
for i in range(n):
    if i%2 == 1:
        x.append(l[i])
    else:
        x.insert(0,l[i])

if n%2 == 0:
    x.reverse()
    print(*x)
else:
    print(*x)

### FIXED CODE ###

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

odd, even = [], []

for i in range(n):
    if (i + 1) % 2 ==1:
        odd += [l[i]]
    else:
        even += [l[i]]

even.reverse()
e_o = even + odd

if n % 2 == 1:
    e_o.reverse()
    print(*e_o)
else:
    print(*e_o)
### BUGGY CODE ###

import numpy as np
from scipy.sparse.csgraph import shortest_path
n = int(input())
Sides = [[0 for i in range(n)] for j in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    Sides[u][v] = w
    Sides[v][u] = w

Path_from_0 = shortest_path(np.array(Sides))
for i in range(n):
    print(int(Path_from_0[0][i]) % 2)


### FIXED CODE ###

import numpy as np
from scipy.sparse.csgraph import shortest_path
import heapq
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append([w, v])
    edge[v].append([w, u])

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

Path_from_0 = dijkstra_heap(0)
for i in range(n):
    print(Path_from_0[i] % 2)
### BUGGY CODE ###

from itertools import product

n = int(input())
s = input()

nums = [str(i) for i in range(10)]

ans = 0
for pat in product(nums, repeat=3):
    i = 0
    for e in s:
        if e == pat[i]:
            i += 1

        if i == 3:
            break

    if i == 3:
        ans += 1

print(ans)


### FIXED CODE ###

from itertools import product

n = int(input())
s = input()
nums = [str(i) for i in range(10)]

cnt = 0
for num in product(nums, repeat=3):
    i = 0
    for e in s:
        if num[i] == e:
            i += 1
        if i == 3:
            break

    if i == 3:
        cnt += 1

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

import math
n = int(input())

temp = 0

while(n > 0):
    temp += n % 10
    n = n // 10

if(temp % 9 == 0):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import math
n = int(input())

if(n % 9 == 0):
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()
    n = ni()

    cnt = 0
    for i in range(n):
        d = list(sys.stdin.readline().split())
        if int(d[0]) == 1:
            cnt = (cnt + 1) % 2
        else:
            if not cnt:
                if int(d[1]) == 1:
                    s = d[2] + s
                else:
                    s = s + d[2]
            else:
                if int(d[1]) == 1:
                    s = s + d[2]
                else:
                    s = d[2] + s

    if cnt:
        s = s[::-1]

    print(s)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()
    n = ni()

    front = ""
    rear = ""

    cnt = 0
    for i in range(n):
        d = list(sys.stdin.readline().split())
        if int(d[0]) == 1:
            cnt = (cnt + 1) % 2
        else:
            if not cnt:
                if int(d[1]) == 1:
                    front = d[2] + front
                else:
                    rear = rear + d[2]
            else:
                if int(d[1]) == 1:
                    rear = rear + d[2]
                else:
                    front = d[2] + front

    if cnt:
        s = s[::-1]
        front = front[::-1]
        rear = rear[::-1]
        ans = rear + s + front
    else:
        ans = front + s + rear

    print(ans)


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

N = int(input())
X = input()


def popcount(n: int):
    bin_n = bin(n)
    return str(bin_n).count('1')


for i in range(N):
    count = 0
    if X[i] == '1':
        tmp = int(X)
        tmp -= 10 ** (N - i - 1)
    else:
        tmp = int(X)
        tmp += 10 ** (N - i - 1)

    tmp = int(str(tmp), 2)
    origin = tmp

    while True:
        if tmp == 0:
            print(count)
            break
        elif tmp == 1:
            print(count + 1)
            break
        elif tmp == 2:
            print(count + 1)
            break
        else:
            count += 1
            tmp = tmp % popcount(tmp)


### FIXED CODE ###

N = int(input())
S = input()
X = int(S, 2)
pcx = S.count('1')
# ビット反転で1が0になる場合
pc1 = X % (pcx - 1) if pcx > 1 else 0
# ビット反転で0が1になる場合
pc2 = X % (pcx + 1)


def f(j):
    cnt = 0
    while j:
        j %= bin(j).count('1')
        cnt += 1
    return cnt


for i, y in enumerate(S):
    k = N - i - 1
    if y == "0":  # modを分配するときは、分配してからもう１回modを作用させれば良い
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
### BUGGY CODE ###

n = int(input())
x = [int(i) for i in input().split()]
xs = sorted(x)
for i in range(n):
  xi = xs.copy()
  xi.remove(x[i])
  print(xi[n // 2 - 1])

### FIXED CODE ###

n = int(input())
x = [int(i) for i in input().split()]
xs = sorted(x)
d = dict()
for i in range(n):
  if xs[i] not in d:
    d[xs[i]] = i
for i in range(n):
  print(xs[n // 2 - int(d[x[i]] >= n // 2)])
### BUGGY CODE ###

def solve(i,m):
    if m == 0:
        return True
    if i == n:
        return False
    else:
        return solve(i+1,m) | solve(i+1,m-n_list[i])


n = int(input())
n_list = list(map(int,input().split()))
q = int(input())
q_list = list(map(int,input().split()))

for num in q_list:
    print('yes') if solve(0,num) else print('no')


### FIXED CODE ###

n = int(input())
a_list = list(map(int,input().split()))
q = int(input())
q_list = list(map(int,input().split()))
bits = 1

for a in a_list:
    bits |= bits << a

for q in q_list:
    if (bits>>q)&1:
        print('yes')
    else:
        print('no')
### BUGGY CODE ###

N, K, Q = map(int, input().split())
players = [K]*N

for i in range(Q):
	A = int(input())
	for j in range(N):
		if A!=j+1:
			players[j]-=1
for p in players:
	if p<1:print("No")
	else:print("Yes")

### FIXED CODE ###

n, k, q = map(int, input().split())
point = [0 for i in range(n)]
for i in range(q):
    point[int(input())-1] -= 1
for i in range(n):
    if q + point[i] < k:
        print("Yes")
    else:
        print("No")