Short Phrase
InterviewTime limit1sMemory limit256 MB
Find the earliest starting word of a contiguous block whose words split into five groups totaling 5, 7, 5, 7, and 7 letters.
- Level
Easy3 of 10
- Topics
- Simulation, Brute force
- Solved
- No attempts yet
Problem
A Short Phrase, also called a Tanku, is a fixed verse inspired by the Japanese poetry forms Tanka and Haiku. It is a sequence of words, each made only of the lowercase letters 'a' to 'z', and it must satisfy the following condition.
(The condition for a Short Phrase)
The sequence of words can be divided into five sections such that the total number of letters in the words of the first section is 5, that of the second is 7, and those of the rest are 5, 7 and 7, respectively.
Here is an example of a Short Phrase.
do the best
and enjoy today
at acm icpc
In this example the nine words divide into five sections: (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", (5) "acm" and "icpc". Their letter counts are 5, 7, 5, 7 and 7 in this order, so the condition holds.
The Short Phrase collection published by your company has received many contributions. Because of an accident, irrelevant text was added at the beginning and at the end of some of them. Write a program that finds the Short Phrase inside a sequence of words that may carry an irrelevant prefix, an irrelevant suffix, or both.
Input
The input consists of several datasets, each in the following format.
n
w1
...
wn
n is the number of words, a positive integer not exceeding 40. wi is the i-th word and consists only of the lowercase letters 'a' to 'z'. The length of each word is between 1 and 10, inclusive. Every dataset contains a Short Phrase.
The end of the input is a line holding a single zero.
Output
For each dataset print one line holding i, where wi is the first word of the Short Phrase. When a dataset contains more than one Short Phrase, print the one that starts earliest.