Wolves and Proper Words
InterviewTime limit2sMemory limit512 MB
Given a word of w, o, l, f, decide whether it is a concatenation of blocks w^n o^n l^n f^n for n >= 1.
Problem
The wolf country uses these rules to decide whether a word is proper.
- For a positive integer , the word made of "w" repeated times, then "o" repeated times, then "l" repeated times, then "f" repeated times is proper.
- The concatenation of two proper words is proper.
- Only the words built by the two rules above are proper.
Here are some examples.
- "wolf", "wwoollff" and "wwwooolllfff", all built by rule 1, are proper.
- "wolfwwoollff", built by rule 2, is proper.
- "wolfwwoollffwolf", built by applying rule 2 twice, is proper.
- "wfol" is not proper because the letters are in the wrong order.
- "wwolfolf" is not proper because another string sits in the middle of a word.
- "wwwoolllfff" is not proper because "o" appears only twice.
Given one word, decide whether it is proper.
Input
The first line contains a word. The word consists only of "w", "o", "l" and "f", and its length is between 1 and 50.
Output
Print 1 if the given word is proper, and 0 otherwise.