Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03241 (python)

Fixed submission:
# import bisect
n,m=map(int,input().split())

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

div=make_divisors(m)
ans=1
for i in range(len(div)):
    if(div[i]>m/n):
        break
    ans=max(div[i],ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n,m=map(int,input().split())
def enum_dif(n):
    ret=[]
    i=1
    while i*i<=n:
        if(n%i==0):
            ret.append(i);
            if(i!=1 and i*i != n):
                ret.append(n//i)
        i+=1
    return ret
enum=enum_dif(m)
enum.sort()
# print(enum)
ind=bisect.bisect_left(enum,m//n)
if(enum[ind]==m//n):
    print(enum[ind])
elif(ind==0):
    print(enum[ind])
else:
    print(enum[ind-1])

Buggy submission (verdict: Runtime Error):
import bisect
n,m=map(int,input().split())
def enum_dif(n):
    ret=[]
    i=1
    while i*i<=n:
        if(n%i==0):
            ret.append(i);
            if(i!=1 and i*i != n):
                ret.append(n//i)
        i+=1
    return ret
enum=enum_dif(m)
enum.sort()
# print(enum)
ind=bisect.bisect_left(enum,m//n)
if(enum[ind]==m//n):
    print(enum[ind])
else:
    print(enum[ind-1])
Problem p03262 (python)

Fixed submission:
import itertools as it
import collections as col
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,x=map(int,input().split())
P=list(map(int,input().split()))

if(n==1):
    print(abs(P[0]-x))
    exit(0)

P.sort()
D=[0]
for i in range(n):
    D.append(abs(P[i]-x))
print(gcd_list(D))

Buggy submission (verdict: Runtime Error):
import itertools as it
import collections as col
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


n,x=map(int,input().split())
P=list(map(int,input().split()))
if(n==1):
    print(abs(P[0]-x))
    exit(0)
P.sort()
if(x<=P[0]):
    P.insert(0,x)
elif(x>=P[n-1]):
    P.append(x)
else:
    for i in range(1,n):
        if(P[i-1]<=x and x<=P[i]):
            P.insert(i,x)
D=[0]
for i in range(1,n):
    D.append(P[i]-P[i-1])
print(gcd_list(D))
Problem p02999 (python)

Fixed submission:
x,a = input().split()
x = int(x)
a = int(a)
if(x<a):
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
aList = input().split()
aList = [int(i) for i in aList]
cn=0

for i in range(len(aList)):
  for j in range(len(aList[i:])):
    jj = len(aList)-j
    if(i==jj):
       break
    if(sum(aList[i:jj]) >= k):
      cn+=1
    else:
      break;
print(cn)
Problem p02553 (python)

Fixed submission:
a, b, c, d = [int(t) for t in input().split()]
print(max([b*d, a*c, a*d, b*c]))

Buggy submission (verdict: Runtime Error):
a, b, c, d = [int(t) for t in input()]
print(max([b*d, a*c, a*d, b*d]))

Buggy submission (verdict: Runtime Error):
a, b, c, d = [int(t) for t in input(t)]
print(max([b*d, a*c, a*d, b*d]))
Problem p03481 (python)

Fixed submission:
x,y=map(int,input().split())
ans=0
while x<=y:
    x = x*2
    ans +=1
print(ans)

Buggy submission (verdict: Runtime Error):
def getAns(x,y):
    num=int(y/x)
    res=1
    while num>1:
        num/=2
        res+=1
    return res

x,y=map(int,input().split())
print getAns(x,y)
Problem p02553 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
print(max(a*c, max(a*d, max(b*c, b*d))))

Buggy submission (verdict: Runtime Error):
a, b, c, d = int(map(int, input().split()))
print(max(a*c, max(a*d, max(b*c, b*d))))
Problem p02706 (python)

Fixed submission:
import numpy as np
import math

n, m = map(int, input().split())
A = list(map(int, input().split()))

a = sum(A)

if n < a:
    print(-1)
else:
    print(n - a)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

homework = A.sum()
print(n - m if n - m >= 0 else -1)
Problem p02783 (python)

Fixed submission:
h, a = map(int, input().split())

ans = 0
while h > 0:
    h -= a
    ans+=1

print(ans)

Buggy submission (verdict: Runtime Error):
h, a = map(int, input().split())

 index = 0
 while h > 0:
     h -= a
     index += 1

print(index)
Problem p02789 (python)

Fixed submission:
n, m = map(int, input().split())

if n == m:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input())

if n == m:
    print("Yes")
else:
    print("No")
Problem p02807 (python)

Fixed submission:
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split())))
L = np.cumsum(np.array([1 / x for x in range(1, n)]))
n_1 = factorial(n-1) % MOD

# fac = [1] * n
# for i in range(1,n):
# 	fac[i] = fac[i-1] * i % MOD

# print(int(np.sum(L * dist * n_1)) % MOD)
# ans = 0
# for l, d in zip(L, dist):
#     print("l d ", l * d)
#     ans += l * d
#     ans %= MOD

ans = 0
tmp = 0
for i, d in enumerate(dist):
    tmp += pow(i+1, MOD-2, MOD)
    ans += tmp * d
    ans %= MOD

# print(n_1)
print(ans * n_1 % MOD)
# print(int(np.sum(dist * L * n_1) % MOD))

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split())))
L = np.cumsum(np.array([1 / x for x in range(1, n)]))
n_1 = factorial(n-1) 
 
