Under construction

Still being built. Things may change

Code Guessing

Time limit1sMemory limit1024 MB

Summary
Given Alice's two digits and the table positions of the four sorted cards, decide whether Bob's two digits are uniquely determined and print them, else -1.
Level

Easy3 of 10

Topics
Brute force, Implementation, Combinatorics
Solved
No attempts yet

Problem

Alice and Bob are playing a board game with a deck of nine cards. For each digit between 1 and 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 four cards on the table in increasing order by the digits. The 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 pp, qq (1≤p<q≤91 \le p < q \le 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.

Examples2

  1. Example 1

    Input
    6 9
    ABBA
    
    Expected output
    7 8
    
  2. Example 2

    Input
    2 5
    BAAB
    
    Expected output
    -1