Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		s := make([]string, n)
		for i := 0; i < n; i++ {
			s[i] = io.NextLine()
		}
		w := [5]int{5, 7, 5, 7, 7}
		ans := 0
	OUTER:
		for i := 0; i < n; i++ {
			cnt, wc := 0, 0
			for j := i; j < n; j++ {
				wc += len(s[j])
				if wc == w[cnt] {
					cnt++
					wc = 0
					if cnt == 5 {
						ans = i + 1
						break OUTER
					}
				} else if wc > w[cnt] {
					break
				}
			}
		}
		io.Println(ans)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<string> s(n);
            vector<int> A(n);
            REP(i, n) cin >> s[i];
            REP(i, n) A[i] = s[i].size();
            int ans;
            bool ok = false;
            REP(i, n + 1){
                int a = 0;
                bool tanka =  false;
                int now = 0; 
                FOR(j, i, A.size()){
                    a += A[j];
                    if(a > 7) break;
                    if((now == 0 or now == 2) and a == 5){
                        now++;
                        a = 0;
                    }
                    if((now == 1 or now == 3) and a == 7){
                        now++;
                        a = 0;
                    }
                    if(now == 4 and a == 7){
                        ok = true;
                        ans = i + 1;
                        break;
                    }
                }
                if(ok) break;
            }
            cout << ans << endl;
        }
    }
}

C++: #include<bits/stdc++.h>
int i,j,p,n,q,a[9]={5,7,5,7,7,-1},d[50];char s[50];
main(){for(;scanf("%d\n",&n),n;){for(i=0;i<n;)d[i++]=strlen(gets(s));
for(i=j=0;j<6;i++)for(p=i,j=q=0;q>=0;)for(q=a[j++];q>0;q-=d[p++]);
printf("%d\n",i);
}}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int n;

int main(){
	while(1){
		cin>>n;
		if(n==0) break;
		vi a(n);
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			a[i]=s.size();
		}
		int b[5]={5,7,5,7,7};
		for(int i=0;i<n;i++){
			int I=i;
			bool B=1;
			for(int j=0;j<5;j++){
				int t=0;
				while(t<b[j]&&I<n) t+=a[I++];
				if(t!=b[j]){
					B=0;
					break;
				}
			}
			if(B){
				cout<<i+1<<endl;
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
 
int main() {
    int n;
    while(cin >> n, n) {
        vector<int> S(n+1);
        string str;
        cin >> str;
        S[0] = 0;
        S[1] = str.size();
        for(int i=2; i<=n; ++i) {
            cin >> str;
            S[i] = S[i-1] + str.size();
        }
        int tmp[5] = {5, 7, 5, 7, 7};
        int ret = 0;
        bool finished = false;
        for(int i=0; i<=n; ++i) {
            if(finished) break;
            int current=i;
            int current_haiku = 0;
            int offset=1;
            ret = i;
            while(current+offset <= S.size()) {
                if(S[current+offset] - S[current] == tmp[current_haiku]) {
                    current += offset;
                    offset = 1;
                    current_haiku++;
                    if(current_haiku == 5) {
                        finished = true;
                        break;
                    }
                } else if(S[current+offset] - S[current] > tmp[current_haiku]) {
                    break;
                } else {
                    offset++;
                }
            }
        }
        cout << ret+1 << endl;
    }
}