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 <bits/stdc++.h>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		bool check = false;
		int n;
		int now = 1;
		int count = 0;

		cin >> n;
		if (n == 0) {
			break;
		}
		vector<string> w(n + 1);
		vector<int>dp(n + 1);
		FOR(i, 1, n) {
			cin >> w[i];
			dp[i] = w[i].size();
		}
		FOR(i, 1, n) {
			bool flag = true;
			now = 1;
			count = 0;
			FOR(t, i, n) {
				count += dp[t];
				switch (now) {
				case 1:
					if (count > 5) {
						flag = false;
					}
					else if (count == 5) {
						now++;
						count = 0;
					}
					break;
				case 2:
					if (count > 7) {
						flag = false;
					}
					else if (count == 7) {
						now++;
						count = 0;
					}
					break;
				case 3:
					if (count > 5) {
						flag = false;
					}
					else if (count == 5) {
						now++;
						count = 0;
					}
					break;
				case 4:
					if (count > 7) {
						flag = false;
					}
					else if (count == 7) {
						now++;
						count = 0;
					}
					break;
				case 5:
					if (count > 7) {
						flag = false;
					}
					else if (count == 7) {
						now++;
						count = 0;
					}
					break;
				}
				if (flag == false) {
					break;
				}
				if (now == 6) {
					cout << i << endl;
					check = true;
					break;
				}
			}
			if (check == true) {
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <vector>

int main() {
  int n;

  constexpr int check[] = {5, 7, 5, 7, 7};

LOOP:
  while (std::cin >> n, n != 0) {
    std::vector<std::string> v(n);

    for (int i = 0; i < n; ++i) {
      std::cin >> v[i];
    }


    for (int i = 0; i < n; ++i) {
      int cnt = 0, idx = 0;
      for (int j = i; j < n; ++j) {
        cnt += v[j].size();
        if (cnt == check[idx]) {
          cnt = 0;
          idx++;
        }
        if (idx == 5) {
          std::cout << i + 1 << std::endl;
          goto LOOP;
        }
      }
    }
  }
}

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

int solve(vector<int> &a) {
    int n = a.size();
    for (int i = 0; i < n; i++) {
        int cur = i;
        bool ok = true;
        for (int tgt: {5, 7, 5, 7, 7}) {
            int cnt = 0;
            while (cur < n && cnt + a[cur] <= tgt) cnt += a[cur++];
            if (cnt != tgt) { ok = false; break; }
        }
        if (ok) return i;
    }
    return -1;
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> len(n);
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            len[i] = s.size();
        }
        cout << solve(len) + 1 << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int N;
        cin >> N;
        if(!N) break;
        string s[N];
        for(int i = 0; i < N; i++) cin >> s[i];
        const vector<int> po = {5, 7, 5, 7, 7};
        for(int i = 0; i < N; i++){
            int index = 0;
            vector<int> yo = po;
            for(int j = i; j < N; j++){
                if(index == 5) break;
                if(yo[index] < s[j].size()) break;
                yo[index] -= s[j].size();
                if(!yo[index]) index++;
            }
            if(index == 5){
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define f(X) for(c=0;c<X;c+=v[p--]);if(c-X)goto L;
main(){for(char n,v[99],s,p,c;p=s=n=atoi(gets(v));){for(;p;v[p--]=strlen(gets(v+70)));L:p=s--;f(5)f(7)f(5)f(7)f(7)puts(itoa(n-s));}}

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

int main(){
	while(1){
		int n;
		cin>>n;

		if(n==0)
			break;
		
		int len[40];
		for(int i=0;i<n;i++){
			string w;
			cin>>w;

			len[i]=w.size();
		}

		for(int i=0;i<n;i++){
			bool flg=false;
			int sta=0;
			int sum=0;
		
			for(int j=i;j<n;j++){
				sum+=len[j];

				if(sum==5||sum==12||sum==17||sum==24||sum==31){
					sta++;
				}

				if(sta==5){
					flg=true;
					break;
				}
				else if(sum>=31){
					break;
				}
			}
			
			if(flg){
				cout<<i+1<<endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S[1000]; int  n, p[5] = { 5,12,17,24,31 };
int main() {
    while (true) {
        cin >> n; if (n == 0)break;
        for (int i = 0; i < n; i++)cin >> S[i];
        for (int i = 0; i < n; i++) {
            int cnt = 0, sum = 0;
            for (int j = i; j < n; j++) {
                if (cnt >= 5)continue;
                sum += S[j].size();
                if (p[cnt] == sum)cnt++;
            }
            if (cnt == 5) { cout << i + 1 << endl; break; }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	int n;
			int word=0;
int first=0;
	while(cin>>n){


		if(n==0)break;

		// int array[4]={5,7,5,7,7};

		vector<int> v1;
		vector<string> v2;

		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v2.push_back(s);

		}

		for(int i=0;i<n;i++){
			string tmp=v2[i];
			int a=tmp.size();
			v1.push_back(a);
		}

		// for(int i=0;i<n;i++){
		// 	cout<<v1[i]<<endl;
		// }

		// cout<<endl;

		for(int i=0;i<n;i++){
			word=0;
			first=i+1;
			// cout<<"FIRST="<<first<<endl;
			int tmp=0;
			

			if(5>=tmp){
				for(int j=i;j<n;j++){

					

					tmp+=v1[j];
					// cout<<tmp<<" "<<word<<endl;
					if(word==0){
						if(tmp==5){
							word++;
							tmp=0;
						}else if(tmp>5){
							
							break;
						}

					}else if(word==1){
						
						if(tmp==7){
							word++;
							tmp=0;
						}else if(tmp>7){

							break;
						}

					}else if(word==2){

						if(tmp==5){
							word++;
							tmp=0;
						}else if(tmp>5){
							break;
						}

					}else if(word==3){
						if(tmp==7){
							tmp=0;
							word++;
						}else if(tmp>7){
							break;
						}

					}else if(word==4){
						if(tmp==7){
							word++;
							break;
						}else if(tmp>7){
							break;
						}
					}
				}
			}

			if(word==5){
				cout<<first<<endl;
				break;
			}	
		}
	
		

	}

	return 0;
}