The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.

During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him.

Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size:   the size he wanted, if he specified one size;  any of the two neibouring sizes, if he specified two sizes. 

If it is possible, the program should find any valid distribution of the t-shirts.


-----Input-----

The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000.

The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants.

The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring.


-----Output-----

If it is not possible to present a t-shirt to each participant, print «NO» (without quotes).

Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input.

If there are multiple solutions, print any of them.


-----Examples-----
Input
0 1 0 1 1 0
3
XL
S,M
XL,XXL

Output
YES
XL
M
XXL

Input
1 1 2 0 1 1
5
S
M
S,M
XXL,XXXL
XL,XXL

Output
NO

Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Flows and cuts

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
def distribution(available, wish):
	double_keys = ['S,M', 'M,L', 'L,XL', 'XL,XXL', 'XXL,XXXL']
	double = {key: [] for key in double_keys}
	people = [''] * len(wish)
	for (i, w) in enumerate(wish):
		if w.count(',') == 0:
			if available[w] > 0:
				available[w] -= 1
				people[i] = w
			else:
				return ['NO']
		else:
			double[w].append(i)
	for key in double_keys:
		for p in double[key]:
			lack = True
			for size in key.split(','):
				if available[size] > 0:
					available[size] -= 1
					people[p] = size
					lack = False
					break
			if lack:
				return ['NO']
	return ['YES', people]

def stock():
	return {size: amount for (size, amount) in zip(['S', 'M', 'L', 'XL', 'XXL', 'XXXL'], map(int, input().split()))}

def request():
	return [input() for i in range(int(input()))]

def solution(n):
	return [input() for i in range(n)]

def answer():
	ans = distribution(stock(), request())
	if ans[0] == 'YES':
		print('YES')
		for p in ans[1]:
			print(p)
	else:
		print('NO')

def check(s, l):
	for size in l:
		if size not in s:
			return False
		else:
			s[size] -= 1
			if s[size] < 0:
				return False
	return True

def compare():
	s = stock()
	r = request()
	ans = distribution(s.copy(), r)
	try:
		usr = input()
		if usr == 'YES':
			l = solution(len(r))
		elif usr == 'NO':
			l = []
		else:
			print(0)
			print('Нарушен формат вывода')
			exit(0)
	except EOFError:
		print(0)
		print('Нарушен формат вывода')
		exit(0)
	if usr != ans[0] or (ans[0] == 'YES' and (not check(s.copy(), l))):
		print(0)
		print('Failed. T-shirts:', s, '. Request:', ';'.join(r), '. Your solution:', usr, ' - ', ';'.join(l))
	else:
		print(1)
		print('Ok')
answer()


def alphabet_replace_size(x):
	return x.replace('XXXL', 'F').replace('XXL', 'E').replace('XL', 'D').replace('L', 'C').replace('M', 'B').replace('S', 'A')

def not_alphabet_replace_size(x):
	return x.replace('F', 'XXXL').replace('E', 'XXL').replace('D', 'XL').replace('C', 'L').replace('B', 'M').replace('A', 'S')
_sizes = ['A', 'B', 'C', 'D', 'E', 'F']
cnt_tshirts = input()
n = int(input())
sizes = []
for i in range(n):
	sizes.append(input())
cnt_tshirts = list(map(lambda x: int(x), cnt_tshirts.split()))
cnt_tshirts = dict(zip(_sizes, cnt_tshirts))
result = [-1] * n
tmp1 = []
for i in range(n):
	tmp1.append(i)
sizes = list(map(alphabet_replace_size, sizes))
tmp2 = dict(zip(tmp1, sizes))
flag = True
for (key, value) in sorted(tmp2.items(), key=lambda k: k[1]):
	if value.find(',') == -1:
		if cnt_tshirts[value] == 0:
			flag = False
			break
		cnt_tshirts[value] -= 1
		result[key] = value
if flag:
	for (key, value) in sorted(tmp2.items(), key=lambda k: k[1]):
		if value.find(',') != -1:
			tmp3 = value.split(',')
			if cnt_tshirts[tmp3[0]] != 0:
				cnt_tshirts[tmp3[0]] -= 1
				result[key] = tmp3[0]
			elif cnt_tshirts[tmp3[1]] != 0:
				cnt_tshirts[tmp3[1]] -= 1
				result[key] = tmp3[1]
			else:
				flag = False
				break
if flag:
	print('YES')
	print('\n'.join(list(map(not_alphabet_replace_size, result))))
else:
	print('NO')


TShirts = list(map(int, input().split()))
NPers = int(input())
Needs = [0, 0, 0, 0, 0]
T = [0 for i in range(10)]
Pers = []
IsFound = True
if sum(TShirts) < NPers:
	IsFound = False
for i in range(NPers):
	s = input().split(',')
	Pers.append(0)
	if 'S' in s:
		Pers[-1] += 1
	if 'M' in s:
		Pers[-1] += 2
	if 'L' in s:
		Pers[-1] += 4
	if 'XL' in s:
		Pers[-1] += 8
	if 'XXL' in s:
		Pers[-1] += 16
	if 'XXXL' in s:
		Pers[-1] += 32
for i in Pers:
	if i == 1:
		TShirts[0] -= 1
	elif i == 2:
		TShirts[1] -= 1
	elif i == 4:
		TShirts[2] -= 1
	elif i == 8:
		TShirts[3] -= 1
	elif i == 16:
		TShirts[4] -= 1
	elif i == 32:
		TShirts[5] -= 1
for i in TShirts:
	if i < 0 and IsFound:
		IsFound = False
for i in Pers:
	if i & 1 != 0 and i & 2 != 0:
		Needs[0] += 1
	elif i & 2 != 0 and i & 4 != 0:
		Needs[1] += 1
	elif i & 4 != 0 and i & 8 != 0:
		Needs[2] += 1
	elif i & 8 != 0 and i & 16 != 0:
		Needs[3] += 1
	elif i & 16 != 0 and i & 32 != 0:
		Needs[4] += 1
for i in range(5):
	while Needs[i] > 0 and TShirts[i] > 0:
		Needs[i] -= 1
		TShirts[i] -= 1
		T[2 * i] += 1
	while Needs[i] > 0 and TShirts[i + 1] > 0:
		Needs[i] -= 1
		TShirts[i + 1] -= 1
		T[2 * i + 1] += 1
if sum(Needs) > 0:
	IsFound = False
if IsFound:
	print('YES')
	for i in range(len(Pers)):
		if T[0] > 0 and Pers[i] == 3:
			Pers[i] -= Pers[i] - 1
			T[0] -= 1
		elif T[1] > 0 and Pers[i] == 3:
			Pers[i] -= Pers[i] - 2
			T[1] -= 1
	for i in range(len(Pers)):
		if T[2] > 0 and Pers[i] == 6:
			Pers[i] -= Pers[i] - 2
			T[2] -= 1
		elif T[3] > 0 and Pers[i] == 6:
			Pers[i] -= Pers[i] - 4
			T[3] -= 1
	for i in range(len(Pers)):
		if T[4] > 0 and Pers[i] == 12:
			Pers[i] -= Pers[i] - 4
			T[4] -= 1
		elif T[5] > 0 and Pers[i] == 12:
			Pers[i] -= Pers[i] - 8
			T[5] -= 1
	for i in range(len(Pers)):
		if T[6] > 0 and Pers[i] == 24:
			Pers[i] -= Pers[i] - 8
			T[6] -= 1
		elif T[7] > 0 and Pers[i] == 24:
			Pers[i] -= Pers[i] - 16
			T[7] -= 1
	for i in range(len(Pers)):
		if T[8] > 0 and Pers[i] == 48:
			Pers[i] -= Pers[i] - 16
			T[8] -= 1
		elif T[9] > 0 and Pers[i] == 48:
			Pers[i] -= Pers[i] - 32
			T[9] -= 1
	for i in Pers:
		if i & 1:
			print('S')
		elif i & 2:
			print('M')
		elif i & 4:
			print('L')
		elif i & 8:
			print('XL')
		elif i & 16:
			print('XXL')
		elif i & 32:
			print('XXXL')
