Harryxun/stf_run huggingface dataset:
from collections import defaultdict,deque
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
  print(-1)
  exit()
G=defaultdict(set)
for i in range(M):
  a,b,c=map(int,input().split())
  G[a+c<<30].add(b+c<<30)
  G[b+c<<30].add(a+c<<30)
  G[a].add(a+c<<30)
  G[b].add(b+c<<30)
  G[a+c<<30].add(a)
  G[b+c<<30].add(b)
def BFS(x):
  d={}
  for k in G.keys():
    d[k]=float("inf")
  stack=deque([(x,0)])
  while stack:
    s,m=stack.popleft()
    if s==N:
      return m
    if d[s]>m:
      d[s]=m
      if s>=(1<<30):
        for i in G[s]:
          if d[i]>10**7:
            stack.appendleft((i,m))
      else: 
        for i in G[s]:
          if d[i]>10**7:
            stack.append((i,m+1))
  return -1

print(BFS(1))



      
    

### FIXED CODE ###

from collections import defaultdict,deque
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
  print(-1)
  exit()
G=defaultdict(set)
for i in range(M):
  a,b,c=map(int,input().split())
  G[a+(c<<30)].add(b+(c<<30))
  G[b+(c<<30)].add(a+(c<<30))
  G[a].add(a+(c<<30))
  G[b].add(b+(c<<30))
  G[a+(c<<30)].add(a)
  G[b+(c<<30)].add(b)
def BFS(x):
  d={}
  for k in G.keys():
    d[k]=float("inf")
  stack=deque([(x,0)])
  if x not in d:
    return -1
  while stack:
    s,m=stack.popleft()
    if s==N:
      return m
    if d[s]>m:
      d[s]=m
      if s>=(1<<30):
        for i in G[s]:
          if d[i]>10**30:
            stack.appendleft((i,m))
      else: 
        for i in G[s]:
          if d[i]>10**30:
            stack.append((i,m+1))
  return -1

print(BFS(1))
import math
def ppcm(x,y):
    return (x*y) // math.gcd(x,y)
A,B = map(int,input().split())
print(ppcm(A,B))

### FIXED CODE ###

