Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    alledge.append([a-1,b-1])
if n==2:
    print(0)
    exit()


def f(x,y,c):
    c += 1
    for e in edge[x]:
        if e != y:
            if c > d and e >= 0 and e<= n-1:
                used[e] = 1
            f(e,x,c)


if k % 2 == 0:
    d = k//2
    res = []
    for i in range(n):
        used = [0]*n
        f(i,-1,0)
        res.append(sum(used))
    print(min(res))
else:
    d = (k-1)//2
    res = []
    for e1 in alledge:
        used = [0]*n
        f(e1[0],e1[1],0)
        #f(e1[1],e1[0],0)
        res.append(sum(used))
    print(min(res))


### FIXED CODE ###

import sys
#input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    alledge.append((a-1,b-1))

def f(x,y,c):
    global tmp
    c += 1
    for e in edge[x]:
        if e == y:
            continue
        if c > d:
            tmp +=1
        f(e,x,c)

sys.setrecursionlimit(4100000)

if k % 2 == 0:
    d = k//2
    ass = 2001
    for i in range(n):
        tmp = 0
        f(i,-1,0)
        ass = min(ass,tmp)
    print(ass)
else:
    d = (k-1)//2
    ass = 2001
    for e1 in alledge:
        tmp = 0
        f(e1[0],e1[1],0)
        f(e1[1],e1[0],0)
        ass = min(ass,tmp)
    print(ass)
print(len(list(set(int,input().split()))))

### FIXED CODE ###

print(len(set(map(int,input().split()))))
x,n = input().split()
x = int(x)
p = list(map(int, input().split()))

all_list = [i for i in range(1,101)]
p = reversed(sorted(p))

for i in p:
  all_list.pop(i-1)
  
if x in all_list:
  ans = x
else:
  abs_ = 100
  for i in all_list:
    if abs(x - i) < abs_:
      abs_ = abs(x - i)
      ans = i

print(ans)

### FIXED CODE ###

x,n = input().split()
x = int(x)
if int(n) != 0:
  p = list(map(int, input().split()))
else:
  p = []

all_list = [i for i in range(1,101)]
p = reversed(sorted(p))

for i in p:
  all_list.pop(i-1)
  
all_list.insert(0,0)
all_list.insert(0,-1)
all_list.append(101)

if x in all_list:
  ans = x
else:
  abs_ = 1000
  for i in all_list:
    if abs(x - i) < abs_:
      abs_ = abs(x - i)
      ans = i

print(ans)
from collections import deque

H,W=[int(i) for i in input().split()]
# c=[[i for i in input().split()] for _ in range(h)]
C=list(input() for _ in range(H))
C=list(list(i) for i in C) #visited_listを用いずに壁にしていく方法ではリスト化が必要

def bfs(maze,s1,s2,g1,g2):
    for y in range(H):
        for x in range(W):
            if maze[y][x]!='#':
                maze[y][x]=10**9

    maze[s1][s2]=0
    que=deque([[s1,s2]])
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+i,x+j
            if nexty >= 0 and nexty < H and nextx >= 0 and nextx < W:
                dist=maze[nexty][nextx]
                if dist!='#':
                    if dist>maze[y][x]+1:
                        maze[nexty][nextx]=maze[y][x]+1
                        que.append([nexty,nextx])
    return maze[g1][g2]

ans=0
for s1,c_w in enumerate(C):
    for s2,c in enumerate(c_w):
        if C[s1][s2]!="#":
            for g1,c_w in enumerate(C):
                for g2,c in enumerate(c_w):
                    if C[g1][g2]!="#":
                        temp=bfs(C,s1,s2,g1,g2)
                        ans=max(temp,ans)
print(ans)


### FIXED CODE ###

z="ABCDEFGHIJKLMNOPQRSTUVWXYZ".lower()
c=input()
print(z[z.find(c)+1])
import collections
def solve(n, a_list):

    count = collections.Counter()
    for i in a_list:
        count[i // 400] += 1

    max_value = len([i for i in count.keys() if i != 8]) + count[8]
    min_value =  1 if max_value - count[8] == 0 else max_value - count[8]
    return "{0} {1}".format(min_value, max_value)

if __name__ == "__main__":
    n = int(input())
    a_list = sorted([int(input()) for i in range(n)])
    print(solve(n, a_list))


### FIXED CODE ###

import collections
def solve(n, a_list):

    count = collections.Counter()
    for i in a_list:
        no = 8 if i // 400 >= 8 else i // 400
        count[no] += 1

    tmp = len([i for i in count.keys() if i != 8])
    max_value = tmp + count[8]
    min_value = 1 if tmp == 0 else tmp

    return "{0} {1}".format(min_value, max_value)

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))
import heapq

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


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)