print(int(np.sum(L * dist * n_1)) % MOD)

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())
dist = np.diff(list(map(int, input().split())))

L = np.cumsum(np.array([1 / x for x in range(1, n)]))
n_1 = factorial(n-1)
# L *= n_1

# print(int((np.sum(L * dist) * n_1) % MOD))

ans = 0
for l, d in zip(L, dist):
    ans += l * d % MOD

ans = (ans * n_1 % MOD)
print(int(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())
X = list(map(int, input().split()))
dist = np.diff(X)

L = np.array([1 / x for x in range(1, n)])

L = np.cumsum(L)
n_1 = factorial(n-1)
L *= n_1

print(int(np.sum(L * dist) % MOD))
Problem p02911 (python)

Fixed submission:
import sys 

N, K, Q = map(int, sys.stdin.readline().split())
A = (int(i) for i in sys.stdin.read().split())

l = [K - Q] * N
for i in A:
    l[i - 1] += 1

for i in range(N):
    if l[i] > 0:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import sys 

N, K, Q = map(int, sys.stdin.readline().split())
A = (int(i) for i in sys.stdin.read().split())

l = [K - Q] * N
for i in range(Q):
    l[A[i] - 1] += 1

for i in range(Q):
    if l[i] >= 0:
        print("Yes")
    else:
        print("No")
Problem p03251 (python)

Fixed submission:
N,M,X,Y = map(int,input().split())
x = max(X,max(list(map(int,input().split()))))
y = min(Y,min(list(map(int,input().split()))))
 
if y>x:
  print("No War")
else:
  print("War")

Buggy submission (verdict: Runtime Error):
import sys

n,m,x,y = map(int, sys.stdin.readline().split())
x_list = list(map(int, sys.stdin.readline().split()))
y_list = list(map(int, sys.stdin.readline().split()))

x_max = max(x_list.append(x))
y_min = min(y_list.append(y))

if x < y:
    print("No War")
else:
    print("War")

Buggy submission (verdict: Runtime Error):
import sys

n,m,x,y = map(int, sys.stdin.readline().split())
x_list = list(map(int, sys.stdin.readline().split()))
y_list = list(map(int, sys.stdin.readline().split()))

x_max = max(x_list.append(x))
y_min = min(y_list.append(y))

if x < y
    print("No War")
else:
    print("War")

Buggy submission (verdict: Runtime Error):
import sys

n,m,x,y = map(int, sys.stdin.readline().split())
x_list = list(map(int, sys.stdin.readline().split()))
y_list = list(map(int, sys.stdin.readline().split()))

x_max = max(x_list)
y_min = min(y_list)

if y_min <= x_max
    print("War")
else:
    print("No War")
Problem p03261 (python)

Fixed submission:
n = int(input())

l = [input() for _ in range(n)]

count = len(set(l))
flag = True
for i in range(len(l) -1 ):
    if l[i][len(l[i]) -1] != l[i+1][0]:
        flag = False
        break

if flag and count == n:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())

l = [input() for _ in range(4)]

count = len(set(l))
flag = True
for i in range(len(l) -1 ):
    if l[i][len(l[i]) -1] != l[i+1][0]:
        flag = False
        break

