#t183. 潜伏者
潜伏者
The Spy
Problem Description
Countries and are at war, each sending spies into the other's territory to act when the chance arises.
After much hardship, spy Little of country , lurking inside country , has finally figured out the encoding rules of 's military cipher:
- The original message that 's military wants to send, and the encrypted message sent over the network, both consist solely of uppercase letters
A–Z(no spaces or other characters). - For each letter, defines a corresponding "cipher letter". Encryption replaces every letter in the original message with its corresponding cipher letter.
- Each letter corresponds to exactly one unique cipher letter, and different letters correspond to different cipher letters. A cipher letter may be the same as the original letter.
For example, if A's cipher letter is A and B's cipher letter is C (other letters and their ciphers omitted), then the original message ABA is encrypted as ACA.
Now Little has, through inside information, obtained one encrypted message from together with its corresponding original message. Little hopes to use this message to crack 's military cipher. His cracking process is as follows: scan the original message; for a letter in the original message (representing any uppercase letter), find its corresponding uppercase letter in the encrypted message, and conclude that in the cipher is the cipher letter of . Continue this until the process stops in one of the following states:
- Scanning is complete, and at least of the letters
A–Zhave appeared in the original message and obtained their corresponding cipher letters, with no contradiction or error. - Scanning is complete, but it is found that at least letters never appeared in the original message.
- During scanning, an obvious contradiction or error is found in the information obtained (violating 's cipher encoding rules). For example, if some message
XYZis translated asABA, that violates the rule "different letters map to different cipher letters".
While Little is busy and dizzy, country 's command sends another telegram asking him to translate an additional encrypted message just intercepted from . Now please help Little : use the information from the inside channel to try to crack the cipher, then use the cracked cipher to translate the encrypted message in the telegram.
Input Format
Three lines in total, each a string of length between and .
The first line is an encrypted message that Little has obtained.
The second line is the original message corresponding to the encrypted message in the first line.
The third line is the encrypted message that country 's command asks Little to translate.
The input is guaranteed to consist only of uppercase letters A–Z, and the first line has the same length as the second line.
Output Format
One line in total.
If the cipher cracking stops in case 2 or case 3 above, output Failed (note the capital first letter, the rest lowercase).
Otherwise output the original message obtained by translating the encrypted message in the telegram using the cipher.
Sample Input 1
AA
AB
EOWIE
Sample Output 1
Failed
Sample Input 2
QWERTYUIOPLKJHGFDSAZXCVBN
ABCDEFGHIJKLMNOPQRSTUVWXY
DSLIEWO
Sample Output 2
Failed
Sample Input 3
MSRTZCJKPFLQYVAWBINXUEDGHOOILSMIJFRCOPPQCEUNYDUMPP
YIZSDWAHLNOVFUCERKJXQMGTBPPKOIYKANZWPLLVWMQJFGQYLL
FLSO
Sample Output 3
NOIP
Hint
Sample 1 explanation: the letters A and B in the original message correspond to the same cipher letter, so output Failed.
Sample 2 explanation: only the letter Z never appeared in the original message, so output Failed.
Constraints
Each input string has length between and , and consists only of uppercase letters A–Z.