Haiku
InterviewTime limit1sMemory limit512 MB
Given a set of syllables, decide whether the three input phrases can each be split into syllables so their syllable counts are 5, 7, and 5.
- Level
Medium6 of 10
- Topics
- Dynamic programming, String, Hash map, Trie
- Solved
- No attempts yet
Problem
A haiku is a Japanese form of poetry. It consists of three phrases of , and syllables each.
Once a year, HiQ has a haiku contest, where employees submit their best poems. The poems are then judged on a wide range of aspects, such as
- creativity
- simplicity
- beauty
- whether the poem is actually a haiku
This last point turned out to be quite a challenge for the judges. Many problems arose when half the judges indexed syllables starting at and the other half at .
Can you help the judges determine whether a submitted poem is a haiku, given a set of syllables? Note that there may exist multiple decompositions of a single word in the poem into syllables. In this case, you should determine whether some decomposition is a haiku.
Input
The first line of input contains a single integer , the number of syllables. The next line contains words separated by spaces (the syllables). Each syllable contains at most lowercase letters a-z.
Then, three lines containing the poem follow. Each line contains a (non-empty) list of words separated by spaces, representing a phrase. The words contain only lowercase letters a-z. The length of each line is at most characters (including spaces).
It is guaranteed that there exists at least one decomposition of the poem into the given syllables.
Output
Output "haiku" if the given poem is a haiku, and "come back next year" otherwise (without the quotes).