Go: // Short Phrase(短句)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		n := nextInt(sc)
		if n == 0 {
			break
		}

		var words []string
		for i := 0; i < n; i++ {
			words = append(words, nextString(sc))
		}

		res := 0
		for i := 0; i < n; i++ {
			tmpWords := words[i:]
			ok := checkRule(tmpWords, 0)
			if ok {
				res = i + 1
				break
			}
		}

		fmt.Println(res)
	}
}

var rule = [5]int{5, 7, 5, 7, 7}

func checkRule(words []string, depth int) bool {
	var shortPhrase = ""
	var i = depth

	if depth == 5 {
		return true
	}

	for len(words) > 0 {
		shortPhrase += words[0]
		words = words[1:]

		if rule[i] == len(shortPhrase) {
			return checkRule(words, i+1) // 短句のルールを満たしたので次の文節へ
		} else if rule[i] < len(shortPhrase) {
			return false // 文節の語数オーバー
		}
	}

	return false // 文節を満たす単語が足りない
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

const int step[5] = {5, 7, 5, 7, 7};

int N;
string S[40];

int solve() {
    for (int i = 0; i < N; ++i) {
        bool ok = true;
        int idx = i;
        for (int t = 0; t < 5; ++t) {
            int acc = 0;
            while (acc < step[t]) acc += S[idx++].size();
            if (acc != step[t]) {
                ok = false;
                break;
            }
        }
        if (ok)
            return i+1;
    }

    return -1;
}

int main(void) {
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int i = 0; i < N; ++i)
            cin >> S[i];

        cout << solve() << endl;
    }
    return 0;
}

C++: #include<vector>
#include<iostream>
#include<string>
using namespace std;
int a0 = 5;
int a1 = 7;
int a2 = 5;
int a3 = 7;
int a4 = 7;
int main() {
	int n;
	while (cin >> n, n != 0) {
		vector<int>v(n);
		for (int i = 0; i < n; i++) {
			string str;
			cin >> str;
			int x = str.size();
			v[i] = x;
		}
		for (int i = 0; i < n; i++) {
			int k = i;
			int ans = i;
			int a = a0;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				

			}
			a = a1;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a2;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a3;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a4;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					cout << ans + 1 << endl;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
		OUT:
			;
		}

	}
	return 0;
}


// 5 12 17 24 31

C++: #include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;

using namespace std;

int main()
{
    int n;
    int len[] = {5,7,5,7,7};
    while (cin >> n, n) {
        int w[n];
        rep (i, n) {
            string s;
            cin >> s;
            w[i] = s.length();
        }
        int i = 0, count = 0;
        frep (s, 0, n) {
            frep(c, s, n) {
                count += w[c];
                if (count == len[i]) {
                    if (i == 4) {
                        cout << s + 1 << endl;
                        s = n;
                        break;
                    }
                    count = 0;
                    ++i;
                } else if (count > len[i]) {
                    i = 0;
                    count = 0;
                    break;
                }
            }
        }
    }
    
    return EXIT_SUCCESS;
}