F - Three Variables Game Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

あるゲームでは 3 つの変数があり、それぞれ A,B,C で表されます。

ゲームの進行と共に、あなたは N 回の選択に迫られます。 それぞれの選択は文字列 s_i によって示され、 s_iAB のとき、AB のどちらかに 1 を足しもう一方から 1 を引くこと、 AC のとき、AC のどちらかに 1 を足しもう一方から 1 を引くこと、 BC のとき、BC のどちらかに 1 を足しもう一方から 1 を引くことを意味します。

いずれの選択の後にも、A,B,C のいずれも負の値になってはいけません。

この条件を満たしつつ N 回すべての選択を終えることが可能であるか判定し、可能であるならそのような選択方法をひとつ示してください。

制約

  • 1 \leq N \leq 10^5
  • 0 \leq A,B,C \leq 10^9
  • N, A, B, C は整数である。
  • s_iAB, AC, BC のいずれか

入力

入力は以下の形式で標準入力から与えられる。

N A B C
s_1
s_2
:
s_N

出力

条件を満たしつつ N 個すべての選択を終えることが可能である場合は Yes を、そうでない場合は No を出力せよ。

加えて、前者の場合は続く N 行に選択方法を示せ。i+1 行目には i 回目の選択で 1 を足す変数の名前 (A, B, C のいずれか) を出力せよ。


入力例 1

2 1 3 0
AB
AC

出力例 1

Yes
A
C

次のようにすることで 2 回すべての選択を終えることができます。

  • 1 回目の選択では、A1 を足し B から 1 を引く。A の値が 2 に、B の値が 2 に変化する。
  • 2 回目の選択では、C1 を足し A から 1 を引く。C の値が 1 に、A の値が 1 に変化する。

入力例 2

3 1 0 0
AB
BC
AB

出力例 2

No

入力例 3

1 0 9 0
AC

出力例 3

No

入力例 4

8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB

出力例 4

Yes
C
B
B
C
C
B
A
A

Score : 600 points

Problem Statement

There is a game that involves three variables, denoted A, B, and C.

As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is AB, you must add 1 to A or B then subtract 1 from the other; if s_i is AC, you must add 1 to A or C then subtract 1 from the other; if s_i is BC, you must add 1 to B or C then subtract 1 from the other.

After each choice, none of A, B, and C should be negative.

Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

Constraints

  • 1 \leq N \leq 10^5
  • 0 \leq A,B,C \leq 10^9
  • N, A, B, C are integers.
  • s_i is AB, AC, or BC.

Input

Input is given from Standard Input in the following format:

N A B C
s_1
s_2
:
s_N

Output

If it is possible to make N choices under the condition, print Yes; otherwise, print No.

Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (A, B, or C) to which you add 1 in the i-th choice.


Sample Input 1

2 1 3 0
AB
AC

Sample Output 1

Yes
A
C

You can successfully make two choices, as follows:

  • In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.
  • In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.

Sample Input 2

3 1 0 0
AB
BC
AB

Sample Output 2

No

Sample Input 3

1 0 9 0
AC

Sample Output 3

No

Sample Input 4

8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB

Sample Output 4

Yes
C
B
B
C
C
B
A
A