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

int main() {

  while(1) {
    bool end = false;

    int n;
    cin >> n;
    if(n == 0) return 0;
    int w[n];
    for(int i = 0; i < n; i++) {
      string s;
      cin >> s;
      w[i] = s.size();
    }

    // for(int i = 0; i < n; i++) cout << w[i] << " ";
    // cout << endl;
    int tanku[5] = {5, 7, 5, 7, 7};
    for(int i = 0; i < n; i++) {
      if(end) break;
      int k = 0;
      for(int j = 0; j < 5; j++) {
        if(end) break;
        int sum = 0;
        while(sum < tanku[j]) {
          sum += w[i+k];
          k++;
        }
        // cout << sum << " :" << j << " ";
        if(sum != tanku[j]) break;
        if(j == 4) {
          cout << i+1 << endl;
          end = true;
        }
      }
    }
  }
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    vs vec;
    rep(i,0,n){
      cin >> s;
      vec.pb(s);
    }
    m = -1;
    rep(i,0,vec.sz){
      t = "";
      l = 0;
      rep(j,i,vec.sz){
        t += vec[j];
        // cout << t << " " << t.sz << endl;
        if(t.sz == 5)l++;
        if(t.sz == 5+7)l++;
        if(t.sz == 5+7+5)l++;
        if(t.sz == 5+7+5+7)l++;
        if(t.sz == 5+7+5+7+7)l++;
        if(t.sz >= 31){
          if(l == 5){
            m = i + 1;
            break;
          }
        }
      }
      if(m != -1)break;
    }
    print(m);
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  while(cin >> n,n){
    int i,j,k;
    string buf;
    int d[50]={};
    for(i=0;i<n;i++){
      cin >> buf;
      d[i]=buf.size();
    }
    for(i=0;i<n;i++){
      int c=0;
      j=i;
      while(c<5) c+=d[j++];
      if(c!=5) continue;
      c=0;
      while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      while(c<5) c+=d[j++];
      if(c!=5) continue;
      c=0;while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      cout << i+1 << endl;
      break;
    }
  }
  return 0;
}

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

int main()
{
	int n;
	string s;
	while (cin >> n, n) {
		vector<int> w(n);
		for (int i = 0; i < n; i++) {
			cin >> s;
			w[i] = s.size();
		}
		int res = -1;
		for (int i = 0; i < n; i++) {
			bool tmp[] = { false, false, false, false };
			int sum = 0;
			for (int j = i;j < n; j++) {
				sum += w[j];
				if (sum == 5) {
					tmp[0] = true;
				}
				if (sum == 12) {
					if (tmp[0]) {
						tmp[1] = true;
					}
					else {
						break;
					}
				}
				if (sum == 17) {
					if (tmp[1]) {
						tmp[2] = true;
					}
					else {
						break;
					}
				}
				if (sum == 24) {
					if (tmp[2]) {
						tmp[3] = true;
					}
					else {
						break;
					}
				}
				if (sum == 31) {
					if (tmp[3]) {
						res = i + 1;
						break;
					}
					else {
						break;
					}
				}
			}
			if (res != -1)
				break;
		}
		cout << res << endl;
	}
	return 0;
}