else:
	print('NO')


maksochnik = list(map(int, input().split()))
dicter = {'S': maksochnik[0], 'M': maksochnik[1], 'L': maksochnik[2], 'XL': maksochnik[3], 'XXL': maksochnik[4], 'XXXL': maksochnik[5]}
x = {'S,M': [], 'M,L': [], 'L,XL': [], 'XL,XXL': [], 'XXL,XXXL': []}
m = int(input())
ans = ['0'] * m
for i in range(m):
	ras = input()
	if ',' not in ras:
		if dicter[ras] <= 0:
			print('NO')
			exit(0)
		else:
			dicter[ras] -= 1
			ans[i] = ras
	else:
		x[ras].append(i)
for (v, p) in x.items():
	(q, w) = v.split(',')
	for j in range(len(p)):
		if dicter[q] > 0:
			dicter[q] -= 1
			ans[p[j]] = q
		elif dicter[w] > 0:
			dicter[w] -= 1
			ans[p[j]] = w
		else:
			print('NO')
			exit(0)
print('YES')
for h in range(len(ans)):
	print(ans[h])


d = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
cnt = [int(t) for t in input().split()]
n = int(input())
ind = [i for i in range(n)]
p = []
for i in range(n):
	p.append(input().split(','))
ind.sort(key=lambda x: [d[p[x][0]], len(p[x])])
ans = {}
for i in ind:
	cur = p[i]
	if cnt[d[cur[0]]] != 0:
		ans[i] = cur[0]
		cnt[d[cur[0]]] -= 1
	elif len(cur) == 2 and cnt[d[cur[1]]] != 0:
		ans[i] = cur[1]
		cnt[d[cur[1]]] -= 1
	else:
		print('NO')
		exit()
print('YES')
for i in ans.keys():
	print(ans[i])


from collections import defaultdict
dist = list(map(int, input().split()))
a = [0] * 11
indexes = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5, 'S,M': 6, 'M,L': 7, 'L,XL': 8, 'XL,XXL': 9, 'XXL,XXXL': 10}
inv = dict(list(zip(list(indexes.values()), list(indexes.keys()))))
n = int(input())
par_d = defaultdict(list)
par = [None] * n
for i in range(n):
	ind = indexes[input().strip()]
	if ind <= 5:
		dist[ind] -= 1
		par[i] = ind
	else:
		par_d[ind].append(i)
	a[ind] += 1
if min(dist) < 0:
	print('NO')
	return
k = 0
k_p = []
for i in range(6, 11):
	size = i - 6
	dist[size] -= k
	if dist[size] < 0:
		print('NO')
		return
	else:
		for j in k_p:
			par[j] = size
	m = len(par_d[i])
	if dist[size] + dist[size + 1] < m:
		print('NO')
		return
	if dist[size] <= m:
		p = par_d[i][:dist[size]]
		k_p = par_d[i][dist[size]:]
		k = m - dist[size]
		for j in p:
			par[j] = size
		dist[size] = 0
	else:
		p = par_d[i]
		k_p = []
		k = 0
		for j in p:
			par[j] = size
if k > dist[-1]:
	print('NO')
	return
else:
	for j in k_p:
		par[j] = 5
print('YES')
for i in range(n):
	print(inv[par[i]])


3
szs = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
d = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
neigh = [[] for i in range(5)]
of = list(map(int, input().split()))
n = int(input())
ans = ['' for i in range(n)]
for i in range(n):
	t = input()
	if ',' in t:
		neigh[d[t.split(',')[0]]].append(i)
	else:
		of[d[t]] -= 1
		ans[i] = t
for i in range(6):
	if of[i] < 0:
		print('NO')
		return
	if i > 0:
		while len(neigh[i - 1]) and of[i] > 0:
			ans[neigh[i - 1][-1]] = szs[i]
			neigh[i - 1].pop()
			of[i] -= 1
	if i < 5:
		while len(neigh[i]) and of[i] > 0:
			ans[neigh[i][-1]] = szs[i]
			neigh[i].pop()
			of[i] -= 1
if sum([len(neigh[i]) for i in range(5)]) != 0:
	print('NO')
else:
	print('YES')
	print('\n'.join(ans))


from math import *
from sys import *

def conv(s):
	if s == 'S' or s == 'S\n':
		return 1
	if s == 'M' or s == 'M\n':
		return 2
	if s == 'L' or s == 'L\n':
		return 3
	if s == 'XL' or s == 'XL\n':
		return 4
	if s == 'XXL' or s == 'XXL\n':
		return 5
	return 6

def uncon(x):
	if x == 1:
		return 'S'
	if x == 2:
		return 'M'
	if x == 3:
		return 'L'
	if x == 4:
		return 'XL'
	if x == 5:
		return 'XXL'
	return 'XXXL'
s = []
m = []
l = []
xl = []
xxl = []
(sp, mp, lp, xp, xxp) = (0, 0, 0, 0, 0)
t = [0]
t += [int(z) for z in stdin.readline().split()]
n = int(stdin.readline())
ans = [0] * n
for i in range(n):
	e = [conv(z) for z in stdin.readline().split(',')]
	if len(e) == 1:
		ans[i] = e[0]
		t[e[0]] -= 1
		if t[e[0]] < 0:
			print('NO')
			exit(0)
	else:
		if e[0] == 1:
			s.append(i)
		if e[0] == 2:
			m.append(i)
		if e[0] == 3:
			l.append(i)
		if e[0] == 4:
			xl.append(i)
		if e[0] == 5:
			xxl.append(i)
while len(s) != sp and t[1]:
	ans[s[sp]] = 1
	sp += 1
	t[1] -= 1
while len(s) != sp and t[2]:
	ans[s[sp]] = 2
	sp += 1
	t[2] -= 1
if len(s) != sp:
	print('NO')
	exit(0)
while len(m) != mp and t[2]:
	ans[m[mp]] = 2
	mp += 1
	t[2] -= 1
while len(m) != mp and t[3]:
	ans[m[mp]] = 3
	mp += 1
	t[3] -= 1
if len(m) != mp:
	print('NO')
	exit(0)
while len(l) != lp and t[3]:
	ans[l[lp]] = 3
	lp += 1
	t[3] -= 1
while len(l) != lp and t[4]:
	ans[l[lp]] = 4
	lp += 1
	t[4] -= 1
if len(l) != lp:
	print('NO')
	exit(0)
while len(xl) != xp and t[4]:
	ans[xl[xp]] = 4
	xp += 1
	t[4] -= 1
while len(xl) != xp and t[5]:
	ans[xl[xp]] = 5
	xp += 1
	t[5] -= 1
