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: a = [5,7,5,7,7]
 
while True:
    n = int(input())
    if n == 0: break
    w = list(map(lambda x: len(input()) , range(n)))
    ans = 0
    for i in range(n):
        aa, g = 0, 0
        for j in range(i, n):
            g += w[j]
            if g == a[aa]:
                g =  0
                aa += 1
                if aa == 5:
                    ans = i+1
                    break
            elif g > a[aa]:
                break
        if ans:
            break
    print(ans)

Python: while True:
    n = int(input())
    if n == 0:
        break
    w = []
    go = 0
    flag = True
    x = 0
    count = 0
    for i in range(n):
        w.append(input())
    else:
        while count < 5:
            for i in range(x,n):
                go += len(w[i])
                if flag == True:
                    if go == 5:
                        flag = False
                        count += 1
                        go = 0
                    if go > 5:
                        x += 1
                        go = 0
                        count = 0
                        break
                if flag == False:
                    if go == 7 and count == 3:
                        flag = False
                        count += 1
                        go = 0
                    if go == 7:
                        flag = True
                        count += 1
                        go = 0
                    if go > 7:
                        x += 1
                        go = 0
                        count = 0
                        flag = True
                        break
                if count == 5:
                    break
    print(x + 1)

Python: target = [5,7,5,7,7]
while True:
    N = int(input())
    if N == 0: break
    src = [len(input()) for i in range(N)]
    ans = -1
    for i in range(N):
        j = i
        _t = target[::-1]
        while True:
            if src[j] > _t[-1]: break
            if src[j] == _t[-1]:
                _t.pop()
                if len(_t) == 0:
                    ans = i+1
                    break
            else:
                _t[-1] -= src[j]
            j += 1
        if ans >= 0:
            print(ans)
            break

Python: fs = [5, 7, 5, 7, 7]
while True:
    flag = 0
    n = int(input())
    if n == 0:
        quit()
    w = []
    for i in range(n):
        w.append(len(input()))
    for i in range(len(w)):
        k, temp = 0, 0
        for j in range(i, len(w)):
            temp += w[j]
            if temp > fs[k]:
                break
            elif temp == fs[k]:
                if k == 4:
                    print(i+1)
                    flag = 1
                    break
                else:
                    k += 1
                    temp = 0
        if flag == 1:
            break

Python: s = [5,7,5,7,7]


def solve(n):
    num = [len(input()) for _ in range(n)]

    for i in range(n):
         c = 0
         k = 0
         for j in range(i,n):
             c+= num[j]
             if c==s[k]:
                 k+=1
                 c = 0
                 if k == 5:
                     print(i+1)
                     return
             if c > s[k]:
                 break


while 1:
    n = int(input())
    if n == 0:
        break
    solve(n)

Python: while True:
    n = int(input())#文字列の量
    if n == 0:
        break
    w = list()#文字用
    for i in range(0, n):#入力
        w.append(input())

    for j in range(1, n+1):#始めの文字の場所
        ck = 0
        co = 0
        p = 0
        t = ""
        for k in range(j-1,50):#５７５７７チェック用
            #print(k)
            if co == 0 or co == 2:#５の場所
                if ck < 5:#五以下
                    #print("<")
                    ck = ck + len(w[k+p])#文字増やす
                elif ck == 5:#ピッタリになったら
                    #print("==")
                    co = co + 1#次に移る
                    ck = 0
                    p = p-1
                else:#オーバーしたら
                    #print(">")
                    break
            else:
                if ck < 7:
                    #print("<7")
                    ck = ck+len(w[k+p])
                    #print("      " ,ck)
                elif ck == 7:
                    #print("==7")
                    co = co+1
                    ck = 0
                    p = p-1
                    if co == 5:
                        t = "fin"
                        break
                else:
                    #print(">7")
                    break

        print(j)
        if t == "fin":
            break
    #print("over")

Python: ans_list = []

def judge(array):
    res = 0
    cnt = 0
    st = [5,7,5,7,7,400]
    for a in array:
        res += len(a)
        if res > st[cnt]:
            return False
        if res == st[cnt]:
            cnt += 1
            res = 0
    if cnt == 5:
        return True

while True:
    n = int(input())
    if n == 0:
        break
    W = [input() for _ in range(n)]
    for i in range(n):
        part = W[i:]
        if judge(part):
            ans = i + 1
            break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Python: while True:
    n = int(input())
    if n == 0:
        break
    else:
        phlist=[]
        phflag=0
        for i in range(n):
            phlist.append(input())

        for i in range(len(phlist)-4):
            cur=0
            state=0
            for j in range(i, len(phlist)):
                s = phlist[j]
                cur+=len(s)
                if state==0 and cur<5:
                    continue
                elif state==0 and cur==5:
                    cur=0
                    state=1
                elif state==1 and cur<7:
                    continue
                elif state==1 and cur==7:
                    cur=0
                    state=2
                elif state==2 and cur<5:
                    continue
                elif state==2 and cur==5:
                    cur=0
                    state=3
                elif state==3 and cur<7:
                    continue
                elif state==3 and cur==7:
                    cur=0
                    state=4
                elif state==4 and cur<7:
                    continue
                elif state==4 and cur==7:
                    print(i+1)
                    phflag=1
                    break

            if phflag:
                break