T-shirts Distribution
Contest: Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2)
Difficulty rating: 1800
Tags: constructive algorithms, flows, greedy

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 format:
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 format:
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.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Example input:
0 1 0 1 1 0
3
XL
S,M
XL,XXL

Example output:
YES
XL
M
XXL

Example input:
1 1 2 0 1 1
5
S
M
S,M
XXL,XXXL
XL,XXL

Example output:
NO

Editorial:
Let in the array cnt we store how many t-shirts of each size are in the typography.
At first let's give the t-shirts to participants who wants exactly one size of the t-shirt and decrease appropriate values in cnt. If in some moment we have no t-shirt of needed size the answer is "NO".
Now we need to give the t-shirts to participants who wants t-shirt with one of two sizes. Let's use greedy. At first we need to give t-shirts with size S to participants who wants it or t-shirt with size M. After that let's move to the t-shirts with size M. At first let's give this t-shirts to participants who wants it or t-shirts with size S and do not already have the t-shirt. After that if t-shirts with size M remain we need to give this t-shirts to participants who wants it or t-shirts with sizes L. Similarly, we must distribute the remaining t-shirts sizes.
If after all operations not each participant has the t-shirt the answer is "NO". In the other case we found the answer.