Ms. Evans's database stores a number of words consisting of the first English letters. To prevent technicians from seeing sensitive information, the words are encrypted in a very simple way: each English letter is mapped to exactly one English letter, such that no two letters map to the same letter. A letter can map to itself. To encrypt a word, each letter of the word is replaced with the letter it maps to.
For example, if , the following mappings are valid:
The following mappings are not valid:
One of the hard drives failed yesterday, and some information about the mapping has been lost. Specifically, for the letter, it is known that it mapped to either or ( and are among the first English letters; ).
Ms. Evans has a list of questions. Question asks: given what we know about the mapping, is it possible that could map to ? and are strings of equal length composed of the first lowercase English characters. No string will exceed characters in length.
It is guaranteed that the input corresponds to at least one valid mapping.
Input Specification
The first line contains . The of the next lines contains and . The next line contains . The of the next lines contains and .
Output Specification
For each question, output a single line containing the answer: either YES
or NO
.
Sample Input 1
2
a b
a b
4
aa bb
aa ab
ba aa
ab ba
Sample Output 1
YES
NO
NO
YES
Sample Input 2
4
b d
a c
a b
c b
3
a b
b b
abcd dabc
Sample Output 2
NO
NO
YES
Comments
Can someone explain the second test case? Why can't a be mapped to b if a can be mapped to b and d?
If 'a' were to be mapped to 'b', then 'c' must be mapped to 'a' and 'd' must be mapped to 'c' (by elimination). This means that 'b' must be mapped to 'd' (since every letter must be mapped by exactly one letter), but this isn't possible since 'b' can only be mapped to 'a' or 'c'. So 'a' cannot be mapped to 'b'.
In all the valid mappings, a maps to d.
We have updated the statement with examples of valid and invalid mappings in an attempt to make the question clearer.
Why cant 'a' be mapped to 'b'? In the input it says the 2 possibilities for 'a' are 'b' and 'd'.
Amen
I am thoroughly confused x.x
To the problem writers: If this is your first contest, I feel you. It definitely is tough making the first one when schools like DM have been doing this for a year. Keep it up!
hob
hob, you realize that nullptr went to the IOI...
BuMP how do you know this shizbiz
Bruh going to IOI doesn't require you to write questions.
Thank you very much for your kind, understanding words.
o
Can't tell if that was sarcasm or just being a decent human being... x) \(^o^ )/
Either way, no problem!
hob