H = [0]
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        H += d_AB[i]
    #else:
        #H += [0]
    #print(H)
    heapq.heapify(H)
    money += heapq.heappop(H)

print(-money)

### FIXED CODE ###

import heapq

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


d_AB = {a:[] for a,b in AB}
for a,b in AB:
    d_AB[a].append(-b)
#print(d_AB)
H = []
heapq.heapify(H)
money = 0
for i in range(1,M+1):
    if i in d_AB.keys():
        for ab in d_AB[i]:
            heapq.heappush(H,ab)
        #print(H)
        money += heapq.heappop(H)
        #print(money)
        
    else:
        money += heapq.heappushpop(H,0)

print(-money)
A = int(input("数字を入力してください:"))
B =int(input("数字を入力:"))

if A > B:
    print(A + A - 1)

elif A == B:
    print(A + B)

else:
    print(B + B -1)

### FIXED CODE ###

button = input().split()
A = int(button[0])
B = int(button[1])


if A > B:
    print(A + A - 1)

elif A == B:
    print(A + B)

else:
    print(B + B -1)
def distance(x, y):
    return (x ** 2 + y ** 2) ** (1 / 2)


def main():
    n, d = map(int, input().split())
    xy_lst = [list(map(int, input().split())) for _ in range(n)]
    count = 0

    for i in range(n):
        x = xy_lst[i][0]
        y = xy_lst[i][1]
        if distance(x, y) <= d:
            count += 1

    print(count)


if __name__ == '__main__':
    main()

### FIXED CODE ###

s = str(input())
t = str(input())
count = 0

for i in range(len(s)):
    if s[i] != t[i]:
        count += 1
        
print(count)
a,b = map(int,input().split())
op = input()
if op == "+":
  print(int(a+b))
else:
  print((a-b))

### FIXED CODE ###

l = list(input().split())
if l[1] == "+":
  print(int(l[0])+int(l[2]))
else:
  print(int(l[0])-int(l[2]))
n, k = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:k])
ans = [tmp]
if n == k:
    ans_mae = ans[0].sum()
    print((ans_mae+k)/2)
else:
    for i in range(1,n-k+1):
        tmp = tmp - p[i-1] + p[i+k-1]
        ans.append(tmp)
    print((max(ans)+k)/2)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:k])
ans = [tmp]
if n == k:
    ans_mae = ans[0]
    print((ans_mae+k)/2)
else:
    for i in range(1,n-k+1):
        tmp = tmp - p[i-1] + p[i+k-1]
        ans.append(tmp)
    print((max(ans)+k)/2)
K=int(input())
X,Y=map(int,input().split())
if K%2==0:
  print(-1)
