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 rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n;
    int cd[6] = {5, 7, 5, 7, 7, 10000};
    while(cin >> n, n){
        string s;
        vector<int> d(n);
        rep(i, 0, n){
            cin >> s;
            d[i] = (int)(s.size());
        }
        int ans = 0;
        rep(i, 0, n){
            int cnt = 0, ind = 0;
            rep(j, i, n){
                cnt += d[j];
                if(cnt == cd[ind]){
                    cnt = 0;
                    ind++;
                }
                if(cnt > cd[ind]) break;
            }
            if(ind == 5){
                ans = i + 1;
                break;
            }
        }
        cout << ans << endl;
    }
}

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

int main(){
  int n;
  while(cin>>n,n){
    string str[50];
    for(int i=0;i<n;i++)cin>>str[i];

    int num[]={5,7,5,7,7},ans=1000000;
    for(int i=0;i<n;i++){
      for(int j=i,idx=0,cnt=0;j<n;j++){
	cnt+=str[j].size();
	if(cnt==num[idx]) idx++,cnt=0;
	if(cnt>num[idx])break;
	if(idx==5) ans=min(ans,i);
      }    
    }
    cout <<ans+1<<endl;
  }
  return 0;
}

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

int main(){
  string w;
  int len[40];
  int tanku[]={5,7,5,7,7};
  int n,sum=0;
  for(;;){
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin>>w;
      len[i]=w.size();
      sum+=len[i];
    }
    for(int i=0,jud=0;i<n;i++){
      if(sum<27) break;
      for(int j=i,k=0,m=0;j<n;j++){
	if(m+len[j]>tanku[k]) break;
	else if(m+len[j]==tanku[k]){
	  k++; m=0;
	}
	else m+=len[j];
	if(k==5){
	  cout<<i+1<<endl; jud=1; break;
	}
      }
      if(jud) break;
    }
  }
}

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

int main(){
  int step,flag=0,n,l,x;
  while(1){
    cin >> n;
    if(n==0){break;}
    string w[n];
    for(int i=0;i<n;i++){
      cin >> w[i];
    }
    for(int i=0;i<n-5;i++){
      l=0;
      step=1;
      flag=0;
      x=i;
      while(1){
        if(flag==1){break;}
        l+=w[x].length();
        switch(step){
          case 1:
          if(l>5){flag=1;}
          else if(l==5){step++;}
          break;
          case 2:
          if(l>12){flag=1;}
          else if(l==12){step++;}
          break;
          case 3:
          if(l>17){flag=1;}
          else if(l==17){step++;}
          break;
          case 4:
          if(l>24){flag=1;}
          else if(l==24){step++;}
          break;
          case 5:
          if(l>31){flag=1;}
          else if(l==31){flag=2;}
          break;
        }
        if(flag==2){break;}
        x++;
      }
      if(flag==2){x=i+1;break;}
    }
    if(flag==2){cout << x << endl;}
  }
  return 0;
}

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

int main(){
	while(true){
		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 <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};
int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<int> lens;
		for (int i = 0; i < n; i++) {
			string s;
			cin >> s;
			lens.emplace_back(s.size());
		}

		vector<int> cnts{ 5,7,5,7,7 };
		int start = -1;
		for (int i = 0; i < n; i++) {
			int now = 0;
			int tmp = 0;
			for (int j = i; j < n; j++) {
				tmp += lens[j];
				if (tmp > cnts[now])break;

				if (tmp == cnts[now]) {
					now++;
					tmp = 0;
					if (now == 5) {
						start = i;
						break;
					}
				}
			}

			if (start >= 0)break;
		}
		cout << start + 1 << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<int> T={5,12,17,24,31};
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<int> A(N+1);
        for(int i=0;i<N;i++){
            string S;cin>>S;
            A[i+1]=A[i]+S.size();
        }
        
        for(int s=0;s<N;s++){
            bool ok=true;
            for(int i=0;i<5;i++){
                if(!binary_search(all(A),A[s]+T[i])) ok=false;
            }
            if(ok){
                cout<<s+1<<endl;
                break;
            }
        }
    }
}

C++: #include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int n;
		cin>>n;
		if(n==0)break;
		vector<string> s(n);
		REP(i, n) cin>>s[i];
		ll cnt = 0;
		ll d = 0;
		ll ans = -1;
		REP(i, n) {
			if(ans != -1) break;
			FOR(j, i, n) {
				if(d == 5) {
					cnt = 0;
					d = 0;
					break;
				}
				cnt += s[j].size();
				switch(d) {
					case 0:
						if(cnt < 5) continue;
						else if(cnt == 5) {
							cnt = 0;
							++d;
						} else if(cnt > 5) d = 5;
						break;
					case 1:
						if(cnt < 7) continue;
						else if(cnt == 7) {
							cnt = 0;
							++d;
						} else if(cnt > 7) d = 5;
						break;
					case 2:
						if(cnt < 5) continue;
						else if(cnt == 5) {
							cnt = 0;
							++d;
						} else if(cnt > 5) d = 5;
						break;
					case 3:
						if(cnt < 7) continue;
						else if(cnt == 7) {
							cnt = 0;
							++d;
						} else if(cnt > 7) d = 5;
						break;
					case 4:
						if(cnt < 7) continue;
						else if(cnt == 7) {
							ans = i + 1;
							++d;
						} else if(cnt > 5) d = 5;
						break;
				}
			}
		}
		cout<<ans<<endl;
	}
}