Harryxun/stf_run huggingface dataset:
N,A,B,C = list(map(int, input().split()))
s = [input() for i in range(N)]

ns = [s[0]]
for v in s[1:]:
  if v!=ns[-1]:
    ns.append([v,1])
  else:
    ns[-1][1] += 1

ans = "No"
q = [[] for i in range(N+1)]
q[0] = [(A,B,C,[])]
for i in range(N):
  while q[i]:
    a,b,c,trace = q[i].pop(0)
    if s[i] == "AB":
      if a-1>0:
        q[i+1].append((a-1,b+1,c,trace+["B"]))
      if b-1>0:
        q[i+1].append((a+1,b-1,c,trace+["A"]))
    if s[i] == "BC":
      if b-1>0:
        q[i+1].append((a,b-1,c+1,trace+["C"]))
      if c-1>0:
        q[i+1].append((a,b+1,c-1,trace+["B"]))
    if s[i] == "AC":
      if a-1>0:
        q[i+1].append((a-1,b,c+1,trace+["C"]))
      if c-1>0:
        q[i+1].append((a+1,b,c-1,trace+["A"]))
if q[N]:
  a,b,c,trace = q[N].pop(0)
  ans = "Yes"


print(ans)
if ans =="Yes":
  for v in trace:
    print(v)
  

### FIXED CODE ###

N,A,B,C = list(map(int, input().split()))
s = [input() for i in range(N)]

u = ["A","B","C"]
ss = ["BC","AC","AB"]
t = [A,B,C]
trace = []
ans = "Yes"
for i in range(N):
  idx = ss.index(s[i])
  if t[(idx+1)%3] == 0 and t[(idx+2)%3] == 0:
    ans = "No"
    break
  elif t[(idx+2)%3] == 0:
    t[(idx+1)%3] -= 1
    t[(idx+2)%3] += 1
    trace.append(u[(idx+2)%3])
  elif t[(idx+1)%3] == 0:
    t[(idx+1)%3] += 1
    t[(idx+2)%3] -= 1
    trace.append(u[(idx+1)%3])
  elif i+1<N and s[i+1] == ss[(idx+1)%3]:
    t[(idx+1)%3] -= 1
    t[(idx+2)%3] += 1
    trace.append(u[(idx+2)%3])
  else:
    t[(idx+1)%3] += 1
    t[(idx+2)%3] -= 1
    trace.append(u[(idx+1)%3])
print(ans)
if ans == "Yes":
  for v in trace:
    print(v)
n=int(input())
a=[int(i) for i in input().split()]
count=0
ans=[[0 for i in range(2)] for j in range(2*n)]
aaa=0

a_max=max(a)
a_min=min(a)

if abs(a_max)>=abs(a_min):
    delta=a_max
else:
    delta=a_min

if delta>0:
    seifu=1
else:
    seifu=-1

for i in range(n):
    if delta==a[i]:
        aaa=i+1
        break


#print(aaa)
#print(a,a_max,a_min)



for i in range(n-1):
    while a[i]>a[i+1]:
        if seifu==1:
            a[i+1]=a[i+1]+delta
            ans[count][0], ans[count][1]=aaa, i+2
        else:
            a[i]=a[i]+delta
            ans[count][0], ans[count][1]=aaa, i+1
        count=count+1
        
print(count)
for i in range(count):
    print(ans[i][0],ans[i][1])


### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]
count=0
ans=[[0 for i in range(2)] for j in range(2*n)]
aaa=0

a_max=max(a)
a_min=min(a)
if abs(a_max)>=abs(a_min):
    delta=a_max
else:
    delta=a_min
if delta>0:
    seifu=1
else:
    seifu=-1

for i in range(n):
    if delta==a[i]:
        aaa=i+1
        break




if seifu==1:

  for i in range(n-1):
    while a[i]>a[i+1]:
        if seifu==1:
            a[i+1]=a[i+1]+delta
            ans[count][0], ans[count][1]=aaa, i+2
        count=count+1
        a_max=max(a)
        delta=a_max
        for k in range(n):
            if delta==a[k]:
                aaa=k+1

