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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int ans,table[41],n;

struct Info{
	Info(int arg_start,int arg_grade,int arg_tmp){
		start = arg_start;
		grade = arg_grade;
		tmp = arg_tmp;
	}
	Info(){
		start = grade = tmp = 0;
	}
	int grade,tmp,start;
};

void recursive(int index,Info info){

	if(info.grade == 5){
		ans = min(ans,info.start);
		return;
	}

	if(index == n+1)return;

	switch(info.grade){
	case 0: //5
		if(table[index]+info.tmp < 5){
			recursive(index+1,Info(info.start,0,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 5){
			recursive(index+1,Info(info.start,1,0));
		}else{
			return;
		}
		break;
	case 1: //7
		if(table[index]+info.tmp < 7){
			recursive(index+1,Info(info.start,1,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 7){
			recursive(index+1,Info(info.start,2,0));
		}else{
			return;
		}
		break;
	case 2: //5
		if(table[index]+info.tmp < 5){
			recursive(index+1,Info(info.start,2,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 5){
			recursive(index+1,Info(info.start,3,0));
		}else{
			return;
		}
		break;
	case 3: //7
		if(table[index]+info.tmp < 7){
			recursive(index+1,Info(info.start,3,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 7){
			recursive(index+1,Info(info.start,4,0));
		}else{
			return;
		}
		break;
	case 4: //7
		if(table[index]+info.tmp < 7){
			recursive(index+1,Info(info.start,4,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 7){
			recursive(index+1,Info(info.start,5,0));
		}else{
			return;
		}
		break;
	}
}


void func(){
	int length;
	char tmp[11];

	for(int loop = 1; loop <= n; loop++){
		scanf("%s",tmp);

		for(length = 0; tmp[length] != '\0'; length++);

		table[loop] = length;
	}

	for(int i = 1; i <= n-4; i++){
		recursive(i,Info(i,0,0));
	}

	printf("%d\n",ans);
}


int main(){

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		ans = 1000000;
		func();
	}
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
    constexpr int len[5] = {5, 7, 5, 7, 7};
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> l(n);
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            l[i] = s.size();
        }

        for (int i = 0; i < n; i++) {
            int ind = 0;
            int sum = 0;
            for (int j = i; j < n; j++) {
                if (ind == 5) {
                    break;
                }
                sum += l[j];
                if (sum > len[ind]) {
                    break;
                } else if (sum == len[ind]) {
                    ind++;
                    sum = 0;
                }
            }
            if (ind == 5) {
                cout << i+1 << endl;
                break;
            }
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
	for(int n; cin >> n, n;){
		vector<string> in(n);
		for(auto & e : in) cin >> e;

		int res = -1;
		rep(i, n){
			int idx = 0;
			int T[5] = {5, 7, 5, 7, 7};

			[&]{
				rep(j, i, n){
					int & e = T[idx];
					e -= in[j].size();
					if(e < 0) return;
					if(e == 0) idx++;

					if(idx == 5) break;
				}

				res = i + 1;
			}();

			if(res != -1) break;
		}

		cout << res << endl;
	}

    return 0;
}