ECOO '15 R1 P4 - Neanderthal Numbers

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

Lefty the Neanderthal is in the process of discovering counting for the first time in history. Using the fingers of his right hand, Lefty assigns each of them a name. he names the first finger "ook", the second finger "ook ook", the third "oog", the fourth "ooga" and the fifth "ug". For many says this is enough, allowing Lefty to quickly express a count to his colleagues in words that are more precise than "many" and "lots".

One day lefty was stuck… after he counted ug shiny beads he realized he had more! So he took a look at his right foot and started naming his toes! He called his toes "mook", "mook mook", "oogam", "oogum" and "ug ug". Now lefty can count all kinds of things!

Number Neanderthal Number Word
0 No such concept
1 ook
2 ook ook
3 oog
4 ooga
5 ug
6 mook
7 mook mook
8 oogam
9 oogum
10 ug ug

The input will contain 10 test cases. Each test case consists of a single line of text with N (1 \le N \le 50) Neanderthal number words. The words are not separated by spaces. You must parse each line and print out (on a single line) the number of possible sequences of Neanderthal numbers that can be represented by a Neanderthal person speaking the words aloud (for example the string "oogamookoogumook" could be "ooga mook oogum ook" meaning "4 6 9 1" or "oogam ook oogum ook" meaning "8 1 9 1".

Note that the sample input below only contains 2 test cases, but the real data files will contain 10.

Sample Input


Sample Output


Educational Computing Organization of Ontario - statements, test data and other materials can be found at


  • 10
    nullptr  commented on April 3, 2015, 3:22 p.m.

    A single test case may actually contain up to 100 Neanderthal number words.