else:
  raise Exception

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from itertools import product
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    K=int(input())
    X,Y=map(int,input().split())
    
    def is_on_square(x0,y0,x1,y1):
        return (abs(x1-x0)==K and y0-K<=y1<=y0+K) or (abs(y1-y0)==K and x0-K<=x1<=x0+K)
    
    rX=X-Y
    rY=X+Y
    x,y=0,0
    ans=[]
    while True:
        # 残り一打
        if max(abs(x-rX),abs(y-rY))==K:
            ans.append((rX,rY))
            break
        # 残り二打以内の可能性あり
        elif abs(x-rX)<=K*2 and abs(y-rY)<=K*2:
            for nx,ny in list(product((x+K,x-K),(rY+K,rY-K)))+list(product((rX+K,rX-K),(y+K,y-K))):
                if is_on_square(x,y,nx,ny) and is_on_square(rX,rY,nx,ny) and (nx+ny)%2==0:
                    x,y=nx,ny
                    break
            else:
                # Kが奇数なら一打後残り二打になる
                if K%2:
                    if x<rX:
                        x+=K
                    else:
                        x-=K
                    if y<rY:
                        y+=K
                    else:
                        y-=K
                else:
                    ans=[]
                    break
        
        else:
            # x==rX or y==rYに寄せる
            if abs(x-rX)<abs(y-rY):
                if abs(x-rX)>=K:
                    if x>rX:
                        x-=K
                    else:
                        x+=K
                    if y>rY:
                        y-=K
                    else:
                        y+=K
                else:
                    x=rX
                    if y>rY:
                        y-=K
                    else:
                        y+=K
                    if (x+y)%2:
                        x+=1
            else:
                if abs(y-rY)>=K:
                    if x>rX:
                        x-=K
                    else:
                        x+=K
                    if y>rY:
                        y-=K
                    else:
                        y+=K
                else:
                    y=rY
                    if x>rX:
                        x-=K
                    else:
                        x+=K
                    if (x+y)%2:
                        y+=1
        ans.append((x,y))
    
    if not ans:
        print(-1)
    else:
        print(len(ans))
        for x,y in ans:
            print((y+x)//2,(y-x)//2)
                
        

if __name__ == '__main__':
    main()
from copy import*
from collections import*
from numpy import*
from itertools import*
a,b=map(int,input().split())
*c,=map(int,input().split())
c1=deepcopy(c)
c2=deepcopy(c)

for i in range(1,a):
    c1[i]=min(c1[i-1],c1[i])
for i in range(a-1,0,-1):
    c2[i-1]=max(c2[i],c2[i-1])

#print(c1,c2)
d=array([k for k,v in groupby(c2)])-array([k for k,v in groupby(c1)])
#print(d)
#print(list(d).count(max(d)))

### FIXED CODE ###

from copy import*
from numpy import*
a,b=map(int,input().split())
*c,=map(int,input().split())
c1=deepcopy(c)
c2=deepcopy(c)

for i in range(1,a):
    c1[i]=min(c1[i-1],c1[i])
for i in range(a-1,0,-1):
    c2[i-1]=max(c2[i],c2[i-1])

#print(c1,c2)
d=array(c2)-array(c1)
d2=array(c)-array(c1)
print(list(d2).count(max(d)))
l = lr[0]
r = lr[1]
 
ans=2019
l_2019 = l % 2019
r_2019 = r % 2019
 
for i in range(l_2019,r_2019):
    for j in range(i+1, r_2019+1):
        new_ans = (i * j) % 2019
        if new_ans < ans:
            ans = new_ans
        
print(ans)

### FIXED CODE ###

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

l = lr[0]
r = lr[1]

ans=2018
tr=min(2019, r-l)
for i in range(l, l+tr):
    for j in range(l+1, l+tr+1):
        ans = min(ans, (i*j)%2019)
        
        
print(ans)
number = input()

for i in range(number):
  number = number+1

print(number)

### FIXED CODE ###

number = int(input())
answer = 0

for i in range(number+1):
  answer = answer + i
print(answer)
from math import gcd
k=map(int,input())
r=range(1,k+1)
ans=0
for i in r:
  for j in r:
    for k in r:
      ans+=gcd(k,gcd(i,j))
print(ans)
# 間に合うはずなくない？？


### FIXED CODE ###

# coding: utf-8
# Your code here!

def MI():return map(int,input().split())
def LI():return list(MI())

n=int(input())

import math
from collections import Counter

# def gcd(*numbers):
    # return reduce(math.gcd, numbers)

ans=0
t=[]
for i in range(1,n+1):
    for j in range(1,n+1):
        t.append(math.gcd(i,j))
        
c=Counter(t).items()

for (i,j) in c:
    for k in range(1,n+1):
        ans+=math.gcd(i,k)*j
        # p\rint(c)
print(ans)
N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))

path = [0]*N

pos = 1
for i in range(K):
    if pos in path: break
    path[i] = pos
    pos = A[pos]

head = path[:path.index(pos)]
rep = path[path.index(pos):i]

print(rep[(K - len(head)) % len(rep)])



### FIXED CODE ###

N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))

path = [0]*(N+1)
visited = set()

pos = 1
for i in range(N+1):
    if pos in visited: break
    path[i] = pos
    visited.add(pos)
    pos = A[pos]

