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>
using namespace std;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        int phraseCount[] = {5, 7, 5, 7, 7};
        int currentPhraseIndex = 0;
        int currentPhraseCount = 0;
        string phrases[n];
        for(int i = 0; i < n; i++){
            cin >> phrases[i];
        }
        bool foundAnser = false;
        for(int k = 0; k < n; k++){
        for(int i = k; i < n; i++){
            string s;
            s = phrases[i];
            currentPhraseCount += s.length();
            if(currentPhraseCount == phraseCount[currentPhraseIndex]){
                currentPhraseIndex++;
                currentPhraseCount = 0;
                if(currentPhraseIndex == 5){
                    cout << k + 1 << endl;
                    for(int j = i + 1; j < n; j++){
                        cin >> s;
                    }
                    foundAnser = true;
                    break;
                }
            }else if(currentPhraseCount > phraseCount[currentPhraseIndex]){
                currentPhraseIndex = 0;
                currentPhraseCount = 0;
                break;
            }
        }
        if(foundAnser){
            break;   
        }
        }
    }
    return 0;
}

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

bool solve(int a){
	int i = a;
	int res = 0;
	while(i < v.size()){
		res += v[i].size();
		i++;
		if(res == 5){
			while(i < v.size()){
				res += v[i].size();
				i++;
				if(res == 12){
					while(i < v.size()){
						res += v[i].size();
						i++;
						if(res == 17){
							while(i < v.size()){
								res += v[i].size();
								i++;
								if(res == 24){
									while(i < v.size()){
										res += v[i].size();
										i++;
										if(res == 31)return true;
										else if(res > 31)return false;
									}
								}
								else if(res > 24)return false;
							}
						}
						else if(res > 17)return false;
					}
				}
				else if(res > 12)return false;
			}
		}
		else if(res > 5)return false;
	}
	return false;
}

int main(){
	int n;
	string s;
	while(cin >> n,n){
		v.clear();
		for(int i = 0;i < n;i++){
			cin >> s;
			v.push_back(s);
		}
		for(int i = 0;i < n;i++){
			if(solve(i)){
				cout << i+1 <<endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int tk[5]={5,7,5,7,7};

void solve(int n){
	string s;
	vi v(n);
	rep(i,n){
		cin>>s;
		v[i]=s.size();
	}
	rep(i,n-4){
		int pos=i;
		int ku=0;
		int wo=0;
		while(pos<n&&ku<5){
			wo+=v[pos];
			pos++;
			if(wo==tk[ku]){
				ku++;
				wo=0;
			}
			else if(wo>tk[ku])break;
		}
		if(ku==5){
			cout<<i+1<<endl;
			return;
		}
	}

}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n)solve(n);
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    auto c = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      string w; cin >> w;
      c[i] = w.length();
    }
    auto solve = [&]() {
      for (int i = 0; i < n; ++i) {
        auto phrase = vector<int>{5, 7, 5, 7, 7};
        int idx = 0;
        for (int j = i; j < n; ++j) {
          if (phrase[idx] > 0) phrase[idx] -= c[j];
          if (phrase[idx] < 0) break;
          if (phrase[idx] == 0) ++idx;
          if (idx == 5) return i + 1;
        }
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
char s[50],a[9]={6,8,6,8,8};main(){for(int i,j,p,n,q;scanf("%d\n",&n),n;){for(i=0;i<n;s[i++]=strlen(gets(s+i)));for(i=j=0;j<6;i++)for(p=i,j=q=0;q+1;)for(q=a[j++]-1;q>0;q-=s[p++]);printf("%d\n",i);}}