Hide

Code Guessing

/problems/codeguessing/file/statement/en/img-0001.png
Alice and Bob are playing a board game with a deck of nine cards. For each digit between $1$ to $9$, there is one card with that digit on it. Alice and Bob each draw two cards after shuffling the cards, and see the digits on their own cards without revealing the digits to each other. Then Alice gives her two cards to Bob. Bob sees the digits on Alice’s cards and lays all the four cards on the table in increasing order by the digits. Cards are laid facing down.

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
CPU Time limit 1 second
Memory limit 1024 MB
Difficulty 2.1easy
Statistics Show
Author
License Creative Commons License (cc by-sa)

Please log in to submit a solution to this problem

Log in