else:
  for i in range(n-1):
    while a[n-2-i]>a[n-1-i]:
        if seifu==-1:
            a[n-2-i]=a[n-2-i]+delta
            ans[count][0], ans[count][1]=aaa, n-2-i+1
        count=count+1

        a_min=min(a)
        delta=a_min
        for k in range(n):
            if delta==a[k]:
                aaa=k+1


print(count)
for i in range(count):
    print(ans[i][0],ans[i][1])
N,K = map(int,input().split())
p = list(map(int,input().split()))
array = []

for i in range(N-K):
a=sum(p[i:K+i])
array.append(a)

max_a = max(array)

ans=(max_a)
print(ans)
  


### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))

    tmp_max = sum(P[:K])
    tmp = sum(P[:K])
    for i in range(N-K):
        tmp += P[i+K]
        tmp -= P[i]

        if tmp > tmp_max:
            tmp_max = tmp

    print((tmp_max + K) / 2)

main()
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort(reverse=True)
c=0
for i in range(k):
    h.pop(0)
    
for i in range(len(h)):
    c+=h[i]
print(c)


### FIXED CODE ###

import math
h,a=map(int,input().split())
t=math.ceil(h/a)
print(t)
import numpy as np
N, M, K = map(np.int64, input().split())
A = list(map(np.int64, input().split()))
B = list(map(np.int64, input().split()))

time0 = 0
cnt = 0
while(time0<=K):
    if len(A) == 0 and len(B) != 0:
        time0 += B.pop(0)
        cnt += 1
    elif len(B) == 0 and len(A) != 0:
        time0 += A.pop(0)
        cnt += 1
    elif len(A) == 0 and len(B) == 0:
        cnt += 1
        break
    else:
        if A[0] < B[0]:
            time0 += A.pop(0)
            cnt += 1
        elif A[0] > B[0]:
            time0 += B.pop(0)
            cnt += 1
        else:
            if A[1]<=B[1]:
                time0 += A.pop(0)
                cnt+=1
            else:
                time0 += B.pop(0)
                cnt+=1
            
cnt -= 1

print(cnt)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
aa = 0
for i in range(1,N+1):
    aa += A[i-1]
    a.append(aa)
    
b = [0]
bb = 0
for i in range(1,M+1):
    bb += B[i-1]
    b.append(bb)
    
time0 = 1
ans = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    else:
        while(j >= 0):
            if b[j] <= K - a[i]:
                ans = max(ans, i+j)
                break
            else:
                j -= 1
        
        
            
print(ans)
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    print('ABC' + str(n))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    print('ABC' + str(n))

if __name__ == '__main__':
    main()
