Every uppercase letter must start a new word, so the split is unique.
Compare each complete word with the five designated words and record its presence in a bitmask. Process the final word too. Answer YES exactly when at least two bits are set. Substring matches and repeated occurrences are not distinct complete words.
Each character is examined a constant number of times: time, space including the input, and auxiliary space.
There is one full-constraints subtask. The separate naive implementation stores the words and uses a set to remove duplicates. It also passes the full task in time and space.
Solution written by GPT