Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2)
D
T-shirts Distribution
Codeforces
1800
原题
← CE →
翻译中…

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.

翻译中…

样例

Input #1
0 1 0 1 1 0
3
XL
S,M
XL,XXL
Output #1
YES
XL
M
XXL
InputCopy OutputCopy
Input #2
1 1 2 0 1 1
5
S
M
S,M
XXL,XXXL
XL,XXL
Output #2
NO
InputCopy OutputCopy
题目信息
标签
构造
网络流
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。