#P4290. Identifying the Original Toy Name
Identifying the Original Toy Name
Identifying the Original Toy Name
A person has a set of toys and wishes to name them in a unique way. He starts by choosing any one letter from the set \(\{W, I, N, G\}\) as the toy’s base name. Then, according to his preference, he may replace any one letter in the name with any two letters (each chosen independently from \(\{W, I, N, G\}\)), thus extending the name arbitrarily.
Given a possibly long toy name resulting from a sequence of such replacements, determine which letter(s) from \(\{W, I, N, G\}\) could have been chosen as the original base name.
Note: The process starts with a single letter. If no replacement is applied (i.e. the toy name is of length 1), then the toy name is exactly the base letter. Otherwise, since each replacement allows completely arbitrary letters, any initial letter can lead to any longer string. In other words, if the given name has a length greater than 1, the answer is always "WING" (all possible starting letters in the set). Otherwise, if the name is exactly one letter long, then that letter is the only possibility.
inputFormat
The input consists of a single line containing a string \(S\) that represents the toy's name. \(S\) is composed only of the uppercase letters \(W\), \(I\), \(N\), and \(G\).
outputFormat
Output a string representing all possible base letters from which the name could have originated. If \(|S| = 1\), output \(S\) itself; if \(|S| > 1\), output the string "WING".
sample
W
W