n = input()
a = list(map(int, input().split())
ans = 0
while all(_%2 == 0 for _ in a):
	a = [_/2 for _ in a]
    ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 0
while all(a%2 == 0 for a in A):
  A = [a/2 for a in A]
  ans += 1
print(ans)
b=input()
print("T" if B=="A" else "A" if B=="T" else "G" if B=="C" else "C" if B=="G")


### FIXED CODE ###

B=input()
print("T" if B=="A" else "A" if B=="T" else "G" if B=="C" else "C")
import bisect
def f(x,a):
  global N
  b = bisect.bisect_left(a,x)
  return True if x==a[min(b,N)] else False
MOD = 10**9+7
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
a.sort()
x = 0
y = 1
for i in range(N):
  if f(i,a) and f(i+1,a):
    print(0)
    exit()
  elif f(i+1,a):
    z = 0
  else:
    z = x + y
  x = y
  y = z
print(z%MOD)


### FIXED CODE ###

import bisect
def f(x,a):
  global M
  b = bisect.bisect_left(a,x)
  if x==a[min(b,M)]:
    return True
  else:
    return False
MOD = 10**9+7
N,M = map(int,input().split())
a = [-1]+[int(input()) for _ in range(M)]
a.sort()
x = 0
y = 1
for i in range(N):
  if f(i,a) and f(i+1,a):
    print(0)
    exit()
  elif f(i+1,a):
    z = 0
  else:
    z = x + y
  x = y
  y = z
print(z%MOD)
a,b,c = [int(i) for i in input() split()]
if a < b < c:
  print("YES)
else:
  print("NO")

### FIXED CODE ###

a,b,c = [int(i) for i in input().split()]
if a < b < c:
  print('Yes')
else:
  print('No')
from sys import stdin

n = int(stdin.readline().rstrip())

sum = 0
for i in range(n):
    if i%5==0:
        continue
    if i%3==0:
        continue
    sum +=15 i

print(sum)


### FIXED CODE ###

from sys import stdin

n = int(stdin.readline().rstrip())

sum = 0
for i in range(1,n+1):
    if i%5==0:
        continue
    if i%3==0:
        continue
    sum += i

print(sum)
n = int(input())
h = list(map(int,input().split()))
cost = [100000] * n
cost[0] = 0
cost[1] = abs(h[0]-h[1])
for i in range(2,n):
    sgl = cost[i-1] + abs(h[i]-h[i-1])
    dbl = cost[i-2] + abs(h[i]-h[i-2])
    cost[i] = min(sgl,dbl)
print(cost[n])

### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
cost = [100000] * n
cost[0] = 0
cost[1] = abs(h[0]-h[1])
for i in range(2,n):
    sgl = cost[i-1] + abs(h[i]-h[i-1])
    dbl = cost[i-2] + abs(h[i]-h[i-2])
    cost[i] = min(sgl,dbl)
print(cost[-1])
lines = sys.stdin.readlines()

digits = int(lines[0][0])

nums = [l.split() for l in lines[1:]]
result = ['0'] * digits

digit_set = set()
for num in nums:
    num_index = int(num[0])-1
    num_value = num[1]
    if num_index in digit_set and result[num_index] != num_value:
        print(-1)
        break
    digit_set.add(num_index)
    result[num_index] = num_value
else:
    if digits > 1 and result[0] == '0':
        print(-1)
    else:
        print(''.join(result))
        

### FIXED CODE ###

n = int(input())
print(n // 2  + (n % 2))
K=int(input())
A=int(input())
B=int(input())
largest=(B/K)*K
if A<=largest:
  print("OK")
else:
  print("NG")

### FIXED CODE ###

K = int(input())
A, B  = map(int, input().split())
X = B//K - A//K

if B%K == 0 or A%K == 0:
    print("OK")

elif X == 0 :
    print("NG")

else :
    print("OK")
import numpy as np
N,K = map(int,input().split())
list = []
list_tmp = [0]*(K-1)
for i in range(N):
 list.append(int(input()))
 if i < N-K:
  list_tmp.append(list[i])
list = sorted(list);
list_tmp = sorted(list_tmp);
tmp = list[-K:];
tmp_list =  list_tmp[K:]
tmp = np.array(tmp)
tmp_list = np.array(tmp_list)
print(min(tmp - tmp_list))

### FIXED CODE ###

import numpy as np
N,K = map(int,input().split())
list = []
for i in range(N):
 list.append(int(input()))
list = sorted(list);
print(min(list[i+K-1] - list[i] for i in range(N-K+1)))
n = int(input())
h = list(map(int, input().split()))
for i in range(n-1):
  if h[i+1] - h[i] > 1:
    print("No")
    break
else:
  for i in range(n-1):
    if h[i+2] - h[i+1] == h[i+1] - h[i] == 1:
      print("No")
      break
  else:
    print("Yes")

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
for i in range(n-1):
  if h[n-1-i] >= h[n-2-i]:
    continue
  elif h[n-2-i] - h[n-1-i] == 1:
    h[n-2-i] -= 1
  else:
    print("No")
    break
else:
  print("Yes")
#coding:utf-8

n = int(input())
power = 1

for i in range(n):
  power = ((i+1) * power) % (7 + 10＊＊９)

print(power)

### FIXED CODE ###

#coding:utf-8

n = int(input())
p = 1

for i in range(0,n):
  p = ((i+1) * p) % (10**9 + 7)

print(p)
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count += abs(y-(median+x+1))
print(count)

### FIXED CODE ###

import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)
aopb = input().split('+'or'-')

if aopb[1] == '+':
    print(int(aopb[0]) + int(aopb[2]))
else:
    print(int(aopb[0]) - int(aopb[2]))


### FIXED CODE ###

aopb = input().split()

if aopb[1] == '+':
    print(int(aopb[0]) + int(aopb[2]))
else:
    print(int(aopb[0]) - int(aopb[2]))
n=int(input())
a=list(map(int,input().split()))
m=a[0]
ans=1
for i,z in enumerate(a):
  if i==0:continue
  if z<=m:
    ans+=1
  m=min(m,z)
print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
if(n==m):
  print('Yes')
else:
  print('No')
d=raw_input().split(" ")
l=list(map(int,d))
if(i[2]>0 and i[3]>0):
    if(l[0]>=(l[2]+l[4])):
        if(l[1]>=(l[3]+l[4])):
            print "Yes"
        else:
            print "No"
    else:
        print "No"
else:
   print "No"


### FIXED CODE ###

d=raw_input().split(" ")
l=list(map(int,d))
if(l[2]>0 and l[3]>0):
    if(l[0]>=(l[2]+l[4])):
        if(l[1]>=(l[3]+l[4])):
            print "Yes"
        else:
            print "No"
    else:
        print "No"
else:
   print "No"
N, K = map(int, input().split())

if K != 1:
    ans = N%(abs(N-K))
else:
    ans = 0
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
ans = min(K-(N%K), N%K)
print(ans)
H, N = map(int, input().split())

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

import numpy as np

d = [0] + [10**18] * H

for hp in range(1, H + 1):
    for ab in AB:
        # print(ab)
        hp_remain = np.max(hp - ab[0], 0)
        # if hp_remain < 0: hp_remain = 0
        # print(hp_remain)
        c = d[hp_remain] + ab[1]
        if c < d[hp]: d[hp] = c

print(d[H])




### FIXED CODE ###

import numpy as np


H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
a, b = np.array(AB, dtype=np.int64).reshape(N, 2).T

d = np.zeros(H + 1, dtype=np.int64)

for hp in range(1, H + 1):
    c = d[np.maximum(hp - a, 0)] + b
    d[hp] = np.amin(c)

print(d[H])
a, b = input().split()
a = int(a)
b = int(b)
print('Even' if a*b%==0 else 'Odd') 

### FIXED CODE ###

a, b = input().split()
a = int(a)
b = int(b)
print('Even' if a * b % 2 == 0 else 'Odd')
n = int(input())
aa = list(map(int, input().strip().sprit()))

g = 0

# for 文書きたくねぇ
for a in aa:
    g += 1 / a

print(1 / g)

### FIXED CODE ###

n = int(input())
aa = list(map(int, input().strip().split()))

g = 0

# for 文書きたくねぇ
for a in aa:
    g += 1 / a

print(1 / g)
n = input()
print(n.replace('1','x').replace('9','1').replace('x','9')

### FIXED CODE ###

n = input()
print(n.replace('1','x').replace('9','1').replace('x','9'))
N = int(input())

def wa(x):
    s = 0
    while x > 0:
        s += x % 10
        x = int(x / 10)
    return s
L = []
for i in range(2,N):
    A = i
    B = N - i
    x = wa(A) + wa(B)
    L.append(x)
    
L = sorted(L)
    
print(L[0])

### FIXED CODE ###

N = int(input())

def wa(x):
    s = 0
    while x > 0:
        s += x % 10
        x = int(x / 10)
    return s
L = []
for i in range(1,N):
    A = i
    B = N - i
    x = wa(A) + wa(B)
    L.append(x)
    
L = sorted(L)
    
print(L[0])
s=input()
X,Y=map(int,input().split())
def solve(a,G):
    dp=[[0]*20000 for _ in range(len(x))]
    dp[0][a[0]]=1

    for i in range(1,len(a)):

        for j in range(-9000,9000):
            dp[i][j-a[i]]+=dp[i-1][j]
            dp[i][j+a[i]]+=dp[i-1][j]
            #print(dp)
    for i in range(len(a)):
        if dp[i][G]>=1:
            return True
    return False

x=[]
y=[0]
flg=1
cnt=0
if s[0]=="T":
    x.append(0)
for i in range(len(s)):
    if s[i]=="F":
        cnt+=1
    else:
        if flg==1:
            x.append(cnt)
            flg*= -1
            cnt=0
        else:
            y.append(cnt)
            flg*= -1
            cnt=0
if flg==1:
    x.append(cnt)
else:
    y.append(cnt)
#print(x)
#print(y)
if not solve(y,Y):
    print("a")
if solve(x,X) and solve(y,Y):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

s=input()
X,Y=map(int,input().split())
from collections import defaultdict
def solve(da,dp,G):
    for i in range(len(da)):
        tmp=set()
        for j in dp:
            tmp.add(j-da[i])
            tmp.add(j+da[i])
        dp=tmp
    if G in dp:
        return True
    else:
        return False
    """amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False
    if a[0]==G:
        return True
    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            #print(dp)
        if dp[i%3][G]>=1:
            return True
    return False"""
    """#print(a)
    dp=set()
    dp.add(a[0])
    dp2=set()
    for i in range(1,len(a)):
        for j in dp:
            dp2.add(j-a[i])
            dp2.add(j+a[i])
        dp=copy.deepcopy(dp2)
    #print(dp)
    if G in dp:
        return True
    return False"""

d=[len(x) for x in s.split("T")]

dx=d[2::2]
dy=d[1::2]

if solve(dx,{d[0]},X) and solve(dy,{0},Y):
    print("Yes")
else:
    print("No")
from itertools import combinations_with_replacement
n,m,x=map(int,input().split())
l=[0,1]
hon=list(combinations_with_replacement(l,n))

c=[]
a=[]

ans=1001001001

for i in range(n):
  tmp=list(map(int,input().split()))
  c.append(tmp[0])
  a.append(tmp[1:])

for i,k in enumerate(hon):
  skill=[0 for i in range(m)]
  cost=0
  flag=True
  for j in range(m):
    if k[j]==1:
      for _ in range(m):
        skill[_]+=a[j][_]
      cost+=c[j]
  for j in range(m):
    if skill[j]<x:
      flag=False
      break
  if flag:
    ans=min(ans,cost)
if ans==1001001001:
  ans=-1
print(ans)

### FIXED CODE ###

from itertools import combinations_with_replacement
n,m,x=map(int,input().split())

c=[]
a=[]

INF=1001001001
ans=INF

for i in range(n):
  tmp=list(map(int,input().split()))
  c.append(tmp[0])
  a.append(tmp[1:])

for i in range(1<<n):
  cost=0
  skill=[0 for _ in range(m)]
  for j in range(n):
    if (i>>j)&1==1:
      #print("i,j,(i>>j&1)",i,j,(i>>j&1))
      cost+=c[j]
      for k in range(m):
        skill[k]+=a[j][k]
  #print("skill",skill,"i",i)
  flag=True
  for j in range(m):
    if skill[j]<x:
      flag=False
      break
  if flag:
    ans=min(ans,cost)
if ans==INF:
  ans=-1
print(ans)
#--import&define---------------------
import math

def yes():
    print("Yes")
def no():
    print("No")
#--my_library--------------------------------
#mapを利用したリストの入力
# x,y = map(int,input().split())

#forを利用したリストの入力
#l = []
#for i in range():
#    l.append(int(input()))

#intの最大値と最小値
#maxX = 2147483647
#minX =-2147483648
#--以下解答---------------------------------
#分からない

n = int(input())
l = []
min = 2147483647
for i in range(n):
    l.append(int(input()))
    min = l[i] if l[i]<min else min

if n%min == 0:
    print(n/min+4)
else:
    tmp = n/min +1
    print(n/tmp+4)


### FIXED CODE ###

N,*A = map(int,open(0).read().split())
print((N+min(A)-1)//min(A) + 4)
from math import inf
A,B=map(int,input().split(' '))
print(min([i if i>0 else inf for i in [B-A,A+B+1,-B+A+2]]))

### FIXED CODE ###

A,B=map(int,input().split(' '))
print(min([i if i>0 else 10**10 for i in [B-A,A+B+1,-B+A+2,-B-A+1]]))
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = max(m.cail(tt/t),m.ceil(aa/a))
    vote = vote * n
print(vote)

### FIXED CODE ###

n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt//t),(aa//a))))
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)
import sys
sys.setrecursionlimit(2 * 10**5)

N = int(input())
X = [i for i in input()]
sum_X = X.count("1")


def f(n, p):
    res = int(n, 2) % p
    if res != 0:
        temp2 = format(res, "b")
        return f(temp2, temp2.count("1")) + 1
    return 1


for i in range(0, N):
    tempX = ""
    count = sum_X
    if X[i] == "0":
        count += 1
        X[i] = "1"
        tempX = "".join(X)
        X[i] = "0"
    else:
        count -= 1
        X[i] = "0"
        tempX = "".join(X)
        X[i] = "1"

    print(f(tempX, count))

### FIXED CODE ###

N = int(input())
X = input()
X_i = int(X, 2)
X_b = bin(X_i)
sum_X = X_b.count("1")
Xp = X_i % (sum_X + 1)
Xm = X_i % (sum_X - 1) if sum_X - 1 > 0 else -1


def f(n, p):
    count = 1
    n %= p
    while n != 0:
        p = bin(n).count("1")
        n %= p
        count += 1
    return count


for i in range(1, N + 1):
    if X[i - 1] == "1":
        if sum_X - 1 <= 0:
            print(0)
            continue
        nm = pow(2, N - i, sum_X - 1)
        print(f(Xm - nm, sum_X - 1))
    else:
        np = pow(2, N - i, sum_X + 1)
        print(f(Xp + np, sum_X + 1))
import sympy
sympy.divisors(10**9)
n = int(input())

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

a.sort(reverse = True)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

if len(set(a)) == 1:
    print(0)
else:
    
    
    ans = 0

    for i in range(n):
        target = make_divisors(a[i])
        if len(set(target) & set(a)) == 1:
            ans += 1

    print(ans)
        

### FIXED CODE ###

n = int(input())

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

M = 1000005

cnt = [0 for i in range(M)]

for x in a:
    if cnt[x] != 0:
        cnt[x] = 2
        continue
    for i in range(x, M, x):
        cnt[i] += 1

ans = 0

for x in a:
    if cnt[x] == 1:
        ans += 1
    
print(ans)
i,x = map(int,input().split()):
 if x == 0;
  break 
  
 print(case i : x)

### FIXED CODE ###

i = 1

while True:

 x=int(input())
 if x==0:
  break
 print("Case {0}: {1}".format(i,x))
 i+=1
n = input()
s = []
while len(s) < 2*n:
    s = s+list(input())+[' ']
    
a = {}
for i in range(1,int(n)+1):
    a[i] = int(s[2*i-2])

result = 0
for i in range(1,int(n)+1):
    if a[a[i]] == i:
        result = result+1
result = int(result/2)
print(result)

### FIXED CODE ###

n = input()
a = input()
a = a.split(sep=' ')

result = 0
for i in range(1,int(n)+1):
    if int(a[int(a[i-1])-1]) == i:
        result = result+1
result = int(result/2)
print(result)
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [False for _ in range(N)]

i = 1
c = 0
jun = []
while True:
    if visited[i-1]:
        lp = i
        break
    else:
        visited[i - 1] = True
        jun.append(i)
        i = A[i-1]
        c += 1
ji = jun.index(lp)
K -= len(jun[:ji+1])
jun = jun[lp:]

kai = K % c

if len(jun) == 0:
    print(1)
    exit()

if kai == len(jun):
    print(jun[0])
else:
    print(jun[kai])

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [False for _ in range(N)]

i = 1
c = 0
jun = []

if K <= N:
    while True:
        K -= 1
        i = A[i-1]
        if K == 0:
            print(i)
            exit()


while True:
    if i == A[i-1]:
        print(i)
        exit()
    if visited[i-1]:
        lp = i
        break
    else:
        visited[i - 1] = True
        jun.append(i)
        i = A[i-1]
        c += 1
ji = jun.index(lp)
K -= len(jun[:ji])
jun = jun[ji:]

kai = K % len(jun)
if kai == len(jun):
    print(jun[0])
else:
    print(jun[kai])