atcoder#ABC166F. [ABC166F] Three Variables Game
[ABC166F] Three Variables Game
Score : points
Problem Statement
There is a game that involves three variables, denoted , , and .
As the game progresses, there will be events where you are asked to make a choice.
Each of these choices is represented by a string . If is AB
, you must add to or then subtract from the other; if is AC
, you must add to or then subtract from the other; if is BC
, you must add to or then subtract from the other.
After each choice, none of , , and should be negative.
Determine whether it is possible to make choices under this condition. If it is possible, also give one such way to make the choices.
Constraints
- are integers.
- is
AB
,AC
, orBC
.
Input
Input is given from Standard Input in the following format:
Output
If it is possible to make 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 lines. The -th line should contain the name of the variable (A
, B
, or C
) to which you add in the -th choice.
2 1 3 0
AB
AC
Yes
A
C
You can successfully make two choices, as follows:
- In the first choice, add to and subtract from . becomes , and becomes .
- In the second choice, add to and subtract from . becomes , and becomes .
3 1 0 0
AB
BC
AB
No
1 0 9 0
AC
No
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
Yes
C
B
B
C
C
B
A
A