Bocchi, the queen of plastic games, downloaded a game she saw in a YouTube advertisement. She's now addicted to this game.
In the game, you start with the number $A$. There are $N$ stages in total and you will go through them one by one. Within each stage, there are two doors, each with a label. Each label is a string consisting of a sign ($+, -, \times$ or $\div$) and a positive integer $x$. You will choose exactly one of the two doors to pass through. Afterwards, the number you have will be changed according to the label of the door like how you usually perform calculations, except that $\div$ represents a truncated division. Formally, if you have the number $a$ before entering a door having sign $s$ and integer $x$, your number will be become $$[ a\ s\ x ]$$ where $s$ is $+, -, \times,$ or $\div$. Note that $[ r ]$ denotes the integer part of $r$, i.e. rounding toward zero. For example, $[-2.1]=-2$ and $[2.6]=2$.
Bocchi wants to achieve the number $B$ after all stages. However, her math is not enough for this game. Can help her to achieve it, or tell her it is impossible to do so?
Input
The first lines consists of three integers $N$, $A$ and $B$.
Then, $N$ lines follow. The $i$-th line consists of two strings, corresponding to the
labels of the first and second doors of the $i$-th stage respectively.
+
, -
, *
and /
represents the signs
$+, -, \times$ and $\div$ respectively.
Output
If it is impossible to achieve $B$ at the end, print No
.
Otherwise, on the first line print Yes
.
Then on the following line,
print $N$ space-seperated integers $d_i$ with $d_i = 1$ or $2$, denoting which door should Bocchi go through at the $i$-th stage.
If there are multiple solutions, you can output any one of them.
Constraints
It is guaranteed that $-10^{18} \le a \le 10^{18}$, where $a$ is Bocchi's number in any moment of the game, no matter which doors she chooses.
For all cases: $1 \le N \le 30$, $-10^9 \le A, B \le 10^9$, $1 \le x \le 10^9$
Subtask 1 (7%): $N \le 2$
Subtask 2 (19%): $N \le 22$
Subtask 3 (25%): No doors have $\times$ or $\div$ as the sign
Subtask 4 (14%): No doors have $\div$ as the sign
Subtask 5 (35%): No additional constraints
Sample Test Cases
Input | Output | |
---|---|---|
2 17 128 *2 /2 +50 +120 |
Yes 2 2 |
|
Bocchi can take the second door of the first stage to get the number $8 = \lfloor 17 \div 2 \rfloor$. She can then take the second door of the second stage to get the number $128 = 8 + 120$. | ||
3 0 -160008 -100 +10 +5 /12 *20000 *20001 |
Yes 1 2 2 |
Scoring: Per Subtask
Authored by s17r28 and s17f18
Appeared in 2023 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