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++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;

int main()
{
	int n;
	while (cin >> n&&n)
	{
		vs a;
		FOR(i, n)
		{
			string s; cin >> s;
			a.push_back(s);
		}
		FOR(i, n)
		{
			int s[5] = { 5,7,5,7,7 };
			int now = i;
			bool ok = true;
			for (int j = 0; j < 5; j++)
			{
				for (; now < n; now++)
				{
					if (s[j] == 0)break;
					if (s[j] < 0)
					{
						ok = false;
						break;
					}
					s[j] -= a[now].size();
				}
			}
			for (int j = 0; j < 5; j++)
			{
				if (s[j] != 0)ok = false;
			}
			if (ok)
			{
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    while(cin >> n, n){
	int len[] = {5, 7, 5, 7, 7};
	string w[44];
	for(int i = 0; i < n; i++) cin >> w[i];
	int ans = 0;
	for(int i = 0; i < n; i++){
	    int cnt = 0, idx = 0;
	    for(int j = i; j < n; j++){
		cnt += w[j].size();
		if(cnt == len[idx]){
		    cnt = 0, idx++;
		    if(idx == 5) break;
		}else if(cnt > len[idx]){ idx = -1; break;}
	    }
	    if(idx == 5){ ans = i; break;}
	}
	cout << ans+1 << endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
bool check(int x, vector<string>v) {
	int table[] = { 5,7,5,7,7 };
	int idx = 0, tmp = 0;
	rep(i, x, v.size()) {
		tmp += v[i].size();
		if (tmp == table[idx]) {
			idx++;
			tmp = 0;
		}
		else if (tmp > table[idx]) {
			return false;
		}
		if (idx == 5) {
			return true;
		}
	}
	return false;
}
signed main() {
	int n;
	while (cin >> n, n) {
		vector<int>v; vector<string>s; v.push_back(0);
		rep(i, 0, n) {
			string t;
			cin >> t;
			s.push_back(t);
			v.push_back(t.size());
		}
		rep(i, 1, n + 1) {
			v[i] += v[i - 1];
		}
		int ans;
		for (ans = 0; ans < n + 1; ans++) {
			rep(j, ans, n + 1) {
				int x = v[j] - v[ans];
				if (x > 31)continue;
				else if (x == 31 && check(ans, s))goto there;
			}
		}

	there:; cout << ans + 1 << endl;
		dumpc(v);

	}
	return 0;
}

C++: i,j,k,L[99];main(n){for(;scanf("%d",&n)*n;i=j=k=!printf("%d\n",j)){for(;n--;scanf("%*s%n",L+i++));for(;k<7;)for(n=j++,k=i=1;i>0;)for(i=k++>5?0:k-2&&k-4?8:6;i>1;i-=L[n++]);}}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<string> words;
            for (int i=0;i<n;i++) {
                cin>>s;
                words.emplace_back(s);
            }
            for (int j=0;j<words.size();j++) {
                std::deque<int> num{5,7,5,7,7};
                int itr=0;
                int now=j;
                while (itr<5) {
                    if (words[now].size()<=num[itr]) {
                        num[itr]-=words[now].size();
                        if (num[itr]==0) {
                            itr++;
                            now++;
                        } else if (num[itr]>0) {
                            now++;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (itr==5) {
                    cout<<j+1<<endl;
                    break;
                }
            }
        }
    }
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<string> str(n);
        for(int i=0; i<n; i++){
            cin >> str[i];
        }

        for(int i=0; i<n; i++){
            int sp[5] = {5,7,5,7,7};
            int now = 0;
            for(int j=0; j<n; j++){
                sp[now] -= str[i+j].length();
                if(sp[now]<0) break;
                if(sp[now]==0) now++;
                if(now==5){
                    cout << i+1 << endl;
                    i=1e9;
                    break;
                }
            }
        }
    }   
    return 0;
}