if flag and count == n:
    print("Yes")
else:
    print("No")
Problem p03264 (python)

Fixed submission:
n = int(input())

if n % 2 == 0:
    print(int((n / 2) ** 2))
else:
    print(int(((n+1)/2) * (n-1)/2))

Buggy submission (verdict: Runtime Error):
n = int(input())

if n % 2 == 0:
    print((n / 2) ** 2)
else
    print(((n+1)/2) * (n-1)/2)
Problem p03294 (python)

Fixed submission:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))

ans = (A-1).sum()
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
A = list(map(int, input().split()))

lcm = np.lcm.reduce(A)
ans = ((lcm - 1) % A).sum()
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
A = list(map(int, input().split()))

print(A)
lcm = np.lcm.reduce(A)
ans = ((lcm - 1) % A).sum()
print(ans)
Problem p03316 (python)

Fixed submission:
n = input()
sum = 0
for i in range(len(n)):
    sum += int(n[i])

if int(n) % sum == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
sum = 0
for i in range(len(n)):
    sum += int(n[i])

if n % sum == 0:
    print("Yes")
else:
    print("No")
Problem p03323 (python)

Fixed submission:
import sys

a, b = map(int, sys.stdin.readline().split())

if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
import sys

a, b = map(int, sys.stdin.readline().split()))

if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
import sys

a, b = map(int, sys.stdin.readline())

if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(":(")
Problem p03399 (python)

Fixed submission:
import sys

a, b, c, d = [int(input()) for _ in range(4)]

print(min(a,b) + min(c,d))

Buggy submission (verdict: Runtime Error):
import sys

a, b, c, d = map(int, sys.stdin.readline().split())
print(min(a,b) + min(c,d))
Problem p03547 (python)

Fixed submission:
import sys

x, y = map(str, sys.stdin.readline().split())

if ord(x) < ord(y):
    print("<")
elif ord(x) > ord(y):
    print(">")
else:
    print("=")

Buggy submission (verdict: Runtime Error):
import sys

x, y = map(int, sys.stdin.readline().split())

if ord(x) < ord(y):
    print("<")
elif ord(x) > ord(y):
    print(">")
else:
    print("=")
Problem p03814 (python)

Fixed submission:
s = input()
print(len(s) - s[::-1].find("Z") - s.find("A"))

Buggy submission (verdict: Runtime Error):
s = input()
print(s.rfind("Z") - s.fine("A") + 1)
Problem p03944 (python)

Fixed submission:
import sys
w,h,n = map(int, sys.stdin.readline().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)

if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

Buggy submission (verdict: Runtime Error):
import sys
w,h,n = map(int, sys.stdin.readline().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = mix(y, y_max)

print(x_min, x_max, y_min, y_max)
if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))
Problem p03998 (python)

Fixed submission:
s = dict()
s["a"] = list(input())[::-1]
s["b"] = list(input())[::-1]
s["c"] = list(input())[::-1]

index = s["a"].pop()

while s[index]:
    index = s[index].pop()

print(index.upper())

Buggy submission (verdict: Runtime Error):
s = dict()
s["a"] = list(input())[::-1]
s["b"] = list(input())[::-1]
s["c"] = list(input())[::-1]

index = s.pop()

while s[index]:
    index = s.pop()

print(index.upper())
Problem p04012 (python)

Fixed submission:
from collections import Counter
w = input()

c = Counter(w)

flag = True

for i in c.values():
    if i % 2 == 1:
        flag = False
        break

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

Buggy submission (verdict: Runtime Error):
from collections import Counter
w = input()

c = Counter(l)

flag = True

for i in c.values():
    if i % 2 == 1:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")
Problem p04043 (python)

Fixed submission:
a, b, c = map(int, input().split())
iroha = [a, b, c]
if iroha.count(5) == 2 and iroha.count(7) == 1:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a=5, b=5, c=7:
  print("Yes")
elif a=5, b=7, c=5:
  print("Yes")
elif a=7, b=5, c=5:
  print("Yes")
else:
  print("No")
Problem p02616 (python)

Fixed submission:
def get_neg(neg_list, k, mod):
    ans = 1
    neg_list.sort(reverse=True)
    for num in neg_list[:k]:
        ans = ans * num % mod
    return ans