def PGCD(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def ppcm(a,b):
    return a*b//PGCD(a,b)
A,B = map(int,input().split())
print(ppcm(A,B))
n,k=map(int,input().split())
list=[0]*(10**5+1)
for i in range(n):
    a,b=map(int,input().split())
    list[a]+=b
sum=0
for l in range(1,len(list)):
    sum+=list[l]
    if sum>=k:
        print(l)
        exit()


### FIXED CODE ###

a,b,c=map(int,input().split())
if a<=c<=b:
    print("Yes")
else:
    print("No")
def solve(X, Y, C, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while white_apples:
        if white_apples[-1] <= red_apples[-1] and white_apples[-1] <= green_apples[-1]:
            break

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)
    return ret + sum(red_apples) + sum(green_apples)

if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    print(solve(X, Y, C, p, q, r))

### FIXED CODE ###

def solve(X, Y, p, q, r):
    red_apples = sorted(p, reverse=True)[: X]
    green_apples = sorted(q, reverse=True)[: Y]
    white_apples = sorted(r)

    ret = 0
    while red_apples and green_apples:
        if not white_apples or (white_apples[-1] < red_apples[-1] and white_apples[-1] < green_apples[-1]):
            return ret + sum(red_apples) + sum(green_apples)

        ret += white_apples.pop(-1)
        if red_apples[-1] < green_apples[-1]:
            red_apples.pop(-1)
        else:
            green_apples.pop(-1)


    if not red_apples:
        while green_apples and white_apples and (green_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            green_apples.pop(-1)
        return ret + sum(green_apples)

    else:
        while red_apples and white_apples and (red_apples[-1] < white_apples[-1]):
            ret += white_apples.pop(-1)
            red_apples.pop(-1)
        return ret + sum(red_apples)

if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    print(solve(X, Y, p, q, r))
import numpy as np
n,m,x=map(int,input().split())
text=[]
cost=[]
for i in range(n):
    text.append(list(map(int,input().split())))
text=np.array(text)

#ビット全探索。bin(i)の各桁を要素に対応させる。
for i in range(2**n):
    flag=0
    bought_text=np.array([0 for j in range(m+1)])
    for j in range(n):
        #0bxxx1と0b0001の比較(＆は論理積)
        if((i>>j)&1):
            bought_text+=text[j]
    for k in range(m):
        if bought_text[k+1]<x:
            flag=1
            break
    if flag==0:
        cost.append(bought_text[0])
print(min(cost) if cost else "-1")

### FIXED CODE ###

import numpy as np
n,m,x=map(int,input().split())
text=[]
cost=[]
for i in range(n):
    text.append(list(map(int,input().split())))
text=np.array(text)

#ビット全探索。bin(i)の各桁を要素に対応させる。
for i in range(2**n):
    flag=0
    bought_text=np.array([0 for j in range(m+1)])
    for j in range(n):
        #0bxxx1と0b0001の比較(＆は論理積)
        if((i>>j)&1):
            bought_text+=text[j]
    for k in range(m):
        if bought_text[k+1]<x:
            flag=1
            break
    if flag==0:
        cost.append(bought_text[0])
print(min(cost) if cost else "-1")
d={c:list(input()) for c in "abc"}
s="a"
while d[s]:
  s=d[s].pop(0)
print(s.upper())

### FIXED CODE ###

import collections
a=list(input())
d=collections.defaultdict(str)
for s in a:
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
c=0
for t in dict(d).values():
    if t%2!=0:
        print("No")
        exit()
print("Yes")
calc_lsit = list(map(int,input().split()))
k = int(input())

calc_list = [a, b, c]
calc_list = sorted(calc_list)
Answer = calc_list[0] + calc_list[1] + calc_list[2]**k
print(Answer)

### FIXED CODE ###

calc_list = list(map(int,input().split()))
k = int(input())
 
calc_list = sorted(calc_list)
Answer = calc_list[0] + calc_list[1] + calc_list[2]*(2**k)
print(Answer)
#!/usr/bin/env python3
import sys
import math

def main():
    N = int(input())
    digit = math.floor(math.log10(N))
    ans = [9 * digit]
    ans.append(sum([int(s) for s in str(N)]))
    
    for i in range(1, digit+1):
        tmp = [int(s) for s in str(N//(10**i) * (10**i) - 1)]
        ans.append(sum(tmp))
    print(max(ans))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import math

def main():
    N = int(input())
    digit = int(math.log10(N))
    c = N // (10**digit)
    if N < int(str(c) + '9'*digit):
        print(9 * digit + c -1)
    else:
        print(9 * digit + c)

if __name__ == '__main__':
    main()
def check(s, p):
    if s == p:
        return 1
    else:
        return 0

word = input().lower()
print(word)
count = 0
while 1:
    array = input().lower()
    if array == "END_OF_TEXT":
        break

    print(array)
    for i in range(len(array)-len(word)+1):
        if array[i:i+len(word)] == word:
            count += 1

print(count)

### FIXED CODE ###

word = input().lower()
count = 0
while 1:
    array = input().split()
    if array[0] == "END_OF_TEXT":
        break

    for a in array:
        if a.lower() == word:
            count += 1

print(count)
def gcd(x,y):
    if x > y:
        a = x
        b = y
    else:
        a = y
        b = x
    while a % b != 0:
        b = a % b
        a = b
    return b

input()
ip = input().split()
data = []
for i in ip:
    data.append(int(i))


def lcmbase(x, y):
    return x * y / gcd(int(x), int(y))

def lcm(num):
    buf = num[0]
    for i in range(1, len(num)):
        buf = lcmbase(num[i], buf)
    return buf

usedata = int(lcm(data) - 1)

suming = 0
for i in data:
    suming += usedata % i

print(suming)

### FIXED CODE ###

input()
ip = input().split()
data = []
ans = 0
for i in ip:
    ans += int(i) - 1

print(ans)
X,A = map(int,input(),split())
if X<A print(0)
else print(10)

### FIXED CODE ###

X, A = map(int, input().split())
if X < A:
  print(0)
else:
  print(10)
a,b,c,d = map(int,input().split())
l = list(range(a, b+1))


### FIXED CODE ###

A,B,C,D = map(int,input().split())

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

def F(N,C,D):
  x = N
  x -= N//C
  x -= N//D
  lcm = C*D//gcd(C,D)
  x += N//lcm
  return x

answer = F(B,C,D) - F(A-1,C,D)
print(answer)
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
def list_count(my_list):
    dic={} #辞書型の宣言
    for num in my_list:
        if num in dic: #もしnumがkeyとして辞書にあれば
            dic[num]+=1 #valueに+1
        else: #なければ
            dic[num]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic
import sys
input = sys.stdin.readline
n=int(input())
s=list(input())
for i in range(n):
    s[i]=int(s[i])
l=[0]*1000
a=list(list_count(s).values())
print(a)
n=len(a)
m=3
dp=[[0 for i in range(n+1)] for j in range(m+1)]

#メイン
#dp[i+1][j]:=i番目までの品物からj個選ぶ組み合わせの総数

for i in range(n+1):
    dp[i][0]=1
for i in range(n):
    for j in range(1,m+1):
        if j-1-a[i]>=0:
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j]-dp[i][j-1-a[i]])
        else:
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j])

