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 pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    string tmp;
    vi a(n);
    REP(i, n) {
      cin >> tmp;
      a[i] = SZ(tmp);
    }
    REP(i, n) {
      vi b = {5, 7, 5, 7, 7};
      int cnt = 0;
      bool ok = false;
      FOR(j, i, n) {
        if(b[cnt] < a[j]) {
          break;
        } else if(b[cnt] == a[j]) {
          if(cnt == 4) {
            ok = true;
            break;
          } else {
            cnt++;
          }
        } else {
          b[cnt] -= a[j];
        }
      }
      if(ok) {
        cout << i+1 << endl;
        break;
      }
    }
  }
}

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


int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    int n;
    while(cin>>n){
        if(!n) break;
        string s[n];
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        int ans=0;
        int haiku[5] = {5,7,5,7,7};
        for(int i=0;i<n;i++){
            bool pos=true;
            int j=i;
            int cnt=0,now=0;
            while(pos && j<n){
                cnt+=s[j].size();
                if(cnt>haiku[now]){
                    pos=false;
                }
                if(cnt==haiku[now]){
                    cnt=0;
                    now++;
                }
                if(now==5) break;
                j++;
            }
            if(pos){
                cout<<i+1<<endl;
                break;
            }
        }
    }
    
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int tnk[5]={5,7,5,7,7};
	int n;
	while(cin>>n,n){
		string s[40];
		int snum=0,now=0,ans=1;
		REP(i,0,n){
			cin>>s[i];
		}
		int j=0;
		while(1){
			snum+=s[j].size();
			j++;
			if(snum==tnk[now]){
				snum=0;
				now++;
			}else if(snum>tnk[now]){
				snum=0;
				now=0;
				j=ans;
				ans++;
			}
			if(now==5){
				p(ans);
				break;
			}

		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>

int n,len[40];
char word[11];

int solve(int pos) {
	int rest;
	rest = 5;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 5;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
			rest -= len[pos++];
			if (rest < 0) return 0;
	}
	return 1;
}

int main() {
	while (1) {
		scanf("%d\n", &n);
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			scanf("%s\n", word);
			len[i] = strlen(word);
		}
		for (int j = 0; j < n; j++) {
			if (solve(j)) {
				printf("%d\n", j + 1);
				break;
			}
		}
	}
}

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

template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}

int a[5] = {5, 12, 17, 24, 31};
void solve(int n){
	vector<string> v;
	readVector(n, v);
	for(int i=0; i<n; ++i){
		int cnt = 0;
		int flag = 0;
		for(int j=i; j<n; ++j){
			cnt += v[j].size();
			for(int k=0; k<5; ++k)
				if(cnt == a[k])
					flag += (1 << k);
		}
		if(flag == 31){
			cout << i+1 << "\n";
			return;
		}
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

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

int main() {

	int n;
	while(cin >> n, n){
		vector<int> w(n);
		rep(i, n){
			string s;
			cin >> s;
			w[i] = s.size();
		}
		
		int ans = -1;
		rep(i, n){
			if(ans != -1) break;
			int pos = 0;
			int cnt = 0;
			REP(j, i, n){
				if(cnt + w[j] > phrase[pos]) break;
				else if(cnt + w[j] == phrase[pos]){
					pos++;
					cnt = 0;
				}
				else cnt += w[j];
				
				if(pos == 5) {
					ans = i + 1;
					break;
				}
			}
		}
		cout << ans << endl;
		
		
	}

	return 0;
}