def get_pos(pos_list, neg_list, k, mod):
    ans = 1
    nums = []
    neg_iter = iter(sorted(neg_list))
    pos_iter = iter(sorted(pos_list, reverse=True))
    if k % 2 == 1:
        ans *= pos_iter.__next__()
        k -= 1
        
    for a, b in zip(pos_iter, pos_iter):
        nums.append(a * b)

    for a, b in zip(neg_iter, neg_iter):
        nums.append(a * b)

    nums.sort(reverse=True)
    for num in nums[:k//2]:
        ans *= num
        ans %= mod
    return ans


def get_all(num_list, mod):
    ans = 1
    for num in num_list:
        ans = ans * num % mod
    return ans


def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    
    if n == k:
        ans = get_all(A, mod)
        print(ans)
        return
    
    pos_list = []
    neg_list = []

    for a in A:
        if a >= 0:
            pos_list.append(a)
        else:
            neg_list.append(a)

    if k % 2 and not pos_list:
        ans = get_neg(neg_list, k, mod)
    else:
        ans = get_pos(pos_list, neg_list, k, mod)

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush


n, k = map(int, input().split())
A = list(map(int, input().split()))
B = []

mod = 10 ** 9 + 7

for a in A:
    num = a
    sign = True
    if a < 0:
        sign = False
        num *= -1

    heappush(B, (-num, sign))

candidate = []
neg_stock = False
keep_neg = 0
count = 0
ans = 1
pos_stock = False

while B and count < k:
    num, sign = heappop(B)
    num *= -1
    if not sign:
        if neg_stock:
            if count == k-1:
                continue
            neg_stock = 0
            ans = ans * num * keep_neg % mod
            count += 2

        else:
            neg_stock += 1
            keep_neg = num

    else:
        if count > k-2:
            ans = ans * num % mod
            count += 1

        else:
            if pos_stock:
                candidate.append(pos_stock*num)
                count -= 1

            else:
                pos_stock = num
                count -= 1

if neg_stock:
    if candidate:
        B.sort()
        if B[0] < 0:
            if neg_stock * -B[0] > candidate[0]:
                ans = ans * neg_stock * -B[0] % mod

    else:
        A.sort(key=lambda x: abs(x))
        ans = 1
        for i in range(k):
            ans = ans * A[i] % mod

print(ans % mod)
Problem p02632 (python)

Fixed submission:
mod = 10 ** 9 + 7

SIZE = 2 * 10 ** 6 + 5
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


k = int(input())
S = input()
s_length = len(S)
full_length = len(S) + k
ans = 0
for i in range(k+1):
    add = pow(26, i, mod) * pow(25, k-i, mod) * nCr(full_length-i-1, s_length-1) % mod
    ans = (ans + add) % mod

print(ans)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7

SIZE = 10 ** 6 + 1
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


k = int(input())
S = input()
s_length = len(S)
full_length = len(S) + k
ans = 0
for i in range(k+1):
    add = pow(26, i, mod) * pow(25, k-i, mod) * nCr(full_length-i-1, s_length-1) % mod
    ans = (ans + add) % mod

print(ans)
Problem p02641 (python)

Fixed submission:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
    
P = set(map(int, input().split()))

d_min = 1000
ans = 1000
for num in range(-1, 102):
    if num in P:
        continue
    
    d = abs(x-num)
    if d < d_min:
        d_min = d
        ans = num

print(ans)

Buggy submission (verdict: Runtime Error):
IN = iter(Input.split('\n')).__next__
def input():
    return IN()

###################################################

x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
P = set(map(int, input().split()))

d_min = 1000
ans = 1000
for num in range(-1, 102):
    if num in P:
        continue
    
    d = abs(x-num)
    if d < d_min:
        d_min = d
        ans = num

print(ans)
Problem p02642 (python)

Fixed submission:
import numpy as np
from collections import Counter


n = int(input())
A = list(map(int, input().split()))
A.sort()
is_divisible = np.zeros(10**6+1, dtype=np.int64)


def update(num):
    nums = np.arange(num, 10**6+1, num)
    is_divisible[nums] = True

counter = Counter(A)
ans = 0
for a, count in counter.items():
    if count == 1 and not is_divisible[a]:
        ans += 1
        
    update(a)

print(ans)

Buggy submission (verdict: Runtime Error):
IN = iter(Input.split('\n')).__next__
def input():
    return IN()

###################################################
from collections import defaultdict


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


def divisor(n):
    div_list = []
    limit = int(n**0.5) + 1
    for div in range(1, limit):
        if n % div == 0:
            div2 = n // div
            div_list.append(div)
            if div != div2:
                div_list.append(div2)
    
    return div_list


        
A_dict = defaultdict(int)
for a in A:
    A_dict[a] += 1

    
ans = n
for a in A:
    divs = divisor(a)
    for div in divs:
        if div == a:
            
            if A_dict[div] >= 2:
                ans -= 1
                break
        else:
            if A_dict[div] >= 1:
                ans -= 1
                break
            

print(ans)
Problem p02647 (python)

Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))