if len(xl) != xp:
	print('NO')
	exit(0)
while len(xxl) != xxp and t[5]:
	ans[xxl[xxp]] = 5
	xxp += 1
	t[5] -= 1
while len(xxl) != xxp and t[6]:
	ans[xxl[xxp]] = 6
	xxp += 1
	t[6] -= 1
if len(xxl) != xxp:
	print('NO')
	exit(0)
res = [uncon(z) for z in ans]
print('YES')
for i in res:
	print(i)


def f(h, l, p):
	nc = len(l)
	for i in range(nc):
		l[i] -= p[1][i]
		if l[i] < 0:
			return ['NO']
	v2s = [0] * (nc - 1)
	v2b = [0] * (nc - 1)
	for i in range(nc - 1):
		v2s[i] = l[i]
		p[2][i] -= v2s[i]
		if p[2][i] <= 0:
			continue
		v2b[i] = p[2][i]
		l[i + 1] -= v2b[i]
		if l[i + 1] < 0:
			return ['NO']
	rl = ['YES']
	for i in history:
		if i >= 0:
			rl.append(i2s[i])
			continue
		i = -i - 1
		if v2s[i] > 0:
			rl.append(i2s[i])
			v2s[i] -= 1
		else:
			rl.append(i2s[i + 1])
	return rl
history = []
s2i = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
i2s = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
p = [None, [0] * 6, [0] * 5]
l = list(map(int, input().split()))
n = int(input())
for _ in range(n):
	s = input().split(',')
	i = s2i[s[0]]
	history.append(i if len(s) == 1 else -i - 1)
	p[len(s)][i] += 1
[print(s) for s in f(history, l, p)]


import sys
T = list(map(int, input().split()))
L = [[] for _ in range(6)]
D = [[] for _ in range(5)]
n = int(input())
S = [str(input()) for _ in range(n)]
for i in range(n):
	x = list(S[i].split(','))
	if len(x) == 2:
		if x[0] == 'S':
			D[0] += [i]
		if x[0] == 'M':
			D[1] += [i]
		if x[0] == 'L':
			D[2] += [i]
		if x[0] == 'XL':
			D[3] += [i]
		if x[0] == 'XXL':
			D[4] += [i]
		if x[0] == 'XXXL':
			D[5] += [i]
	else:
		if x[0] == 'S':
			L[0] += [i]
		if x[0] == 'M':
			L[1] += [i]
		if x[0] == 'L':
			L[2] += [i]
		if x[0] == 'XL':
			L[3] += [i]
		if x[0] == 'XXL':
			L[4] += [i]
		if x[0] == 'XXXL':
			L[5] += [i]
a = 0
ok = 1
R = ['' for _ in range(n)]
if len(L[0]) <= T[0]:
	for x in L[0]:
		R[x] = 'S'
	T[0] -= len(L[0])
else:
	print('NO')
	ok = 0
a = max(0, len(D[0]) - T[0])
for i in range(min(len(D[0]), T[0])):
	R[D[0][i]] = 'S'
if a + len(L[1]) <= T[1]:
	for i in range(len(D[0]) - a, len(D[0])):
		R[D[0][i]] = 'M'
	for x in L[1]:
		R[x] = 'M'
	T[1] -= len(L[1]) + a
else:
	print('NO')
	ok = 0
a = max(0, len(D[1]) - T[1])
for i in range(min(len(D[1]), T[1])):
	R[D[1][i]] = 'M'
if a + len(L[2]) <= T[2]:
	for i in range(len(D[1]) - a, len(D[1])):
		R[D[1][i]] = 'L'
	for x in L[2]:
		R[x] = 'L'
	T[2] -= len(L[2]) + a
else:
	print('NO')
	ok = 0
a = max(0, len(D[2]) - T[2])
for i in range(min(len(D[2]), T[2])):
	R[D[2][i]] = 'L'
if a + len(L[3]) <= T[3]:
	for i in range(len(D[2]) - a, len(D[2])):
		R[D[2][i]] = 'XL'
	for x in L[3]:
		R[x] = 'XL'
	T[3] -= len(L[3]) + a
else:
	print('NO')
	ok = 0
a = max(0, len(D[3]) - T[3])
for i in range(min(len(D[3]), T[3])):
	R[D[3][i]] = 'XL'
if a + len(L[4]) <= T[4]:
	for i in range(len(D[3]) - a, len(D[3])):
		R[D[3][i]] = 'XXL'
	for x in L[4]:
		R[x] = 'XXL'
	T[4] -= len(L[4]) + a
else:
	print('NO')
	ok = 0
a = max(0, len(D[4]) - T[4])
for i in range(min(len(D[4]), T[4])):
	R[D[4][i]] = 'XXL'
if a + len(L[5]) <= T[5]:
	for i in range(len(D[4]) - a, len(D[4])):
		R[D[4][i]] = 'XXXL'
	for x in L[5]:
		R[x] = 'XXXL'
else:
	print('NO')
	ok = 0
if ok:
	print('YES')
	for i in range(n):
		print(R[i])


import sys
input = sys.stdin.readline
size = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
num = {size[i]: i for i in range(6)}

def distribute():
	for i in range(n):
		if len(want[i]) == 1:
			w = want[i][0]
			if cnt[w] == 0:
				return False
			ans[i] = size[w]
			cnt[w] -= 1
	return True

def distribute2(x):
	for i in range(n):
		if len(want[i]) == 2:
			(w1, w2) = want[i]
			if w1 == x:
				if cnt[w1] > 0:
					ans[i] = size[w1]
					cnt[w1] -= 1
				elif cnt[w2] > 0:
					ans[i] = size[w2]
					cnt[w2] -= 1
				else:
					return False
	return True
cnt = list(map(int, input().split()))
n = int(input())
want = []
for _ in range(n):
	w = sorted((num[s] for s in input()[:-1].split(',')))
	want.append(w)
ans = [0] * n
if not distribute():
	print('NO')
	exit()
for i in range(5):
	if not distribute2(i):
		print('NO')
		exit()
print('YES')
for s in ans:
	print(s)


def fail():
	print('NO')
	exit()
read = lambda : map(int, input().split())
d = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
d2 = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
c = list(read())
n = int(input())
c2 = [0] * 6
ind = [list() for i in range(6)]
ans = [0] * n
for i in range(n):
	t = input()
	if ',' not in t:
		c[d[t]] -= 1
		ans[i] = t
	else:
		(a, b) = t.split(',')
		c2[d[a]] += 1
		ind[d[a]].append(i)
if min(c) < 0:
	fail()
for i in range(5):
	x = c2[i]
	while c[i] and x:
		c[i] -= 1
		x -= 1
		cur = ind[i].pop()
		ans[cur] = d2[i]
	while c[i + 1] and x:
		c[i + 1] -= 1
		x -= 1
		cur = ind[i].pop()
		ans[cur] = d2[i + 1]
	if x:
		fail()
print('YES')
print('\n'.join(map(str, ans)))


import sys

def gg():
	print('NO')
	sys.exit()
(s, m, l, xl, xxl, xxxl) = map(int, input().split())
r = {'S': s, 'M': m, 'L': l, 'XL': xl, 'XXL': xxl, 'XXXL': xxxl}
t = {'S,M': [], 'M,L': [], 'L,XL': [], 'XL,XXL': [], 'XXL,XXXL': []}
n = int(input())
z = [''] * n
for i in range(n):
	s = input()
	if ',' not in s:
		if r[s] <= 0:
			gg()
		r[s] -= 1
		z[i] = s
	else:
		t[s].append(i)
