Problem E
Code Guessing
Bob tells Alice the positions of her two cards. The goal of Alice is to guess the digits on Bob’s two cards. Can Alice uniquely determine these two digits and guess them correctly?
Input
The input has two integers $p, q$ ($1 \leq p < q \leq 9$) on the first line, giving the digits on Alice’s cards. The next line has a string containing two ‘A’s and two ‘B’s, giving the positions of Alice’s and Bob’s cards on the table. It is guaranteed that Bob correctly sorts the cards and gives the correct positions of Alice’s cards.
Output
If Alice can uniquely determine the two digits on Bob’s cards, output the two digits on a single line, starting with the smaller digit. Otherwise, output $-1$.
Sample Input 1 | Sample Output 1 |
---|---|
6 9 ABBA |
7 8 |
Sample Input 2 | Sample Output 2 |
---|---|
2 5 BAAB |
-1 |