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: # coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

while True:
    N = int(input())
    
    if N == 0:
        break
    
    S = []
    ans = None
    flag = False

    for i in range(N):
        S.append(len(input()))

    #print(S)

    for i in range(N):
        for j in range(i, N):
            A = S[i:j+1] 
            C = [5, 12, 17, 24, 31]
            #print(sum(A))
            if sum(A) == 31:
                for k in A:
                    C = [x-k if x != 0 else x for x in C]
            if sum(C) == 0:
                ans = i
                flag = True
                break
        if flag:
            break

    print(ans+1)

Python: while True :
    n = int(input())
    
    if(n == 0) :
        break
    
    else :
        S = [len(input()) for i in range(n)]
        T = [5, 7, 5, 7, 7]
        ans = 0
        
        for i in range(n) :
            s = 0
            w = 0
            for j in range(i, n) :
                s += S[j]
                if(s == T[w]) :
                    s = 0
                    w += 1
                    if(w == 5) :
                        ans = i + 1
                        break
                    else :
                        pass
                elif(s > T[w]) :
                    break
                else :
                    pass
            if(ans != 0) :
                break
            else :
                pass
        print(ans)

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

Python: class CheckError(Exception):
    pass

def check(wclist, count):
    c = 0
    while True:
        c += wclist.pop(0)
        if c == count:
            return wclist
        elif c > count:
            raise CheckError

def tanku_check(wclist):
    for i in range(len(wclist)):
        try:
            wcl = wclist[:][i:]
            wcl = check(wcl, 5)
            wcl = check(wcl, 7)
            wcl = check(wcl, 5)
            wcl = check(wcl, 7)
            wcl = check(wcl, 7)
            return i+1
        except CheckError:
            pass

def main():
    while True:
        n = int(input().strip())
        if n == 0:
            break
        wclist = [len(input().strip()) for _ in range(n)]
        print(tanku_check(wclist))

if __name__ == '__main__':
    main()

Python: def check(word):
    l = 0
    step = 0
    for w in word:
        l += len(w)
        if step == 0 or step == 2:
            if l == 5:
                step += 1
                l = 0
            elif l > 5:
                return False
        elif step == 1 or step == 3:
            if l == 7:
                step += 1
                l = 0
            elif l > 7:
                return False
        elif step == 4:
            if l == 7:
                return True
    return False


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

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

    cnt = 0
    while word != []:
        cnt += 1
        if check(word):
            break
        word.pop(0)

    print(cnt)

Python: import sys


from inspect import currentframe


def pri(*args):
    names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    # print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))


def solve(n, w_count):
    pri("solve")
    right_count = [5, 7, 5, 7, 7]

    for i in range(n):
        locate = 0
        way_count = 0
        pri(i)

        for w_i in w_count[i:]:
            if right_count[locate] == w_i + way_count:
                locate += 1
                way_count = 0
            elif right_count[locate] > w_i + way_count:
                way_count += w_i
            else:
                break

            if locate == 5:
                print(i + 1)
                return


    return


if __name__ == '__main__':
    while True:
        n_input = int(input())
        if n_input == 0:
            break
        w_count_imput = [len(input()) for i in range(n_input)]

        solve(n_input, w_count_imput)