for (v, p) in t.items():
	(f, s) = v.split(',')
	for i in range(len(p)):
		if r[f] > 0:
			r[f] -= 1
			z[p[i]] = f
		elif r[s] > 0:
			r[s] -= 1
			z[p[i]] = s
		else:
			gg()
print('YES')
for i in z:
	print(i)


counts = [int(x) for x in input().split()]
n = int(input())
sizes = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
size_to_i = {size: i for (i, size) in enumerate(sizes)}
two_sizes = {(x, y): [] for (x, y) in zip(list(range(6)), list(range(1, 7)))}
decision = [''] * n
for i in range(n):
	demand = [size_to_i[size] for size in input().split(',')]
	if len(demand) == 1:
		d = demand[0]
		counts[d] -= 1
		decision[i] = sizes[d]
	else:
		two_sizes[demand[0], demand[1]].append(i)
for (smaller, larger) in zip(list(range(5)), list(range(1, 6))):
	for part in two_sizes[smaller, larger]:
		to_give = smaller if counts[smaller] > 0 else larger
		counts[to_give] -= 1
		decision[part] = sizes[to_give]

def possible():
	for c in counts:
		if c < 0:
			return False
	return True
if possible():
	print('YES')
	for d in decision:
		print(d)
else:
	print('NO')


(s, m, l, xl, xxl, xxxl) = map(int, input().split())
count = {'S': s, 'M': m, 'L': l, 'XL': xl, 'XXL': xxl, 'XXXL': xxxl}
key = ['XXXL', 'XXL,XXXL', 'XXL', 'XL,XXL', 'XL', 'L,XL', 'L', 'M,L', 'M', 'S,M', 'S']
needs = sorted([(input(), i) for i in range(int(input()))], key=lambda a: key.index(a[0]))
res = [0] * len(needs)
for size in needs:
	if ',' not in size[0]:
		count[size[0]] -= 1
		res[size[1]] = size[0]
		if count[size[0]] < 0:
			print('NO')
			exit()
	else:
		sizes = size[0].replace(',', ' ').split()
		if count[sizes[1]] > 0:
			count[sizes[1]] -= 1
			res[size[1]] = sizes[1]
		elif count[sizes[0]] > 0:
			count[sizes[0]] -= 1
			res[size[1]] = sizes[0]
		else:
			print('NO')
			exit()
print('YES')
print(*res, sep='\n')


our = list(map(int, input().split()))
ch = dict()
ch['S'] = 0
ch['M'] = 1
ch['L'] = 2
ch['XL'] = 3
ch['XXL'] = 4
ch['XXXL'] = 5
back = dict()
for elem in ch:
	back[ch[elem]] = elem
n = int(input())
res = [0] * n
think = []
for i in range(n):
	s = input().split(',')
	if len(s) == 1:
		our[ch[s[0]]] -= 1
		if our[ch[s[0]]] < 0:
			print('NO')
			exit()
		res[i] = s[0]
	else:
		think.append((ch[s[0]], ch[s[1]], i))
left = len(think)
think.sort()
for i in range(5, -1, -1):
	for j in range(len(think) - 1, -1, -1):
		if our[i] == 0:
			break
		if (think[j][0] == i or think[j][1] == i) and res[think[j][2]] == 0:
			our[i] -= 1
			res[think[j][2]] = back[i]
			left -= 1
if left != 0:
	print('NO')
else:
	print('YES')
	print('\n'.join(res))


import copy
sizes = list(map(int, input().split()))
participants = {}
participants_list = []
N = int(input())
for i in range(N):
	s = input()
	size_string = s
	d = participants.get(size_string, 0)
	participants[size_string] = d + 1
	participants_list.append(size_string)
single_sizes = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
multiple_sizes = [single_sizes[i] + ',' + single_sizes[i + 1] for i in range(len(single_sizes) - 1)]
size_to_index = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
multiple_answers = {}
sizes_copy = copy.copy(sizes)
res = 'YES'
for single_size in single_sizes:
	nb_participants = participants.get(single_size, 0)
	ind = size_to_index[single_size]
	if nb_participants > sizes_copy[ind]:
		res = 'NO'
		break
	sizes_copy[ind] -= nb_participants
for multiple_size in multiple_sizes:
	(size_1, size_2) = multiple_size.split(',')
	nb_participants = participants.get(multiple_size, 0)
	ind_1 = size_to_index[size_1]
	first_size = min(sizes_copy[ind_1], nb_participants)
	sizes_copy[ind_1] -= first_size
	nb_participants -= first_size
	ind_2 = size_to_index[size_2]
	if nb_participants > sizes_copy[ind_2]:
		res = 'NO'
		break
	sizes_copy[ind_2] -= nb_participants
	multiple_answers[multiple_size] = (first_size, nb_participants)
print(res)
if res == 'YES':
	for participant_size in participants_list:
		if ',' in participant_size:
			(size_1, size_2) = participant_size.split(',')
			(r1, r2) = multiple_answers.get(participant_size, 0)
			if r1 > 0:
				print(size_1)
				r1 -= 1
			else:
				print(size_2)
				r2 -= 1
			multiple_answers[participant_size] = (r1, r2)
		else:
			print(participant_size)


def some_random_function():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function5():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
import os, sys
from io import BytesIO, IOBase

def main():
	arr = list(map(int, input().split()))
	dct = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
	xx = list(dct.keys())
	n = int(input())
	ans = [0] * n
	de = [[] for _ in range(5)]
	for i in range(n):
		a = input().split(',')
		if len(a) == 1:
			ans[i] = a[0]
			arr[dct[a[0]]] -= 1
		else:
			de[dct[a[0]]].append(i)
	for i in range(5):
		for j in de[i]:
			if arr[i] > 0:
				ans[j] = xx[i]
				arr[i] -= 1
			else:
				ans[j] = xx[i + 1]
				arr[i + 1] -= 1
	if min(arr) < 0:
		print('NO')
	else:
		print('YES')
		print(*ans, sep='\n')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def some_random_function1():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function2():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function3():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function4():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function6():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function7():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)

def some_random_function8():
	x = 10
	x *= 100
	i_dont_know = x
	why_am_i_writing_this = x * x
	print(i_dont_know)
	print(why_am_i_writing_this)
main()


arr = list(map(int, input().split()))
n = int(input())
d = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5, 0: 'S', 1: 'M', 2: 'L', 3: 'XL', 4: 'XXL', 5: 'XXXL'}
ans = [-1] * n
fl = False
men = []
for i in range(n):
	s = input().split(',')
	if len(s) == 1:
		if arr[d[s[0]]] != 0:
			arr[d[s[0]]] -= 1
			ans[i] = s[0]
		else:
			print('NO')
			fl = True
	else:
		men.append((d[s[0]], d[s[1]], i))
if not fl:
	men.sort()
	for i in range(len(men)):
		if arr[men[i][0]] != 0:
			arr[men[i][0]] -= 1
			ans[men[i][-1]] = d[men[i][0]]
			continue
		elif len(men[i]) == 2:
			print('NO')
			fl = True
			break
		elif arr[men[i][1]] != 0:
			arr[men[i][1]] -= 1
			ans[men[i][-1]] = d[men[i][1]]
			continue
		else:
			print('NO')
			fl = True
			break
	if not fl:
		print('YES')
		print('\n'.join(ans))


