Under construction

Still being built. Things may change

Short Phrase

Interview

Time limit1sMemory limit256 MB

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

Examples2

  1. Example 1

    Input
    9
    do
    the
    best
    and
    enjoy
    today
    at
    acm
    icpc
    14
    oh
    yes
    by
    far
    it
    is
    wow
    so
    bad
    to
    me
    you
    know
    hey
    15
    abcde
    fghijkl
    mnopq
    rstuvwx
    yzz
    abcde
    fghijkl
    mnopq
    rstuvwx
    yz
    abcde
    fghijkl
    mnopq
    rstuvwx
    yz
    0
    
    Expected output
    1
    2
    6
    
  2. Example 2

    Input
    5
    aaaaa
    bbbbbbb
    ccccc
    ddddddd
    eeeeeee
    0
    
    Expected output
    1