#K35062. Appendable Substrings
Appendable Substrings
Appendable Substrings
You are given a string \(S\). Determine if \(S\) can be constructed by starting with an empty string and repeatedly appending any one of the following substrings:
apple
banana
321
xyz
You may use each substring any number of times (including zero). Output YES
if it is possible to construct the string exactly, otherwise output NO
.
Note: The empty string is considered valid and should output YES
.
inputFormat
The input consists of a single line that contains the string \(S\) (which may be empty). \(S\) will only contain alphanumeric characters.
outputFormat
Output a single line with YES
if the string can be formed by concatenating one or more of the allowed substrings; otherwise, output NO
.
321applebanana
YES