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>
using namespace std;
int main(){
    while(1){
        int N;
        cin >> N;
        if(!N) break;
        string s[N];
        for(int i = 0; i < N; i++) cin >> s[i];
        const vector<int> po = {5, 7, 5, 7, 7};
        for(int i = 0; i < N; i++){
            int index = 0;
            vector<int> yo = po;
            for(int j = i; j < N; j++){
                if(index == 5) break;
                if(yo[index] < s[j].size()) break;
                yo[index] -= s[j].size();
                if(!yo[index]) index++;
            }
            if(index == 5){
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define f(X) for(c=0;c<X;c+=v[p--]);if(c-X)goto L;
main(){for(char n,v[99],s,p,c;p=s=n=atoi(gets(v));){for(;p;v[p--]=strlen(gets(v+70)));L:p=s--;f(5)f(7)f(5)f(7)f(7)puts(itoa(n-s));}}

C++: #include<iostream>
#include<string>
using namespace std;

int main(){
	while(1){
		int n;
		cin>>n;

		if(n==0)
			break;
		
		int len[40];
		for(int i=0;i<n;i++){
			string w;
			cin>>w;

			len[i]=w.size();
		}

		for(int i=0;i<n;i++){
			bool flg=false;
			int sta=0;
			int sum=0;
		
			for(int j=i;j<n;j++){
				sum+=len[j];

				if(sum==5||sum==12||sum==17||sum==24||sum==31){
					sta++;
				}

				if(sta==5){
					flg=true;
					break;
				}
				else if(sum>=31){
					break;
				}
			}
			
			if(flg){
				cout<<i+1<<endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S[1000]; int  n, p[5] = { 5,12,17,24,31 };
int main() {
    while (true) {
        cin >> n; if (n == 0)break;
        for (int i = 0; i < n; i++)cin >> S[i];
        for (int i = 0; i < n; i++) {
            int cnt = 0, sum = 0;
            for (int j = i; j < n; j++) {
                if (cnt >= 5)continue;
                sum += S[j].size();
                if (p[cnt] == sum)cnt++;
            }
            if (cnt == 5) { cout << i + 1 << endl; break; }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	int n;
			int word=0;
int first=0;
	while(cin>>n){


		if(n==0)break;

		// int array[4]={5,7,5,7,7};

		vector<int> v1;
		vector<string> v2;

		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v2.push_back(s);

		}

		for(int i=0;i<n;i++){
			string tmp=v2[i];
			int a=tmp.size();
			v1.push_back(a);
		}

		// for(int i=0;i<n;i++){
		// 	cout<<v1[i]<<endl;
		// }

		// cout<<endl;

		for(int i=0;i<n;i++){
			word=0;
			first=i+1;
			// cout<<"FIRST="<<first<<endl;
			int tmp=0;
			

			if(5>=tmp){
				for(int j=i;j<n;j++){

					

					tmp+=v1[j];
					// cout<<tmp<<" "<<word<<endl;
					if(word==0){
						if(tmp==5){
							word++;
							tmp=0;
						}else if(tmp>5){
							
							break;
						}

					}else if(word==1){
						
						if(tmp==7){
							word++;
							tmp=0;
						}else if(tmp>7){

							break;
						}

					}else if(word==2){

						if(tmp==5){
							word++;
							tmp=0;
						}else if(tmp>5){
							break;
						}

					}else if(word==3){
						if(tmp==7){
							tmp=0;
							word++;
						}else if(tmp>7){
							break;
						}

					}else if(word==4){
						if(tmp==7){
							word++;
							break;
						}else if(tmp>7){
							break;
						}
					}
				}
			}

			if(word==5){
				cout<<first<<endl;
				break;
			}	
		}
	
		

	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
void solve(int N){
    vector<int> V(N);
    rep(i,0,N){
        string s;
        cin >> s;
        V[i] = s.size();
    }
    int arr[] = {5,7,5,7,7};
    rep(i,0,N){
        int sum = 0, cur = 0;
        bool ok = 1;
        rep(j,i,N){
            sum += V[j];
            if(sum > arr[cur]){
                ok = 0;
                break;
            }else if(sum == arr[cur]){
                cur++;
                sum = 0;
            }
            if(cur == 5)break;
        }
        if(!ok || cur != 5)continue;
        cout << i+1 << endl;
        return;
    }
}
main(){
    int N;
    cin >> N;
    while(N){
        solve(N);
        cin >> N;
    }
}

C++: #include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<climits>
#include<string.h>
using namespace std;

int main(){
    int n;
    while(cin>>n,n){;
    vector<int>v;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        v.push_back(s.length());
    }
    int nee[5]={5,7,5,7,7};
    for(int i=0;i<v.size();i++){
        int cur=0,ne=0,no=0;
        for(int j=i;j<v.size();j++){
            //cout<<i<<" "<<j<<" "<<cur<<" "<<ne<<endl;
            if(cur+v[j]>nee[ne]){
                break;
            }
            if(cur+v[j]==nee[ne]){
                if(ne==4){
                    cout<<i+1<<endl;
                    goto ne;
                } else {
                    cur=0;ne++;
                }
            } else {
                cur+=v[j];
            }
        }
    }
        ne:;}
}