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>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    int w[5] = {5, 7, 5, 7, 7};
    while (cin >> n && n){
        VI a(n);
        REP(i,n) {
            string s;
            cin >> s;
            a[i] = s.length();
        }
        REP(s,n){
            int x = 0, i = s, j = 0, f = 1;
            while (f){
                x += a[i];
                i++;
                if (x > w[j]) f = 0;
                if (x == w[j]){
                    x = 0;
                    j++;
                }
                if (j == 5) break;
            }
            if (f) cout << s+1 << 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<stdio.h>
#include<string.h>

int main(void){
	int n,n_l[40],count=0,cap=0;
	char w[10];
	scanf("%d",&n);

	int i;
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%s",w);
			n_l[i]=strlen(w);
		}
		for(i=0;;i++){
			count=0;
			cap=0;
			while(count<5){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=5)
				continue;
			count=0;
			while(count<7){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=7)
				continue;
			count=0;
			while(count<5){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=5)
				continue;
			count=0;
			while(count<7){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=7)
				continue;
			while(count<7){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=7)
				continue;
			break;
		}
		printf("%d\n",i+1);
		scanf("%d",&n);
	}
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<string> w;
	for (int i = 0;i < n;++i) {
		string tmp;
		cin >> tmp;
		w.push_back(tmp);
	}

	int flag = 0;
	int len = 0;
	int output=100000000;
	for (int i = 0;i < n;++i) {
		flag = 0;
		len = 0;
		for (int j = i; j< n;++j) {
			len += w[j].size();
			if (flag == 0 || flag == 2) {
				if (len == 5) {
					len = 0;
					flag++;
				}
				else if (len > 5) {
					break;
				}
			}
			else {
				if (len == 7) {
					len = 0;
					flag++;
				}
				else if (len > 7) {
					break;
				}
			}
		}

		if (flag >= 5) {
			output = i+1;
			break;
		}
	}

	cout << output << endl;

}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int N;
    vector<int> num = {5, 7, 5, 7, 7};

    while (cin >> N, N) {
        vector<string> S(N);
        rep(i, N) cin >> S[i];

        rep(i, N) {
            int tmp_len = 0;
            int num_idx = 0;
            bool ok = false;
            
            for (int j=i; j<N; j++) {
                if (tmp_len < num[num_idx]) {
                    tmp_len += S[j].size();
                }

                if (tmp_len == num[num_idx]) {
                    num_idx++;
                    tmp_len = 0;
                } else if (tmp_len > num[num_idx]) {
                    break;
                }

                if (num_idx == 5) {
                    ok = true;
                    break;
                }
            }
            if (ok) {
                cout << i+1 << endl;
                break;
            }
        }
    }
}