#出力
print(dp[n][m])




### FIXED CODE ###

def search(a):
    x=0
    a="".join(["0"*(3-len(a)),a])
    for i in range(n):
        if a[x]==s[i]:
            x+=1
            if x==3:
                return True
    return False
n=int(input())
s=input()
ans=0
k=[False]*1000
for i in range(1000):
    k[i]=search(str(i))
for i in k:
    if i:
        ans+=1
print(ans)
import sys
sys.setrecursionlimit(10**7)

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

mx = 10**9 + 7

from math import factorial
# def npr(n, r):
#     ans = math.factorial(n+r) // (math.factorial(n) * math.factorial(r))
#     return ans

def ncr(n, r):
    a = factorial(n) // (factorial(r) * factorial(n - r))
    return a

def solve():
    N, K = map(int, input().split())
    M = N - K

    for i in range(1, K+1):
        # まず、赤がM個あるので、両端を含む隙間 M+1 から、i個選ぶ
        agroup = ncr(M+1, i)

        # そのあと、青iこの箱にKをを分ける
        bagroup = ncr(K-1, i-1)

        print((agroup * bagroup) % mx)

solve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

mx = 10**9 + 7

from math import factorial
# def npr(n, r):
#     ans = math.factorial(n+r) // (math.factorial(n) * math.factorial(r))
#     return ans

def ncr(n, r):
    a = factorial(n) // (factorial(r) * factorial(n - r))
    return a

def solve():
    N, K = map(int, input().split())
    M = N - K

    for i in range(1, K+1):
        if M+1 < i:
            print(0)
            continue
        # まず、赤がM個あるので、両端を含む隙間 M+1 から、i個選ぶ
        agroup = ncr(M+1, i)

        # そのあと、青iこの箱にKをを分ける
        bagroup = ncr(K-1, i-1)

        print((agroup * bagroup) % mx)

solve()
#素因数分解にsympy を使ってみる（素数の列挙）
import sympy
import math
def soinsu_bunkai(m,sosu_list):
    pf={}
    for i in sosu_list:
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:
        pf[m]=1
    return pf

#初期入力
N,M= (int(x) for x in input().split())
A= list(map(int, input().split()))

#ai<10**9 だから
ai_root =int(math.sqrt(10**9)) +1
sosu_list = list(sympy.primerange(2, ai_root))


y ={}
for i in A:
    x_dic =soinsu_bunkai(i,sosu_list) 
    for k,v in x_dic.items():
        if k not in y:
            y[k] = v
            if y[k] < v:
                y[k] = v
#半＿最小公倍数
han_saisyo_kobaisu =1
for i,v in y.items():
    han_saisyo_kobaisu *= i*v
han_saisyo_kobaisu //=2