loc = path.index(pos)
head = path[:loc]
rep = path[loc:i]

if K < len(head):
    print(head[K])
else:
    print(rep[(K - len(head)) % len(rep)])
A, B, C, D = map(int, input().split())
print(min(A, B) + min(C, D))


### FIXED CODE ###

A, B, C, D = [int(input()) for _ in range(4)]
print(min(A, B) + min(C, D))
line = input().split()
nPerson = int(line[0])
nFriend = int(line[1])
nBlock  = int(line[2])

friends = [[] for i in range(nFriend)]
for i in range(nFriend):
  line = input().split()
  friends[i] =[int(line[0]), int(line[1]) ]

blocks = [[] for i in range(nBlock)]
for i in range(nBlock):
  line = input().split()
  blocks[i] = [int(line[0]), int(line[1]) ]
  
connected = [[] for i in range(nPerson+1)]
  
for i in friends:
  connected[i[0]].append(i[1])
  connected[i[1]].append(i[0])

blocked = [[] for i in range(nPerson+1)]
for i in blocks:
  blocked[i[0]].append(i[1])
  blocked[i[1]].append(i[0])
  
for i in range(len(connected)):
  connected[i] = set(connected[i])
for i in range(len(blocked)):
  blocked[i] = set(blocked[i])
  
nCand = [0]*(nPerson+1)

def findCand(target,curPer):
  if visited[curPer] == True :
    return
  visited[curPer] = True
  if curPer not in connected[target] and curPer not in blocked[target]:
    nCand[target] += 1
  for i in connected[curPer]:
    findCand(target,i)

for i in range(1,nPerson+1):
  visited = [False]*(nPerson+1)
  visited[i] = True
  for j in connected[i]:
    findCand(i,j)

res = ""
for i in range(1,nPerson+1):
  res += str(nCand[i]) + " "
  
print(res)
  

### FIXED CODE ###

class unionFind():
  def __init__(self,n):
    self.size = n
    self.parents = [-1]*n
  def find(self, x):
     if self.parents[x] < 0:
       return x
     else:
       self.parents[x] = self.find(self.parents[x])
       return self.parents[x]
      
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def grpsize(self, x):
    return -self.parents[self.find(x)]
  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]
  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.size) if self.find(i) == root]
  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
import sys
sys.setrecursionlimit(4100000)

line = input().split()
nPerson = int(line[0])
nFriend = int(line[1])
nBlock  = int(line[2])

friends = [[] for i in range(nFriend)]
for i in range(nFriend):
  line = input().split()
  friends[i] =[int(line[0])-1, int(line[1])-1]

nconnected = [0]*nPerson
for i in friends:
    nconnected[i[0]] += 1
    nconnected[i[1]] += 1
  
  
blocks = [[] for i in range(nBlock)]
for i in range(nBlock):
  line = input().split()
  blocks[i] = [int(line[0])-1, int(line[1])-1]

uf = unionFind(nPerson)
for i in friends:
  uf.union(i[0],i[1])

nblocked = [0]*nPerson
for i in blocks:
  if uf.find(i[0]) == uf.find(i[1]):
    nblocked[i[0]] += 1
    nblocked[i[1]] += 1
  
res = ""
for i in range(nPerson):
  res += str(uf.grpsize(i)-nconnected[i] -nblocked[i]-1) + " "

print(res)
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(len(L)-2):
  for j in range(i+1, len(L)-1):
    k = j + 1
    while L[k-1] == L[k]:
      k += 1
    T = L[k:]
    cnt += bisect_left(T,L[i]+L[j])

print(cnt)


### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += max(bisect_left(L, L[i]+L[j]) - (j+1), 0)

print(cnt)
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