L = list(map(int, input().split()))
n = int(input())
ss = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
d = {}
doubs = []
have = {}
vals = {}
cnt = {}
for i in range(6):
	d[ss[i]] = i
	if i < 5:
		have[i, i + 1] = 0
		vals[i, i + 1] = 0
		cnt[i, i + 1] = 0
for i in range(n):
	x = list(input().split(','))
	if len(x) == 1:
		st = d[x[0]]
		L[st] -= 1
		doubs.append((st, -1))
	else:
		(a, b) = (d[x[0]], d[x[1]])
		doubs.append((min(a, b), max(a, b)))
		have[doubs[i]] += 1
for i in range(6):
	if L[i] < 0:
		print('NO')
		exit(0)
for (k, v) in have.items():
	if v == 0:
		continue
	(a, b) = k
	if L[a] + L[b] < v:
		print('NO')
		exit(0)
	h = L[a] + L[b] - v
	pb = L[b]
	L[b] = min(L[b], h)
	bused = pb - L[b]
	aused = v - bused
	vals[k] = aused
ans = []
for x in doubs:
	if x[1] == -1:
		ans.append(ss[x[0]])
		continue
	if cnt[x] >= vals[x]:
		ans.append(ss[x[1]])
	else:
		ans.append(ss[x[0]])
		cnt[x] += 1
print('YES')
for y in ans:
	print(y)


import sys

def no():
	print('NO')
	sys.exit()
a = list(map(int, input().split()))
p = {'S': a[0], 'M': a[1], 'L': a[2], 'XL': a[3], 'XXL': a[4], 'XXXL': a[5]}
d = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
e = {0: 'S', 1: 'M', 2: 'L', 3: 'XL', 4: 'XXL', 5: 'XXXL'}
a = [0] * 5
z = [[] for i in range(5)]
g = []
n = int(input())
ans = [''] * n
for i in range(n):
	s = input()
	if ',' not in s:
		if p[s] != 0:
			p[s] -= 1
			ans[i] = s
		else:
			no()
	else:
		(b, c) = map(str, s.split(','))
		z[d[b]].append(i)
		a[d[b]] += 1
f = 0
for i in range(5):
	if a[i] > 0:
		f = i
		break
j = f
zi = 0
while a[f] != 0:
	if p[e[j]] != 0:
		p[e[j]] -= 1
		a[f] -= 1
		ans[z[f][zi]] = e[j]
		zi += 1
		if a[f] == 0:
			for i in range(f + 1, 5):
				if a[i] > 0:
					f = i
					break
			j = f
			zi = 0
	elif j - f == 1:
		no()
	else:
		j += 1
print('YES')
for i in ans:
	print(i)


d = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
nums = list(map(int, input().split()))
n = int(input())
ans = ['' for i in range(n)]
no = []
for i in range(n):
	x = input().split(',')
	if len(x) > 1:
		no.append(x + [i])
	else:
		nums[d[x[0]]] -= 1
		ans[i] = x[0]
for i in range(6):
	if nums[i] < 0:
		print('NO')
		return
no.sort(key=lambda x: d[x[0]])
for item in no:
	if nums[d[item[0]]] > 0:
		ans[item[2]] = item[0]
		nums[d[item[0]]] -= 1
	elif nums[d[item[1]]] > 0:
		ans[item[2]] = item[1]
		nums[d[item[1]]] -= 1
	else:
		print('NO')
		return
print('YES')
for i in ans:
	print(i)


d = dict.fromkeys(['S', 'M', 'L', 'XL', 'XXL', 'XXXL'])
d2 = {'S': 0, 'M': 0, 'L': 0, 'XL': 0, 'XXL': 0}
d3 = {'S': 0, 'M': 0, 'L': 0, 'XL': 0, 'XXL': 0, 'XXXL': 0}
l = input().split()
l2 = []
i = 0
for x in ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']:
	d[x] = int(l[i])
	i += 1
n = int(input())
t = True
for i in range(n):
	l = input().split(',')
	l2 += [l]
	if len(l) == 1:
		d[l[0]] -= 1
		if d[l[0]] < 0:
			print('NO')
			t = False
			break
	else:
		d2[l[0]] += 1
m = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
if t == True:
	for i in range(5):
		if d[m[i]] >= d2[m[i]]:
			d3[m[i]] += d2[m[i]]
			d[m[i]] -= d2[m[i]]
		else:
			d3[m[i]] += d[m[i]]
			d[m[i + 1]] -= d2[m[i]] - d[m[i]]
			d[m[i]] = 0
			if d[m[i + 1]] < 0:
				print('NO')
				t = False
				break
if t == True:
	print('YES')
	for x in l2:
		if len(x) == 1:
			print(x[0])
		elif d3[x[0]] > 0:
			print(x[0])
			d3[x[0]] -= 1
		else:
			print(x[1])


contest = True
if not contest:
	fin = open('in', 'r')
inp = input if contest else lambda : fin.readline()[:-1]
read = lambda : tuple(map(int, inp().split()))
tz = dict([(v, i) for (i, v) in enumerate('S,M,L,XL,XXL,XXXL'.split(','))])
sz = list(read())
n = read()[0]

def main():
	ans = {}
	q = []
	for i in range(n):
		v = inp().split(',')
		if len(v) == 1:
			v = v[0]
			ans[i] = v
			sz[tz[v]] -= 1
			if sz[tz[v]] < 0:
				return ['NO']
		else:
			v = sorted([(tz[e], e, i) for e in v], key=lambda v: v[0])
			q += [v]
	q.sort(key=lambda v: v[0][0])
	for v in q:
		if sz[v[0][0]] <= 0:
			if sz[v[1][0]] <= 0:
				return ['NO']
			else:
				sz[v[1][0]] -= 1
				ans[v[1][2]] = v[1][1]
		else:
			sz[v[0][0]] -= 1
			ans[v[0][2]] = v[0][1]
	return ['YES', [ans[i] for i in range(n)]]
v = main()
print(v[0])
if len(v) > 1:
	print('\n'.join(v[1]))


SIZES = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
INV_SIZES = {v: k for (k, v) in SIZES.items()}
shirt_count = [int(x) for x in input().split(' ')]
n = int(input())
result = []
sizes = {'S': 0, 'M': 0, 'L': 0, 'XL': 0, 'XXL': 0, 'XXXL': 0}
indices = {'S,M': 0, 'M,L': 1, 'L,XL': 2, 'XL,XXL': 3, 'XXL,XXXL': 4, 'XXXL': 5}
twosizes = [[] for x in range(6)]
for i in range(n):
	size = input()
	if size in sizes:
		sizes[size] += 1
		result.append(size)
	else:
		ind = indices[size]
		twosizes[ind].append(i)
		result.append('?')
failed = False
for (size, count) in sizes.items():
	ind = SIZES[size]
	shirt_count[ind] -= count
	if shirt_count[ind] < 0:
		failed = True
		break
for (i, x) in enumerate(shirt_count):
	if i > 0:
		arr = twosizes[i - 1]
		shirt_count[i] -= len(arr)
		if shirt_count[i] < 0:
			failed = True
			break
		else:
			for index in arr:
				result[index] = INV_SIZES[i]
	arr = twosizes[i]
	count = min(len(arr), shirt_count[i])
	shirt_count[i] -= count
	for _ in range(count):
		ind = arr.pop()
		result[ind] = INV_SIZES[i]
