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;

int main(){
  int step,flag=0,n,l,x;
  while(1){
    cin >> n;
    if(n==0){break;}
    string w[n];
    for(int i=0;i<n;i++){
      cin >> w[i];
    }
    for(int i=0;i<n-5;i++){
      l=0;
      step=1;
      flag=0;
      x=i;
      while(1){
        if(flag==1){break;}
        l+=w[x].length();
        switch(step){
          case 1:
          if(l>5){flag=1;}
          else if(l==5){step++;}
          break;
          case 2:
          if(l>12){flag=1;}
          else if(l==12){step++;}
          break;
          case 3:
          if(l>17){flag=1;}
          else if(l==17){step++;}
          break;
          case 4:
          if(l>24){flag=1;}
          else if(l==24){step++;}
          break;
          case 5:
          if(l>31){flag=1;}
          else if(l==31){flag=2;}
          break;
        }
        if(flag==2){break;}
        x++;
      }
      if(flag==2){x=i+1;break;}
    }
    if(flag==2){cout << x << endl;}
  }
  return 0;
}

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

int main(){
	while(true){
		int n;
		cin>>n;
		
		if(n==0)
			break;
		
	int len[40];
	for(int i=0;i<n;i++){
		string w;
		cin>>w;
		
		len[i] = w.size();
	}

	for(int i=0;i<n;i++){
		bool flg=false;
		int sta=0;
		int sum=0;
		
		for(int j=i;j<n;j++){
			sum += len[j];
	
			if(sum==5||sum=12||sum==17||sum==24||sum==31){
				sta++;
			}
			if(sta==5){
				flg=true;
				break;
			}
			else if(sum>=31){
				break;
			}
		}

		if(flg){
			cout<<i+1<<endl;
			break;
		}
	}

	}
	return 0;
	}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};
int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<int> lens;
		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;
			lens.emplace_back(s.size());
		}

		vector<int> cnts{ 5,7,5,7,7 };
		int start = -1;
		for (int i = 0; i < n; i++) {
			int now = 0;
			int tmp = 0;
			for (int j = i; j < n; j++) {
				tmp += lens[j];
				if (tmp > cnts[now])break;

				if (tmp == cnts[now]) {
					now++;
					tmp = 0;
					if (now == 5) {
						start = i;
						break;
					}
				}
			}

			if (start >= 0)break;
		}
		cout << start + 1 << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<int> T={5,12,17,24,31};
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<int> A(N+1);
        for(int i=0;i<N;i++){
            string S;cin>>S;
            A[i+1]=A[i]+S.size();
        }
        
        for(int s=0;s<N;s++){
            bool ok=true;
            for(int i=0;i<5;i++){
                if(!binary_search(all(A),A[s]+T[i])) ok=false;
            }
            if(ok){
                cout<<s+1<<endl;
                break;
            }
        }
    }
}

C++: #include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int n;
		cin>>n;
		if(n==0)break;
		vector<string> s(n);
		REP(i, n) cin>>s[i];
		ll cnt = 0;
		ll d = 0;
		ll ans = -1;
		REP(i, n) {
			if(ans != -1) break;
			FOR(j, i, n) {
				if(d == 5) {
					cnt = 0;
					d = 0;
					break;
				}
				cnt += s[j].size();
				switch(d) {
					case 0:
						if(cnt < 5) continue;
						else if(cnt == 5) {
							cnt = 0;
							++d;
						} else if(cnt > 5) d = 5;
						break;
					case 1:
						if(cnt < 7) continue;
						else if(cnt == 7) {
							cnt = 0;
							++d;
						} else if(cnt > 7) d = 5;
						break;
					case 2:
						if(cnt < 5) continue;
						else if(cnt == 5) {
							cnt = 0;
							++d;
						} else if(cnt > 5) d = 5;
						break;
					case 3:
						if(cnt < 7) continue;
						else if(cnt == 7) {
							cnt = 0;
							++d;
						} else if(cnt > 7) d = 5;
						break;
					case 4:
						if(cnt < 7) continue;
						else if(cnt == 7) {
							ans = i + 1;
							++d;
						} else if(cnt > 5) d = 5;
						break;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int n, p[] = { 5, 7, 5, 7, 7 }, ans;
string s[40];

int main() {
	while (true) {
		cin >> n;
		if (!n)break;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		ans = 0;

		for (int i = 0; i < n; i++) {
			int index = 0;
			int sum = 0;
			for (int j = i; j < n; j++) {
				sum += s[j].length();
				if (sum == p[index]) {//次に進む
					index++;
					sum = 0;
				}
				else if (sum > p[index]) {//もうあり得ない
					break;
				}

				if (index > 4) {
					ans = i + 1;
					break;
				}
			}

			if (ans > 0)break;
		}

		cout << ans << endl;
	}
}