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;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  string s;
  int len[5]={5,7,5,7,7};
  int count;
  int now;
  int ans;
  while(1){
    cin >> n;
    if(n==0) return 0;
    vector<int> w(n);
    for(int i=0;i<n;i++){
      cin >> s;
      w[i]=s.length();
    }
    ans=-1;
    for(int i=0;i<n;i++){
      count=0;
      now=0;
      for(int j=i;j<n;j++){
        count+=w[j];
        if(count==len[now]){
          now++;
          count=0;
          if(now==5){
            ans=i;
          }
        }else if(count>len[now]){
          break;
        }
      }
      if(ans!=-1){
        break;
      }
    }
    cout << ans+1 << endl;
  }
  return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n; cin >> n&&n;) {
		vector<string> w(n); rep(i, 0, n) { cin >> w[i]; }
		rep(i, 0, n) {
			int a[5] = { 5,7,5,7,7 };
			int idx = 0;
			rep(j, i, n) {
				a[idx] -= w[j].size();
				if (a[idx] == 0) {
					if (idx == 4) {
						cout << i + 1 << endl;
						i = INF;
						break;
					}
					idx++;
				}
				if (a[idx] < 0)break;
			}
		}
	}
	return 0;
}

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

int main(){
  int n;
  const int haiku[5]={5,7,5,7,7};
  while(cin>>n,n){
    vector<string> w(n);
    for(int i=0;i<n;i++) cin>>w[i];
    int res=-1;
    for(int i=0;i<n && res==-1;i++){
      int stage=0;
      int cnt=0;
      for(int j=i;j<n;j++){
	cnt+=w[j].size();
	if(cnt==haiku[stage]){
	  stage++;
	  cnt=0;
	}
	if(stage==5){
	  res=i+1;
	  break;
	}

      }
    }
    cout<<res<<endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int n;
    while(cin>>n&&n){
        vector<string> vs(n);
        rep(i,n)cin>>vs[i];
        
        rep(i,n){
            int count;
            int pos = i;

            count = 0;
            while(count<5 && pos<n) count+=vs[pos++].size();
            if(count!=5)continue;

            count = 0;
            while(count<7 && pos<n) count+=vs[pos++].size();
            if(count!=7)continue;

            count = 0;
            while(count<5 && pos<n) count+=vs[pos++].size();
            if(count!=5)continue;

            count = 0;
            while(count<7 && pos<n) count+=vs[pos++].size();
            if(count!=7)continue;

            count = 0;
            while(count<7 && pos<n) count+=vs[pos++].size();
            if(count!=7)continue;

            cout<<i+1<<endl;
            break;
        }
    }
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
    while(cin >> n, n){
    int len[] = {5, 7, 5, 7, 7};
    string w[44];
    for(int i = 0; i < n; i++) cin >> w[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        int cnt = 0, idx = 0;
        for(int j = i; j < n; j++){
        cnt += w[j].size();
        if(cnt == len[idx]){
            cnt = 0, idx++;
            if(idx == 5) break;
        }else if(cnt > len[idx]){ idx = -1; break;}
        }
        if(idx == 5){ ans = i; break;}
    }
    cout << ans+1 << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		int n; cin >> n;
		if (n == 0) break;
		
		vector<string> str(n);
		for(int i = 0; i < n; i++) {
			cin >> str[i];	
		}

		int ans = 0;
		for(int i = 0; i < n; i++) {
			ans = i;	
			vector<int> check = {5,7,5,7,7};
			int idx = 0;
			for (int j = i; j < n; j++) {
					if (check[idx] > 0){
						check[idx] -= str[j].size();
					}else if(check[idx] <= 0){
						idx++;
						check[idx] -= str[j].size();
					}
					
			}
			int sum = 0;
			for (int k = 0; k < 5; k++){
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

		}
		cout << ans + 1 << endl;
	}

	return 0;
}