This page is still under construction.

Parts of this page are still being built. What you see may change.

Wolves and Proper Words

Interview

Time limit2sMemory limit512 MB

Summary
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.
Level

Medium4 of 10

Topics
Stack, Greedy
Solved
No attempts yet

Problem

The wolf country uses these rules to decide whether a word is proper.

  1. For a positive integer nn, the word made of "w" repeated nn times, then "o" repeated nn times, then "l" repeated nn times, then "f" repeated nn times is proper.
  2. The concatenation of two proper words is proper.
  3. 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.

Examples6

  1. Example 1

    Input
    wolf
    
    Expected output
    1
    
  2. Example 2

    Input
    wwolfolf
    
    Expected output
    0
    
  3. Example 3

    Input
    wwoollff
    
    Expected output
    1
    
  4. Example 4

    Input
    wwwooolllfff
    
    Expected output
    1
    
  5. Example 5

    Input
    wolfwwoollff
    
    Expected output
    1
    
  6. Example 6

    Input
    wolfwwoollffwolf
    
    Expected output
    1