Go: // Short Phrase(短句)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		n := nextInt(sc)
		if n == 0 {
			break
		}

		var words []string
		for i := 0; i < n; i++ {
			words = append(words, nextString(sc))
		}

		res := 0
		for i := 0; i < n; i++ {
			tmpWords := words[i:]
			ok := checkRule(tmpWords, 0)
			if ok {
				res = i + 1
				break
			}
		}

		fmt.Println(res)
	}
}

var rule = [5]int{5, 7, 5, 7, 7}

func checkRule(words []string, depth int) bool {
	var shortPhrase = ""
	var i = depth

	if depth == 5 {
		return true
	}

	for len(words) > 0 {
		shortPhrase += words[0]
		words = words[1:]

		if rule[i] == len(shortPhrase) {
			return checkRule(words, i+1) // 短句のルールを満たしたので次の文節へ
		} else if rule[i] < len(shortPhrase) {
			return false // 文節の語数オーバー
		}
	}

	return false // 文節を満たす単語が足りない
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

Python: def main():
    while True:
        n = int(input().strip())

        if n == 0:
            break

        phrases = []
        for _ in range(n):
            word = input().strip()
            phrases.append(word)

        PHRASE_LEN = [5,7,5,7,7]
        found_flag = False

        for i in range(n):
            acc_len = 0
            phrase_idx = 0
            for j in range(i, n):
                acc_len += len(phrases[j])

                if acc_len == PHRASE_LEN[phrase_idx]:
                    if phrase_idx == (len(PHRASE_LEN)-1):
                        found_flag = True
                        break

                    acc_len = 0
                    phrase_idx += 1
                elif acc_len > PHRASE_LEN[phrase_idx]:
                    break

            if found_flag:
                print(i+1)
                break

if __name__ == "__main__":
    main()

Python: def es(k,le):
    i=k
    x=0
    while le>x:
        x+=len(l[i])
        i+=1
    if le==x:return i
    else: return 0



while True:
    n=int(input())
    if n==0:break
    l=[input() for _ in range(n)]
    ans=1
    for i in range(n):
        k=i
        k=es(k,5)
        if k==0:continue
        k=es(k,7)
        if k==0:continue
        k=es(k,5)
        if k==0:continue
        k=es(k,7)
        if k==0:continue
        k=es(k,7)
        if k==0:continue
        print(ans+i)
        break

Python: while True:
    n = int(input())
    if n == 0:
        break
    count = [0] * n
    for i in range(n):
        count[i] = len(input())
    for i in range(n-4):
        ind = i
        fin = True
        for tmp in [5, 7, 5, 7, 7]:
            while tmp > 0 and ind < n:
                tmp -= count[ind]
                ind += 1
            if tmp != 0:
                fin = False
                break
        if fin:
            print(i+1)
            break

Python: while True:
    n = int(input())
    if n == 0:
        break
    else:
        words = []
        for i in range(n):
            w = input()
            words.append(w)
        check = [5, 7, 5, 7, 7]
        flag = 0
        count = 1
        while True:
            w_len = 0
            for i in range(count-1, n):
                w_len += len(words[i])
                if w_len == check[flag]:
                    flag += 1
                    w_len = 0
                elif w_len > check[flag]:
                    flag = 0
                    break
                if flag == 5:
                    print(count)
                    break
            if flag == 5:
                break
            else:
                count += 1

Python: p = [5, 7, 5, 7, 7]
while True:
    n = int(input())
    if n == 0:
        break
    word = [input() for _ in range(n)]
    flag = False
    for i in range(len(word)):
        ip = 0
        phrase = ["" for _ in range(len(p))]
        if flag:
            break
        for j in range(i, len(word)):
            if len(phrase[ip]+word[j]) == p[ip]:
                phrase[ip] += word[j]
                ip += 1
            else:
                phrase[ip] += word[j]
                if len(phrase[ip]) > p[ip]:
                    break
                if len(phrase[ip]) == p[ip]:
                    ip += 1
            if len(phrase[-1]) == 7:
                print(i+1)
                flag = True
                break

Python: "短句"
# 各単語を始まりとして57577が作れるかどうか
while True:
    n = int(input())
    if n == 0:
        break
    words = [str(input()) for _ in range(n)]

    tanku = [5, 7, 5, 7, 7]
    target = 0
    ans = 0
    for i in range(n):
        now_len = 0
        # print("i : ", i)
        for j in range(i, n):
            now_len += len(words[j])
            # print(words[j], now_len)

            if now_len == tanku[target]:
                now_len = 0
                target += 1
            elif now_len < tanku[target]:
                pass
            elif now_len > tanku[target]:
                target = 0
                break

            if target == 5:
                break
        if target == 5:
            ans = i
            break
    print(ans+1)

Python: r = [5, 7, 5, 7, 7]
while True:
    n = int(input())
    if n == 0:
        break
    w = []
    for _ in range(n):
        w.append(len(input()))
    for j in range(n):
        i = j
        for k in r:
            s = 0
            while s < k:
                s = s + w[i]
                i = i + 1
            if s != k:
                break
        else:
            print(j+1)
            break

Python: # AOJ 1601: Short Phrase
# Python3 2018.7.13 bal4u

a = [5,7,5,7,7]

while True:
	n = int(input())
	if n == 0: break
	ans = 0
	w = [len(input()) for i in range(n)]
	for i in range(n):
		k = s = 0
		for j in range(i, n):
			s += w[j]
			if s == a[k]:
				s, k = 0, k+1
				if k == 5: ans = i+1; break
			elif s > a[k]: break
		if ans: break
	print(ans)