if failed:
	print('NO')
else:
	print('YES')
	for x in result:
		print(x)


shorts = [int(t) for t in input().split()]
n = int(input())
d = dict()
d['S'] = 0
d['M'] = 1
d['L'] = 2
d['XL'] = 3
d['XXL'] = 4
d['XXXL'] = 5
people = []
order = [t for t in range(n)]
for _ in range(n):
	people.append(input().split(','))
order.sort(key=lambda x: [d[people[x][0]], len(people[x])])
ans = dict()
for i in order:
	p = people[i]
	if shorts[d[p[0]]] != 0:
		ans[i] = p[0]
		shorts[d[p[0]]] -= 1
	elif len(p) == 2 and shorts[d[p[1]]] != 0:
		ans[i] = p[1]
		shorts[d[p[1]]] -= 1
	else:
		print('NO')
		exit()
print('YES')
for i in ans.keys():
	print(ans[i])


import sys
from random import randint

class Graph:
	verticies = {}
	nodesCount = 0

	class Vertex:

		def __init__(self, label, endPoint=None):
			self.label = label
			self.edges = []
			self.visitedToken = 0
			self.endPoint = endPoint

	class Edge:
		residual = None

		def __init__(self, from_, to_, isResidual, maxCapacity):
			self.from_ = from_
			self.to_ = to_
			self.isResidual = isResidual
			self.capacity = maxCapacity
			self.flow = 0

		def augment(self, bootleneck):
			self.flow += bootleneck
			self.residual.flow -= bootleneck

		def remainingCapacity(self):
			return self.capacity - self.flow

	def addEdge(self, from_, to_, capacity):
		from_ = self.verticies[from_]
		to_ = self.verticies[to_]
		if from_.endPoint and from_.endPoint != to_:
			from_ = from_.endPoint
		main = self.Edge(from_, to_, False, capacity)
		residual = self.Edge(to_, from_, True, 0)
		main.residual = residual
		residual.residual = main
		from_.edges.append(main)
		to_.edges.append(residual)

	def addVertex(self, label, *args):
		self.nodesCount += 1
		if args:
			capacity = args[0]
			key = str(randint(0, sys.maxsize)) + '--' + str(label)
			endPoint = self.Vertex(key)
			self.verticies[key] = endPoint
			self.verticies[label] = self.Vertex(label, endPoint=endPoint)
			self.addEdge(label, key, capacity)
		else:
			self.verticies[label] = self.Vertex(label)

	def maxFlow(self, f, t):
		f = self.verticies[f]
		t = self.verticies[t]
		visitedToken = 1
		flow = 0

		def dfs(node, bootleneck=sys.maxsize):
			node.visitedToken = visitedToken
			bootleneck_backup = bootleneck
			if node == t:
				return bootleneck
			for edge in node.edges:
				if edge.remainingCapacity() == 0 or edge.to_.visitedToken == visitedToken:
					continue
				bootleneck = dfs(edge.to_, min(bootleneck, edge.remainingCapacity()))
				if bootleneck:
					edge.augment(bootleneck)
					return bootleneck
				else:
					bootleneck = bootleneck_backup
			return 0
		while True:
			bootleneck = dfs(f)
			if not bootleneck:
				break
			flow += bootleneck
			visitedToken += 1
		return flow

def solve():
	g = Graph()
	sink = 12
	g.addVertex(sink)
	vc = 0
	counts = list(map(int, input().split()))
	sss = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
	supply = []
	wants = [0, 0, 0, 0, 0]
	order = []
	n = int(input())
	g.addVertex(vc)
	vc += 1
	res = ['' for i in range(n)]
	for i in range(11):
		g.addVertex(vc)
		vc += 1
	for _ in range(n):
		s = input().split(',')
		if len(s) == 1:
			counts[sss.index(s[0])] -= 1
			n -= 1
			res[_] = s[0]
			if counts[sss.index(s[0])] < 0:
				return print('NO')
		else:
			order.append(sss.index(s[0]))
			wants[sss.index(s[0])] += 1
	for i in range(6):
		g.addEdge(0, i + 1, counts[i])
	g.addEdge(1, 7, sys.maxsize)
	g.addEdge(2, 7, sys.maxsize)
	g.addEdge(2, 8, sys.maxsize)
	g.addEdge(3, 8, sys.maxsize)
	g.addEdge(3, 9, sys.maxsize)
	g.addEdge(4, 9, sys.maxsize)
	g.addEdge(4, 10, sys.maxsize)
	g.addEdge(5, 10, sys.maxsize)
	g.addEdge(5, 11, sys.maxsize)
	g.addEdge(6, 11, sys.maxsize)
	for i in range(5):
		g.addEdge(7 + i, sink, wants[i])
	if g.maxFlow(0, sink) == n:
		print('YES')
		for i in range(1, 7):
			for e in g.verticies[i].edges:
				if not e.isResidual:
					supply.append(e.flow)
		for i in range(len(res)):
			if not res[i]:
				want = order.pop(0)
				if supply[want * 2]:
					supply[want * 2] -= 1
					res[i] = sss[want]
				else:
					supply[want * 2 + 1] -= 1
					res[i] = sss[want + 1]
		print('\n'.join(res))
	else:
		print('NO')
solve()


__author__ = 'Think'
assign = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5, 'S,M': 6, 'M,L': 7, 'L,XL': 8, 'XL,XXL': 9, 'XXL,XXXL': 10}
up = {'S,M': 'M', 'M,L': 'L', 'L,XL': 'XL', 'XL,XXL': 'XXL', 'XXL,XXXL': 'XXXL'}
down = {'S,M': 'S', 'M,L': 'M', 'L,XL': 'L', 'XL,XXL': 'XL', 'XXL,XXXL': 'XXL'}
shirts = {i: 0 for i in range(11)}
numbers = [int(i) for i in input().split()]
split = {i: 0 for i in range(6, 11)}
n = int(input())
failed = False
received = []
for i in range(n):
	s = input()
	shirts[assign[s]] += 1
	received.append(s)
for i in range(6):
	numbers[i] -= shirts[i]
	if numbers[i] < 0:
		print('NO')
		failed = True
		break
if not failed:
	for i in range(6, 11):
		below = numbers[i - 6]
		above = numbers[i - 5]
		needed = shirts[i]
		if below >= needed:
			split[i] = needed
		else:
			split[i] = below
			needed -= below
			if above < needed:
				failed = True
				print('NO')
				break
			else:
				numbers[i - 5] -= needed
	if not failed:
		print('YES')
		for s in received:
			if assign[s] < 6:
				print(s)
			elif split[assign[s]] > 0:
				split[assign[s]] -= 1
				print(down[s])
			else:
				print(up[s])