A, B, M = map(int, input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
List_discount = [list(map(int, input().split())) for i in range(M)]

# print(List_discount)
ans = 2 * 10**5
for d in List_discount:
    # print(d)
    p = List_A[d[0]-1] + List_B[d[0]-1] - d[2]
    ans = min(ans, p)
no_discount = min(List_A) + min(List_B)
ans = min(ans, no_discount)
print(ans)


### FIXED CODE ###

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

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

A, B, M = map(int, input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
List_discount = [list(map(int, input().split())) for i in range(M)]

# print(List_discount)
ans = 2 * 10**5
for d in List_discount:
    # print(d)
    p = List_A[d[0]-1] + List_B[d[1]-1] - d[2]
    ans = min(ans, p)
no_discount = min(List_A) + min(List_B)
ans = min(ans, no_discount)
print(ans)
w, h, x, y = map(int,input().split())

if w / 2 == x and h / 2 == y:
    print((w - x) * h,end=" ")
    print(1)
elif w / x == h / y:
    print(w * h / 2,end=" ")
    print(0)
elif w / 2 == x:
    print(x * h,end=" ")
    print(0)
elif h / 2 == y:
    print(w * y,end=" ")
    print(0)
else:
    print(max(w * y,x * h),end=" ")
    print(0)

### FIXED CODE ###

w, h, x, y = map(int,input().split())

if w / 2 == x and h / 2 == y:
    print(w * h / 2, 1)
else:
    print(w * h / 2, 0)
a, b, c = map(int, input().split(" "))
if a % 2 = 0 and b % 2 = 0 and c % 2 = 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a, b, c = map(int, input().split(" "))
if a + b == c or b + c == a or c + a == b:
  print("Yes")
else:
  print("No")
a, b, k = map(int, input().split())

ans = []

for i in range(1, max(a, b) + 1):
  if a % i == 0 and b % i == 0:
    ans.append(i)

    print(ans[-k])




### FIXED CODE ###

a, b, k = map(int, input().split())

ans = []

for i in range(1, max(a, b) + 1):
	if a % i == 0 and b % i == 0:
		ans.append(i)

print(ans[-k])
N=int(input())
a=list(map(int,input().split()))

res=[0]*(N+1)
for i in range(1,N+1)[::-1]:
    sum_res=sum(res[x] for x in range(i,N+1,i))
    if sum_res % 2!=a[i-1]:
        res[i] = 1

print(sum(res))

if sum(res):
    ans=[]
    for i,ele in enumerator(res):
        if ele:
            ans.append(i)
    print(*ans)

### FIXED CODE ###

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

res=[0]*(N+1)
for i in range(1,N+1)[::-1]:
    sum_res=sum(res[x] for x in range(i,N+1,i))
    if sum_res % 2!=a[i-1]:
        res[i] = 1

print(sum(res))

if sum(res):
    ans=[]
    for i,ele in enumerate(res):
        if ele:
            ans.append(i)
    print(*ans)
import bisect
n, m = list(map(int, input().split(' ')))
aaa = list(map(int, input().split(' ')))
aaa = sorted([-a for a in aaa])
len_aaa = len(aaa)

cccbbb = []
for i in range(m):
    b, c = list(map(int, input().split(' ')))
    cccbbb.append((-c, b))
cccbbb = sorted(cccbbb)
for c, b in cccbbb:
    index = bisect.bisect_left(aaa, c)
    if index < len_aaa:
        ccc = [c] * min(b, len_aaa - index)
        aaa = (aaa[:index] + ccc + aaa[index:max(index, len_aaa - min(b, len_aaa - index))])
        print(aaa)
    else:
        break
print(abs(sum(aaa)))

### FIXED CODE ###

import bisect
n, m = list(map(int, input().split(' ')))
aaa = list(map(int, input().split(' ')))
aaa = sorted([-a for a in aaa])[::-1]
len_aaa = len(aaa)

cccbbb = []
for i in range(m):
    b, c = list(map(int, input().split(' ')))
    cccbbb.append((-c, b))
cccbbb = sorted(cccbbb)
ccc = []
for c, b in cccbbb:
    ccc += [c] * b
    if len(ccc) > len_aaa:
        break
ans = 0
for i in range(len_aaa):
    c = ccc[i] if i < len(ccc) else 0
    ans += min(aaa[i], c)
print(abs(ans))
from collections import defaultdict
from bisect import bisect_right

N, K = map(int, input().split())
*A, = map(int, input().split())

dd = defaultdict(list)
for i, j in enumerate(A):
    dd[j].append(i)

pos = 0
loop = 1
# l = []
cic = defaultdict(list)

while pos < N:
    num = A[pos]
    
    pp = bisect_right(dd[num], pos)
    if pp < len(dd[num]):
        pos = dd[num][pp]+1
    else:
        pos = dd[num][0]+1            
        loop += 1
    # l.append((pos, loop))
    cic[loop].append(pos)

# for pos, v in l:
#     if (K-v)%loop==0:
#         break

if cic[K%loop]:
    print()
else:
    pos = cic[K%loop][0] #pos if pos<N else 0
    ans = []
    while pos < N:
        num = A[pos]
        pp = bisect_right(dd[num], pos)
        if pp < len(dd[num]):
            pos = dd[num][pp]+1
        else:
            ans.append(num)
            pos += 1
    print(*ans)


### FIXED CODE ###

from collections import defaultdict, Counter
from bisect import bisect_right, bisect_left

N, K = map(int, input().split())
*A, = map(int, input().split())

c = Counter(A)
target = []
d = defaultdict(list)

dd = defaultdict(list)
for i, j in enumerate(A):
    dd[j].append(i)

pos = 0
loop = 1
l = []

while pos < N:
    num = A[pos]
    
    pp = bisect_right(dd[num], pos)
    if pp < len(dd[num]):
        pos = dd[num][pp]+1
    else:
        pos = dd[num][0]+1            
        loop += 1
    l.append((num, pos, loop))

for v, pos, p in l:
    if (K-p)%loop==0:
        break

pos = pos if pos<N else 0
ans = []
while pos < N:
    num = A[pos]
    pp = bisect_right(dd[num], pos)
    if pp < len(dd[num]):
        pos = dd[num][pp]+1
    else:
        ans.append(num)
        pos += 1
print(*ans)
hoge=input()
key=input()
ans=[]
for i in range(len(hoge)-len(key)+1):
  flag=0
  for j in range(len(key)):
    if(hoge[i+j]==key[j] or hoge[i+j]=="?"):
      flag+=1
  if(flag==len(key)):
    kari=hoge[:i]+key+hoge[i+len(key):]
    ans.append(kari.replace("?","a"))
    
ans.sort()
print(ans[0])

### FIXED CODE ###

hoge=input()
key=input()
ans=[]
for i in range(len(hoge)-len(key)+1):
  flag=0
  for j in range(len(key)):
    if(hoge[i+j]==key[j] or hoge[i+j]=="?"):
      flag+=1
  if(flag==len(key)):
    kari=hoge[:i]+key+hoge[i+len(key):]
    ans.append(kari.replace("?","a"))
    
if(len(ans)>0):
  ans.sort()
  print(ans[0])
else:
  print("UNRESTORABLE")
N, M = map(int, input().split())
check = [0] * M
for i in range(N):
    a = [int(i - 1) for i in input().split()]
    a = a[1:]
    for j in check:
        check[j] += 1
    

ans = 0
for i in check:
    if i == N:
        ans += 1
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
check = [0] * M
for i in range(N):
    a = [int(i) - 1 for i in input().split()]
    a = a[1:]
    for j in a:
        check[j] += 1


ans = 0
for i in check:
    if i == N:
        ans += 1
print(ans)
N=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        aw=(N*n*h)
        bw=4*n*h-N*h-N*n
        if bw!=0 and bw/aw=bw//aw:
            h=i
            n=j
            break
print(h,n,bw//aw)

### FIXED CODE ###

N=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        bw=4*i*j-N*i-N*j
        if bw<=0:
            continue
        if (N*i*j)%bw==0:
            print(i,j,(N*i*j)//bw)
            exit()
N, A, B = map(int, input().split())
S = str(input())

total = 0
kaigai = 0

for i in range(0, len(S)):
    if L[i] == 'a':
        if total < A+B:
            print('Yes')
            total += 1
        else:
            print('No')
    elif L[i] == 'b':
        if total < A+B & kaigai <B:
            print('Yes')
            total += 1
            kaigai += 1
        else:
            print('No')
    else:
        print('No')


### FIXED CODE ###

N, A, B = map(int, input().split())
L = str(input())

total = 0
kaigai = 0

for i in range(0, len(L)):
	if L[i] == 'a':
		if total < A + B:
			print('Yes')
			total += 1
		else:
			print('No')
	elif L[i] == 'b':
		if total < A + B and kaigai < B:
			print('Yes')
			total += 1
			kaigai += 1
		else:
			print('No')
	else:
		print('No')