#半公倍数の数( Mの中に半最小公倍数の数→偶数を削除のためさらに2で割る)
han_kobaisu_num =( M // han_saisyo_kobaisu +1 )//2
print(han_kobaisu_num)

### FIXED CODE ###


# 最小公倍数(mathは3.5以降) fractions
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
lcm         =lcm_list(A)
han_lcm     =lcm//2
han_lcm_num =M//han_lcm
han_lcm_num =(han_lcm_num +1)//2 #偶数を除く

#半公倍数がA自身の中にある時は✖
if han_lcm in A:
    han_lcm_num =0
#半公倍数がaiで割り切れるときは✖
for a in A:
    if han_lcm % a ==0:
        han_lcm_num =0
print(han_lcm_num)
S = raw_input()
length = len(S)

print '{0}{1}{2}'.format(S[0], length-2, S[length-1])


### FIXED CODE ###

S = raw_input()
length = len(S)

print '{0}{1}{2}'.format(S[0], length-2, S[length-1])
import numpy as np

N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

A = np.array(A)
B = np.array(B)

A = np.cumsum(A)
B = np.cumsum(B)

A1 = np.zeros((len(A),2))
A1[:,0] = A
A1[:,1] = np.arange(1,len(A)+1)

B1 = np.zeros((len(B),2))
B1[:,0] = B
B1[:,1] = np.arange(1,len(B)+1)

C1 = np.zeros((len(A)*len(B),2))
lenB = len(B)
for i in range(len(A)):
    for j in range(len(B)):
        C1[lenB*i+j,:] = A1[i,:] + B1[j,:]
C2 = np.array([[Cl[0],Cl[1]] for Cl in C1 if Cl[0] <= K])

if len(C2):
  print(int(C2[:,1].max()))
else:
  print(0)

### FIXED CODE ###

import numpy as np

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

A = np.array(A).cumsum()
B = np.array(B).cumsum()

ans = 0
j = M
for i in range(N+1):
    if A[i] > K:
        break
    while B[j] > K - A[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
N = int(input())
 
sum = 0
tmp = N
while tmp > 0:
  sum += tmp % 10
  tmp =// 10
if N % sum == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N = int(input())
 
sum = 0
tmp = N
while tmp > 0:
  sum += tmp % 10
  tmp //= 10
if N % sum == 0:
  print("Yes")
else:
  print("No")
a = int(input())
b = int(input())
c = a*b
if c%2 == 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
if a*b % 2 == 0 :
  print("Even")
else:
  print("Odd")
a = input()
s = input()
if a >= 3200:
  print s
else:
  print 'red'

### FIXED CODE ###

a = int(input())
s = str(input())
if a >= 3200:
  print(s)
else:
  print('red')
N = int(input())
A = list(map(int,input().split()))
summary = sum(A)
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
    
Q = int(input())
for _ in range(Q):
  B, C = list(map(int,input().split()))
  b = d[B]
  d[B] = 0
  if C in d:
    d[C] += b
  else:
    d[C] = b
  summary = summary + b * (C - B)
  print(summary)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
summary = sum(A)
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
    
Q = int(input())
for _ in range(Q):
  B, C = list(map(int,input().split()))
  if B not in d:
    b = 0
  else:
    b = d[B]
    d[B] = 0
  if C in d:
    d[C] += b
  else:
    d[C] = b
  summary = summary + b * (C - B)
  print(summary)
n, k = map( int, input().split() )
mod = 10 ** 9 + 7

numer = [ 1 ] * ( n + 1 )
demon = [ 1 ] * ( n + 1 )

for i in range( 1, n + 1 ):
  numer[ i + 1 ] = ( numer[ i ] * i ) % mod

demon[ n ] = pow( numer[ n ], mod - 2, mod )
for i in range( n, 0, -1 ):
  demon[ i - 1 ] = ( demon[ i ] * i ) % mod
  
def nCr( n, r ):
  if r < 1:
    return 0
  return ( numer[ n ] * demon[ r ] % mod ) * demon[ n - r ] % mod

ans = 0
for i in range( min( k, n - 1 ) + 1 ):
  ans = ( ans + nCr( n, i ) * nCr( n -1, i ) % mod
print( ans )


### FIXED CODE ###

n, k = map( int, input().split() )
mod = 10 ** 9 + 7
 
numer = [ 1 ] * ( n + 1 )
demon = [ 1 ] * ( n + 1 )
 
for i in range( 1, n + 1 ):
  numer[ i ] = numer[ i - 1 ] * i % mod

demon[ n ] = pow( numer[ n ], mod - 2, mod )
for i in range( n, 0, -1 ):
  demon[ i - 1 ] = ( demon[ i ] * i ) % mod

def nCr( n, r ):
  if r < 1:
    return 1
  return ( numer[ n ] * demon[ r ] % mod ) * demon[ n - r ] % mod
 
ans = 0
for i in range( min( k, n - 1) + 1 ):
  ans = ( ans + nCr( n, i ) * nCr( n - 1, i )) % mod
print( ans )
N,K = map(int,input().split())
A = list(map(int,input().split()))
pos = 0
visit = [0] * N
move = []
roop = []
while visit[pos]!=2:
    if visit[pos]==0:
        move.append(pos)
    else:
        roop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move)>K:
    print(move[K]+1)
else:
    print(roop[(K-(len(move)-len(roop)))%len(roop)]+1)

### FIXED CODE ###

# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

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

def main():
    n,k = readInt()
    a = readInt()
    pos = 0
    visit = [0] * n
    move = []
    roop = []
    while visit[pos]!=2:
        if visit[pos]==0:
            move.append(pos)
        else:
            roop.append(pos)
        visit[pos] += 1
        pos = a[pos] - 1
    num = 0
    if len(move)>k:
        print(move[k]+1)
    else:
        num = (k - (len(move)-len(roop))) % len(roop)
        print(roop[num]+1)
    return

if __name__=='__main__':
    main()
import sys

i = 0

while x != 0:
  x = sys.stdin.readline()
  i += 1

  print "Case %d: %d", %(i,x)
  

### FIXED CODE ###

i = 0
d = 0

while d == 0:
    x = input()
    if x != 0:
        i += 1
        print("Case %d: %d" %(i, x))
    else:
        d = 1
n, m=map(int, input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]

par=[i for i in range(n)]
cnt_con=[1 for i in range(n)]

def root(x):
    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
def connect(x,y):
    if root(x)==root(y):
        0
    else:
        cnt_con[root(y)]+=cnt_con[root(x)]
        par[root(x)]=root(y)      
    return

for i in range(m):
    a[i], b[i]=map(int, input().split())
    a[i], b[i]=a[i]-1, b[i]-1


tmp=int(n*(n-1)/2)
ans=[0]*m
ans[-1]=tmp
#ans[0]=0
#print('a,b=',a,b)
for i in range(m-1,-1,-1):
    ans[i]=tmp
    if root(a[i])==root(b[i]):
        0
    else:
        tmp-=cnt_con[root(a[i])]*cnt_con[root(b[i])]
    connect(a[i],b[i])
    #print('i,tmp',i,(a[i],b[i]),ans[i],tmp,par,cnt_con)
for i in range(m):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

n, m=map(int, input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]
g=[list() for i in range(1+n)]
#print(g)

par=[i for i in range(n)]
cnt_con=[1 for i in range(n)]

def root(x):
    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
def connect(x,y):
    #par[x]=root(x)
    #par[y]=root(y)
    if root(x)==root(y):
        0
    else:
        cnt_con[root(y)]+=cnt_con[root(x)]
        par[root(x)]=root(y)      
    return

for i in range(m):
    a[i], b[i]=map(int, input().split())
    a[i], b[i]=a[i]-1, b[i]-1


tmp=int(n*(n-1)/2)
ans=[0]*m
ans[-1]=tmp
#ans[0]=0
#print('a,b=',a,b)
for i in range(m-1,-1,-1):
    ans[i]=tmp
    if root(a[i])==root(b[i]):
        0
    else:
        tmp-=cnt_con[root(a[i])]*cnt_con[root(b[i])]
    connect(a[i],b[i])
    #print('i,tmp',i,(a[i],b[i]),ans[i],tmp,par,cnt_con)
    

    
for i in range(m):
    print(ans[i])
n, a, b, c = list(map(int, input().split()))
ss = []
for i in range(n):
    ss.append(input())
ans = []
num_dic = {"A": a,"B": b, "C": c}

for i in range(n):
    s = ss[i]
    if num_dic[s[0]] == 0 and num_dic[s[1]] == 0:
        print("No")
        exit()
    elif num_dic[s[0]] > num_dic[s[1]]:
        num_dic[s[0]] -= 1
        num_dic[s[1]] += 1
        ans.append(s[0])
    elif num_dic[s[0]] > num_dic[s[1]]:
        num_dic[s[0]] -= 1
        num_dic[s[1]] += 1
        ans.append(s[1])
    elif i == n -1:
        ans.append(s[0])
    elif s[0] in s[i+1]:
        num_dic[s[0]] += 1
        num_dic[s[1]] -= 1
        ans.append(s[0])
    else:
        num_dic[s[0]] -= 1
        num_dic[s[1]] += 1
        ans.append(s[1])
for a in ans:
    print(a)


### FIXED CODE ###

n, a, b, c = list(map(int, input().split()))
ss = []
for i in range(n):
    ss.append(input())
ans = []
num_dic = {"A": a,"B": b, "C": c}

for i in range(n):
    s = ss[i]
    if num_dic[s[0]] == 0 and num_dic[s[1]] == 0:
        print("No")
        exit()
    elif num_dic[s[0]] > num_dic[s[1]]:
        num_dic[s[0]] -= 1
        num_dic[s[1]] += 1
        ans.append(s[1])
    elif num_dic[s[0]] < num_dic[s[1]]:
        num_dic[s[0]] += 1
        num_dic[s[1]] -= 1
        ans.append(s[0])
    elif i == n -1:
        ans.append(s[0])
        num_dic[s[0]] -= 1
        num_dic[s[1]] += 1
    elif s[0] in ss[i+1]:
        num_dic[s[0]] += 1
        num_dic[s[1]] -= 1
        ans.append(s[0])
    else:
        num_dic[s[0]] -= 1
        num_dic[s[1]] += 1
        ans.append(s[1])
print("Yes")
for a in ans:
    print(a)
# coding: utf-8
n = int(input())
lst = list(map(int, input().split()))
cnt = 0
data = []
for i in range(n - 1):
    if lst[i] >= lst[i + 1]:
        cnt += 1
    else:
        data.append(cnt)
        cnt = 0
print(max(cnt))


### FIXED CODE ###

# coding: utf-8
n = int(input())
lst = list(map(int, input().split()))
cnt = 0
data = []
for i in range(n - 1):
    if lst[i] >= lst[i + 1]:
        cnt += 1
    else:
        data.append(cnt)
        cnt = 0
data.append(cnt)
print(max(data))
n=int(input())
x=1
for i in range(1,n+1):
    x*=i

res=1

for i in range(2,n+1):
    cnt=1
    while x%i==0:
        x=x/i
        cnt+=1
    res*=cnt
    
print(res)
    

### FIXED CODE ###

n=int(input())
x=1
for i in range(1,n+1):
    x*=i

res=1

for i in range(2,n+1):
    cnt=1
    while x%i==0:
        x=x//i
        cnt+=1
    res*=cnt
    
print(res%(10**9+7))
import math
import fractions
def isprime(number):
    for i in range(2, round(math.sqrt(number)) + 1):
        if number % i == 0:
            return False
    return True

A, B = map(int, input().split())
count = 1
N = fractions.gcd(A, B)

for i in range(2, N + 1):
  	if i != 2 and i % 2 == 0:
        continue
    if N % i == 0:
        if isprime(i):
            count += 1

print(str(count))


### FIXED CODE ###

from fractions import gcd
def f(n):
    tmp = n
    cnt = 0
    i = 2
    while i <= n**0.5 + 1:
        if tmp < i:
            break
        if tmp % i == 0:
            cnt += 1
            while tmp % i == 0:
                tmp //= i
        i += 1
    if tmp != 1:
        cnt += 1
    return cnt

A, B = map(int, input().split())
g = gcd(A, B)
ans = f(g) + 1
print(ans)
t = [int(input()) for i in range(5)]
t1 = 0
t2 = []
for a in t:
  if a % 10 == 0:
    t1 += a
  else:  
    t1 += (a//10 + 1)*10
    t2.append(a % 10)
print(t1 + min(t2) - 10)

### FIXED CODE ###

t = [int(input()) for i in range(5)]
t1 = 0
t2 = []
for a in t:
  if a % 10 == 0:
    t1 += a
  else:  
    t1 += (a//10 + 1)*10
    t2.append(a % 10)
if t2 == []:
  print(t1)
else:
  print(t1 + min(t2) - 10)