#K62112. Consistent Teleportation Pattern
Consistent Teleportation Pattern
Consistent Teleportation Pattern
You are given three strings: s
, t
, and u
. They represent a series of teleportation modifications. A transformation from one string to the next (i.e. from s
to t
and from t
to u
) is considered consistent if there exists a one-to-one mapping between the corresponding characters of the two strings.
More formally, for two strings X and Y of the same length, the transformation from X to Y is valid if for each index i the mapping X[i] -> Y[i]
is consistent (i.e. if a character in X has been already mapped, it must always map to the same character in Y, and no two different characters in X map to the same character in Y).
The task is to determine if both transformations – from s
to t
and from t
to u
– are valid according to the described rules. Print Yes
if both are valid, and No
otherwise.
Note: If the transformation is valid, then each mapping must be a bijection between the characters of the source and target strings.
inputFormat
The input is given on stdin as a single line containing three space-separated strings s
, t
, and u
. All strings have the same length.
outputFormat
Output a single line on stdout containing either Yes
if the transformations from s
to t
and t
to u
are both consistent, or No
otherwise.
abc bcd def
Yes