def query(lamps):
    start_list = []
    end_list = []
    for idx, power in enumerate(lamps):
        start, end = idx - power, idx + power
        start_list.append(start)
        end_list.append(end)

    start_list.sort(reverse=True)
    end_list.sort(reverse=True)

    now = 0
    for idx in range(n):
        while start_list and start_list[-1] <= idx:
            start_list.pop()
            now += 1

        while end_list and end_list[-1] < idx:
            end_list.pop()
            now -= 1

        lamps[idx] = now


def full_check(counts, full):
    for count in counts:
        if count == full:
            continue
        else:
            return False

    return True


for _ in range(k):
    query(A)
    if full_check(A, n):
        break

print(*A)

Buggy submission (verdict: Runtime Error):
from numba import njit


n, k = map(int, input().split())
A = list(map(int, input().split()))


@njit('(i8[::1],)', cache=True)
def query(lamps):
    counts = [0] * n
    for idx, power in enumerate(lamps):
        start, end = idx - power, idx + power
        if start < 0:
            start = 0
        counts[start] += 1

        if end >= n-1:
            continue
        counts[end+1] -= 1

    now = 0
    for idx, count in enumerate(counts):
        now += count
        lamps[idx] = now


def full_check(counts, full):
    for count in counts:
        if count == full:
            continue
        else:
            return False

    return True


for _ in range(k):
    query(A)
    if full_check(A, n):
        break

print(*A)
Problem p02662 (python)

Fixed submission:
import numpy as np

mod = 998244353

n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)

for num, a in enumerate(A):
    double = DP * 2
    shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
    DP = double + shift
    DP[a] += pow(2, num, mod)
    DP %= mod

print(DP[s])

Buggy submission (verdict: Runtime Error):
import numpy as np

n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3001, dtype=np.int64)

for num, a in enumerate(A):
    double = DP * 2
    shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
    DP = double + shift
    DP[a] += 2 ** num

print(DP[s])
Problem p02692 (python)

Fixed submission:
import sys
input = sys.stdin.readline

n, a, b, c = map(int, input().split())
count = {
    'A': a,
    'B': b,
    'C': c
}
queries = []
for _ in range(n):
    query = tuple(input().replace('\n', ''))
    queries.append(query)


def solve(plus, minus):
    count[plus] += 1
    count[minus] -= 1
    ans.append(plus)


ans = []
for idx, (x, y) in enumerate(queries):
    if count[x] == count[y] == 0:
        print('No')
        exit()

    if count[x] == count[y] == 1:
        if idx == n-1:
            solve(x, y)
            break

        nex = queries[idx+1]
        if x in nex:
            solve(x, y)
        else:
            solve(y, x)

    elif count[x] >= count[y]:
        solve(y, x)

    else:
        solve(x, y)

print('Yes')
for c in ans:
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, a, b, c = map(int, input().split())
count = {
    'A': a,
    'B': b,
    'C': c
}
queries = []
for _ in range(n):
    query = tuple(input())
    queries.append(query)


def solve(plus, minus):
    count[plus] += 1
    count[minus] += 1
    ans.append(plus)


ans = []
for idx, (x, y) in enumerate(queries):
    if count[x] == count[y] == 0:
        print('No')
        exit()

    if count[x] == count[y] == 1:
        if idx == n-1:
            solve(x, y)
            break

        nex = queries[idx+1]
        if x in nex:
            solve(x, y)
        else:
            solve(y, x)
    
    elif count[x] >= count[y]:
        solve(x, y)
        
    else:
        solve(y, x)

print('Yes')
for c in ans:
    print(c)