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;

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main(){
  vi p = {5, 12, 17, 24, 31};
  
  while(1){
    int n; cin >> n; if(n == 0) break;

    vs w(n); rep(i,n) cin >> w[i];
    vi l(n+1); rep(i,n) l[i+1] = sz(w[i]);
    rep(i,n) l[i+1] += l[i];

    rep(i,n){
      bool f = true;
      rep(j,5) if(not binary_search(all(l),p[j] + l[i])) f = false;
      if(f){
	cout << i + 1 << endl;
	break;
      }
    }
  }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<double,pair<string,int> > mypair;
string re(string a){
	for(int i=0;i<a.size();i++){
		a[i]='a'+('z'-a[i]);
	}
	return a;
	}
	string eq(string a){
		string b;
		for(int i=0;i<20;i++)
         b.push_back('A');
		for(int i=0;i<a.size();i++)
     b[i]=a[i];
		return b;
	}
int main(void){
	int n;
	while(1){
cin>> n;
if(n==0)break;
vector<string> l(n);
vector<int> p(n),a(n),b(n),c(n),d(n),e(n),f(n),s(n),m(n);
for(int i=0;i<n;i++)
cin>>l[i]>>p[i]>>a[i]>>b[i]>>c[i]>>d[i]>>e[i]>>f[i]>>s[i]>>m[i];
vector<mypair> q(n);
for(int i=0;i<n;i++){
	q[i].first=(double)(m[i]*f[i]*s[i]-p[i])/(a[i]+b[i]+c[i]+m[i]*(d[i]+e[i]));
	q[i].second.first=re(eq(l[i]));
	q[i].second.second=i;
}

sort(q.begin(),q.end(),greater<mypair>());

for(int i=0;i<n;i++){
cout<<l[q[i].second.second] <<endl;
}
cout<<'#'<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)continue;
using namespace std;
main(){
    for(int n,v[50],s,p,c;cin>>n,n;){
        for(s=1;s<n;s++){string t;cin>>t;v[s]=t.size();}
        for(s=p=1;;p=++s){f(5);f(7);f(5);f(7);f(7);cout<<s<<endl;break;}
    }
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
const int MOD = 1000000007;

int main() {
	int n;
	int c[] = {5, 7, 5, 7, 7};
	while (cin >> n, n) {
		vs w(n);
		REP(i, n) {
			cin >> w[i];
		}
		int ans = -1;
		REP(i, n) {
			int p = 0, t = 0;
			FOR(j, i, n - 1) {
				t += w[j].size();
				if (t == c[p]) {
					if (p == 4) {
						ans = i+1;
						break;
					}
					else {
						p++;
						t = 0;
					}
				}
				else if (t > c[p]) {
					break;
				}
			}
			if (ans != -1) {
				break;
			}
		}
		cout << ans << endl;
	}
}