tsh = list(map(int, input().split()))
need = [[0, 0] for i in range(6)]
n = int(input())
ans = [[0, False] for i in range(n)]
for i in range(n):
	req = input().split(',')
	ans[i][1] = len(req) > 1
	if len(req) == 1:
		if req[0] == 'S':
			need[0][0] += 1
			ans[i][0] = 0
		elif req[0] == 'M':
			need[1][0] += 1
			ans[i][0] = 1
		elif req[0] == 'L':
			need[2][0] += 1
			ans[i][0] = 2
		elif req[0] == 'XL':
			need[3][0] += 1
			ans[i][0] = 3
		elif req[0] == 'XXL':
			need[4][0] += 1
			ans[i][0] = 4
		elif req[0] == 'XXXL':
			need[5][0] += 1
			ans[i][0] = 5
	elif req[0] == 'S':
		need[0][1] += 1
		ans[i][0] = 0
	elif req[0] == 'M':
		need[1][1] += 1
		ans[i][0] = 1
	elif req[0] == 'L':
		need[2][1] += 1
		ans[i][0] = 2
	elif req[0] == 'XL':
		need[3][1] += 1
		ans[i][0] = 3
	elif req[0] == 'XXL':
		need[4][1] += 1
		ans[i][0] = 4
	elif req[0] == 'XXXL':
		need[5][1] += 1
		ans[i][0] = 5
next = 0
new = [[0, 0] for i in range(6)]
for i in range(6):
	tsh[i] -= need[i][0]
	tsh[i] -= next
	new[i][0] = next + need[i][0]
	if tsh[i] < 0:
		print('NO')
		quit()
	can = min(tsh[i], need[i][1])
	next = need[i][1] - can
	new[i][1] = next
print('YES')
for x in ans:
	if x[1] and new[x[0]][1] > 0:
		new[x[0]][1] -= 1
		x[0] += 1
	t = x[0]
	if t == 0:
		print('S')
	elif t == 1:
		print('M')
	elif t == 2:
		print('L')
	elif t == 3:
		print('XL')
	elif t == 4:
		print('XXL')
	elif t == 5:
		print('XXXL')


a = list(map(int, input().split()))
n = int(input())
result = [0] * n
sizes = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
buckets = [[] for _ in range(5)]
count = []

def die():
	print('NO')
	exit()
for i in range(n):
	sizeIndices = tuple(map(lambda x: sizes.index(x), input().split(',')))
	if len(sizeIndices) == 1:
		index = sizeIndices[0]
		a[index] -= 1
		if a[index] < 0:
			die()
		result[i] = sizes[index]
	else:
		buckets[min(sizeIndices)].append(i)
for i in range(len(buckets)):
	for x in buckets[i]:
		count.append((x, i, i + 1))
for (index, x, y) in count:
	if a[x] > 0:
		a[x] -= 1
		result[index] = sizes[x]
	elif a[y] > 0:
		a[y] -= 1
		result[index] = sizes[y]
	else:
		die()
print('YES')
for i in range(n):
	print(result[i])


cs = list(map(int, input().split(' ')))
camisas = {}
camisas['S'] = cs[0]
camisas['M'] = cs[1]
camisas['L'] = cs[2]
camisas['XL'] = cs[3]
camisas['XXL'] = cs[4]
camisas['XXXL'] = cs[5]
p = int(input())
resposta = {}
possivel = True
s = []
m = []
l = []
xl = []
xxl = []
for i in range(p):
	camisa_pessoa = list(input().split(','))
	if len(camisa_pessoa) == 1:
		camisa = camisa_pessoa[0]
		if camisas[camisa] > 0:
			resposta[i] = camisa
			camisas[camisa] = camisas[camisa] - 1
		else:
			possivel = False
	elif camisa_pessoa[0] == 'S':
		s.append(i)
	elif camisa_pessoa[0] == 'M':
		m.append(i)
	elif camisa_pessoa[0] == 'L':
		l.append(i)
	elif camisa_pessoa[0] == 'XL':
		xl.append(i)
	elif camisa_pessoa[0] == 'XXL':
		xxl.append(i)
if possivel:
	for i in s:
		if camisas['S'] > 0:
			camisas['S'] = camisas['S'] - 1
			resposta[i] = 'S'
		elif camisas['M'] > 0:
			camisas['M'] = camisas['M'] - 1
			resposta[i] = 'M'
		else:
			possivel = False
			break
if possivel:
	for i in m:
		if camisas['M'] > 0:
			camisas['M'] = camisas['M'] - 1
			resposta[i] = 'M'
		elif camisas['L'] > 0:
			camisas['L'] = camisas['L'] - 1
			resposta[i] = 'L'
		else:
			possivel = False
			break
if possivel:
	for i in l:
		if camisas['L'] > 0:
			camisas['L'] = camisas['L'] - 1
			resposta[i] = 'L'
		elif camisas['XL'] > 0:
			camisas['XL'] = camisas['XL'] - 1
			resposta[i] = 'XL'
		else:
			possivel = False
			break
if possivel:
	for i in xl:
		if camisas['XL'] > 0:
			camisas['XL'] = camisas['XL'] - 1
			resposta[i] = 'XL'
		elif camisas['XXL'] > 0:
			camisas['XXL'] = camisas['XXL'] - 1
			resposta[i] = 'XXL'
		else:
			possivel = False
			break
if possivel:
	for i in xxl:
		if camisas['XXL'] > 0:
			camisas['XXL'] = camisas['XXL'] - 1
			resposta[i] = 'XXL'
		elif camisas['XXXL'] > 0:
			camisas['XXXL'] = camisas['XXXL'] - 1
			resposta[i] = 'XXXL'
		else:
			possivel = False
			break
if not possivel:
	print('NO')
else:
	print('YES')
	for k in range(p):
		print(resposta[k])


arr = [int(i) for i in input().split()]
left = []
cont = True
n = int(input())
ans = [None] * n
for i in range(n):
	s = input().split(',')
	a = []
	for j in range(len(s)):
		if s[j] == 'S':
			a.append(0)
		elif s[j] == 'M':
			a.append(1)
		elif s[j] == 'L':
			a.append(2)
		elif s[j] == 'XL':
			a.append(3)
		elif s[j] == 'XXL':
			a.append(4)
		else:
			a.append(5)
	if len(s) == 2:
		left.append([a[0], a[1], s[0], s[1], i])
	else:
		arr[a[0]] -= 1
		if arr[a[0]] < 0:
			print('NO')
			cont = False
			break
		else:
			ans[i] = s[0]
left = sorted(left)
if cont:
	l = len(left)
	for i in range(6):
		for j in range(len(left)):
			if arr[i] == 0 or l == 0:
				break
			if len(left[j]) == 1:
				continue
			if i == left[j][0]:
				l -= 1
				arr[i] -= 1
				ans[left[j][4]] = left[j][2]
				left[j] = [0]
			elif i == left[j][1]:
				l -= 1
				arr[i] -= 1
				ans[left[j][4]] = left[j][3]
				left[j] = [0]
	if l > 0:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			print(ans[i])


shirts_count = list(map(int, input().split()))
no = False
n = 0
for i in shirts_count:
	n += i
sizes = ('S', 'M', 'L', 'XL', 'XXL', 'XXXL')
shirts = dict()
children = list()
for i in range(len(sizes)):
	shirts[sizes[i]] = shirts_count[i]
for i in range(int(input())):
	children.append(input().split(','))
if n < len(children):
	print('NO')
