Carbon, the element of life, is part of many different molecules essential to living things. One particular type of carbon-based molecule, the tetrahedral molecule, consists of a single carbon atom bonded to four groups. This type of molecule forms a tetrahedral shape, with the carbon in the centre and the groups at the four vertices. Groups are represented as strings of alphanumeric characters, and two groups are equal if and only if their respective strings are equal.
The four vertices of a tetrahedral molecule are numbered as follows. The topmost vertex is numbered 1, while the other three vertices are numbered 2, 3, and 4 in clockwise order starting from the rightmost vertex, like so:
Molecules can be subject to any rotation or reflection in 3D space. Two molecules match if and only if, for each vertex , the group at vertex of molecule 1 equals the group at vertex of molecule 2. Two molecules are identical if and only if one can be made to match the other after a series of zero or more rotations. Two molecules are mirror images if and only if one can be made to match the other after exactly one reflection.
Two molecules are called enantiomers if and only if one can be made into the mirror image of the other after a series of zero or more rotations, and they are not identical. Such molecules can have very different biological functions, so it is important to be able to identify them.
Given two tetrahedral molecules, please determine if they are enantiomers.
Input Specification
Two lines representing the two tetrahedral molecules, each containing four space-separated strings. String of line represents the group on vertex of molecule .
Each string in the input consists only of alphanumeric characters and is no more than 5 characters long.
Output Specification
Output YES
if the two molecules are enantiomers, and NO
otherwise.
Sample Input 1
F Br Cl H
H Cl F Br
Sample Output 1
YES
Explanation for Sample 1
The two molecules are:
It is impossible to rotate one molecule so that it matches the other. However, by rotating the second molecule so the F
is on the top and the Cl
is closest to us, the two molecules become mirror images:
Thus, the molecules are enantiomers.
Sample Input 2
COOH CH3 CH3 OH
COOH OH CH3 CH3
Sample Output 2
NO
Explanation for Sample 2
The two molecules are:
It is clear that one molecule is the mirror image of the other. However, the two molecules are also identical; by rotating the second molecule 180 degrees around the vertical axis, it can be made to match the first molecule:
Thus, the molecules are not enantiomers.
Sample Input 3
COOH H H H
COOH H H H
Sample Output 3
NO
Sample Input 4
COOH H OH CH3
F Br Cl H
Sample Output 4
NO
Comments