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 <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll t[5] = {5,7,5,7,7};

int main(){
	while(1){
		ll n; cin >> n;
		if(!n) break;
		vs s(n);
		rep(i,n) cin >> s[i];
		rep(i,n){
			ll now = 0;
			ll rest = 5;
			for(ll j=i; j<n; j++){
				if(s[j].size() > rest) break;
				else if(s[j].size() == rest){
					now++;
					if(now < 5) rest = t[now];
				}else{
					rest -= s[j].size();
				}
				if(now == 5) break;
			}
			if(now == 5){
				cout << i+1 << endl;
				break;
			}
		}
	}
}

C++: #include<bits/stdc++.h>
#define N 45
using namespace std;
int n,l[N],L[N],ans;
int d[5]={5,7,5,7,7};
string s;

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++){
      cin>>s,l[i]=s.size();
      L[i]=L[i-1]+l[i];
    }
    ans=0;
    for(int i=1;i<=n-6;i++){
      int idx=0,s=i;
      for(int j=i;j<=n;j++){
	if(L[j]-L[s-1]==d[idx])idx++,s=j+1;
	if(!ans&&idx==5)ans=i;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int haiku[5] = {5,7,5,7,7};
  int n;
  while(cin>>n,n){
    vector<string> vs(n);
    FOR(i,0,n) cin >> vs[i];
    FOR(i,0,n) {
      int j = 0;
      int k = i;
      while(k < n && j < 5) {
        int len = 0;
        while(len < haiku[j] && k < n) {
          len += vs[k].length();
          k++;
        }
        if(len != haiku[j]) break;
        j++;
      }
      if(j == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}

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

using namespace std;

int main(){
    int n;
    while(cin>>n,n){
        vector<int>v(n);
        for(int i=0;i<n;++i){
            string s;
            cin>>s;
            v[i]=s.length();
        }
        for(int i=0;i<n;++i){
            int a=0,b=0,c=0,d=0,e=0,j=i;
            bool flag=0;
            while(a<5){
                a+=v[j++];
                if(a==5){
                    while(b<7){
                        b+=v[j++];
                        if(b==7){
                            while(c<5){
                                c+=v[j++];
                                if(c==5){
                                    while(d<7){
                                        d+=v[j++];
                                        if(d==7){
                                            while(e<7){
                                                e+=v[j++];
                                                if(e==7){
                                                    cout<<i+1<<endl;
                                                    flag=1;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if(flag)break;
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
  int n, t, x, j;
  string s;
  vector<int> v, u;
  while (cin >> n, n) {
    for (int i = 0; i < n; ++i) {
      cin >> s;
      v.push_back(s.size());
    }
    t = 0;
    u = {5, 7, 5, 7, 7, 0};
    for (int i = 0; i < n; ++i) {
      j = i;
      t = 0;
      x = 5;
      while (x >= 0 && t < 5) {
	x -= v[j];
	if (!x) {
	  ++t;
	  x = u[t];
	} else if (x < 0) break;
	++j;
      }
      if (t == 5) {
	cout << i+1 << endl;
	break;
      }
    }
    v.erase(v.begin(), v.end());
  }
  return 0;
}