else:
	itog = [0] * len(children)
	for i in range(len(children)):
		if len(children[i]) == 1:
			if shirts[str(children[i][0])] > 0:
				shirts[str(children[i][0])] -= 1
				itog[i] = str(children[i][0])
			else:
				no = True
	a = 0
	while a < 5 and (not no):
		for i in range(len(children)):
			if len(children[i]) > 1:
				if sizes[a] == children[i][0] and sizes[a + 1] == children[i][1]:
					if shirts[sizes[a]] > 0:
						itog[i] = sizes[a]
						shirts[sizes[a]] -= 1
					elif shirts[sizes[a + 1]] > 0:
						itog[i] = sizes[a + 1]
						shirts[sizes[a + 1]] -= 1
					else:
						no = True
		a += 1
	if not no:
		print('YES')
		for i in range(len(itog)):
			print(itog[i])
	if no:
		print('NO')


s = list(map(int, input().split()))
d = {'S': s[0], 'M': s[1], 'L': s[2], 'XL': s[3], 'XXL': s[4], 'XXXL': s[5]}
o = {0: 'S', 1: 'M', 2: 'L', 3: 'XL', 4: 'XXL', 5: 'XXXL'}
n = int(input())
l = []
for i in range(n):
	s = input()
	if ',' not in s:
		l.append(s.split())
	else:
		l.append(s.split(','))
flag = 0
done = {}
for i in range(n):
	if len(l[i]) == 1:
		if d[l[i][0]] == 0:
			flag = 1
			break
		else:
			d[l[i][0]] -= 1
			done[i] = l[i][0]
if flag:
	print('NO')
	exit()
for i in range(6):
	if i == 0:
		j = 0
		while d[o[i]] != 0 and j < n:
			if j not in done and o[i] in l[j] and (o[i + 1] in l[j]):
				done[j] = o[i]
				d[o[i]] -= 1
			j += 1
	else:
		j = 0
		while d[o[i]] != 0 and j < n:
			if j not in done and o[i] in l[j] and (o[i - 1] in l[j]):
				done[j] = o[i]
				d[o[i]] -= 1
			j += 1
		j = 0
		while d[o[i]] != 0 and j < n:
			if j not in done and o[i] in l[j] and (o[i + 1] in l[j]):
				done[j] = o[i]
				d[o[i]] -= 1
			j += 1
if len(done) != n:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print(done[i])


SIZES = 'S M L XL XXL XXXL'.split()
have = {key: int(count) for (count, key) in zip(input().split(), SIZES)}
n = int(input())
possible = []
uses = []
for size in range(n):
	possible.append(input().split(','))
	if len(possible[-1]) > 1:
		uses.append(None)
	else:
		uses.append(possible[-1][0])
		have[possible[-1][0]] -= 1
		if have[possible[-1][0]] < 0:
			print('NO')
			exit(0)
		possible[-1] = None
for size in SIZES:
	for i in range(2):
		for (index, poss) in enumerate(possible):
			if poss is not None:
				if have[size] > 0:
					if i == 0 and size == poss[1] or (i == 1 and size in poss):
						have[size] -= 1
						uses[index] = size
						possible[index] = None
				else:
					break
if None in uses:
	print('NO')
else:
	print('YES')
	for i in uses:
		print(i)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from bisect import *
from math import gcd
from itertools import permutations, combinations
from math import sqrt, ceil, floor

def main():
	a = list(map(int, input().split()))
	b = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
	c = [[] for _ in range(5)]
	d = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
	n = int(input())
	ans = [''] * n
	for i in range(n):
		e = input().split(',')
		if len(e) == 1:
			a[b[e[0]]] -= 1
			ans[i] = e[0]
		else:
			c[b[e[0]]].append(i)
	for i in range(5):
		while c[i]:
			if a[i] > 0:
				a[i] -= 1
				ans[c[i].pop()] = d[i]
			else:
				a[i + 1] -= 1
				ans[c[i].pop()] = d[i + 1]
	if min(a) < 0:
		print('NO')
	else:
		print('YES')
		print(*ans, sep='\n')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


a = list(map(int, input().split()))
b = [0, 0, 0, 0, 0]
c = [0, 0, 0, 0, 0]
ipt = []
ans = []
d = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
n = int(input())
for i in range(1, n + 1):
	j = input()
	ipt.append(j)
	ans.append(j)
	if j.find(',') == -1:
		a[d[j]] -= 1
	else:
		b[d[j[0:j.find(',')]]] += 1
ans = False
for i in range(0, 6):
	if a[i] < 0 and ans == False:
		ans = True
	elif i < 5:
		if i == 0:
			if b[i] > a[i]:
				c[i] = b[i] - a[i]
				b[i] -= a[i]
				a[i] = 0
			else:
				c[i] = 0
				a[i] -= b[i]
				b[i] = 0
		else:
			if b[i - 1] > 0:
				if b[i - 1] > a[i]:
					ans = True
				else:
					a[i] -= b[i - 1]
			if b[i] > a[i]:
				c[i] = b[i] - a[i]
				b[i] -= a[i]
				a[i] = 0
			else:
				c[i] = 0
				a[i] -= b[i]
				b[i] = 0
	elif i == 5:
		if a[i] < b[i - 1]:
			ans = True
if ans == True:
	print('NO')
else:
	print('YES')
	for i in ipt:
		if i.find(',') == -1:
			print(i)
		else:
			tmp = i[0:i.find(',')]
			if c[d[tmp]] > 0:
				print(i[i.find(',') + 1:])
				c[d[tmp]] -= 1
			else:
				print(tmp)


def solve(a, n):
	M = {'S': 0, 'M': 1, 'L': 2, 'XL': 3, 'XXL': 4, 'XXXL': 5}
	m = {0: 'S', 1: 'M', 2: 'L', 3: 'XL', 4: 'XXL', 5: 'XXXL'}
	p = [[] for _ in range(5)]
	ans = [''] * n
	for i in range(n):
		s = input()
		if ',' in s:
			p[M[s[:s.find(',')]]] += [i]
		else:
			s = M[s]
			if a[s] <= 0:
				return []
			a[s] -= 1
			ans[i] = m[s]
	for i in range(5):
		for x in p[i]:
			if a[i] > 0:
				a[i] -= 1
				ans[x] = m[i]
			elif a[i + 1] > 0:
				a[i + 1] -= 1
				ans[x] = m[i + 1]
			else:
				return []
	return ans
ans = solve(list(map(int, input().split())), int(input()))
if ans == []:
	print('NO')
else:
	print('YES')
	for s in ans:
		print(s)


def solve(n, sizes, allocation, demands):
	for i in range(n):
		curr = input()
		if len(curr.split(',')) == 1:
			if sizes[curr] > 0:
				sizes[curr] -= 1
				allocation[i] = curr
			else:
				return False
		else:
			demands[curr].append(i)
	for (demand, people) in demands.items():
		(poss_1, poss_2) = demand.split(',')
		for i in range(len(people)):
			if sizes[poss_1] > 0:
				sizes[poss_1] -= 1
				allocation[people[i]] = poss_1
			elif sizes[poss_2] > 0:
				sizes[poss_2] -= 1
				allocation[people[i]] = poss_2
			else:
				return False
	return True
(s, m, l, xl, xxl, xxxl) = map(int, input().split())
n = int(input())
sizes = {'S': s, 'M': m, 'L': l, 'XL': xl, 'XXL': xxl, 'XXXL': xxxl}
allocation = ['' for _ in range(n)]
demands = {'S,M': [], 'M,L': [], 'L,XL': [], 'XL,XXL': [], 'XXL,XXXL': []}
if not solve(n, sizes, allocation, demands):
	print('NO')
else:
	print('YES')
	for a in allocation:
		print(a)