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>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int a[5] = {5,7,5,7,7};
signed main() {
	int n;
	while (cin >> n && n) {
	    vector<int> v(n);
	    rep(i, n) {
	        string s; cin >> s;
	        v[i] = s.size();
	    }
	    rep(i, n) {
	        bool ok = true;
	        int idx = 0;
	        int sum = 0;
	        rep(j, 5) {
	            while (i + idx < n && sum < a[j]) {
	                sum += v[i + idx++];
	              }
	            if (sum > a[j]) {
	                ok = false;
	                break;
	            }
	            sum = 0;
	        }
	        if (ok) {
	            cout << i + 1 << endl;
	            break;
	        }
	    }
    }
}

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

int main(){
  while(1){
    int N;
    cin >> N ;
    vector<int> a;
    if(N==0){
      break;
    }
    for(int i=0;i<N;i++){
      string str;
      cin >> str;
      a.push_back(str.size());
    }
    for(int i=0;i<N;i++){
      int tanka=0;
      int sum=0;
      for(int j=i;j<N;j++){
        sum+=a[j];
        if(sum==5&&(tanka==0||tanka==2)||sum==7&&(tanka==1||tanka==3||tanka==4)){
          tanka++;
          sum=0;
        }
      }
      if(tanka==5){
        cout << i+1 << endl;
        break;
      }
    }
  }
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    vector<int> a(n);
    for(int i=0; i<n; i++){
      string s;
      cin >> s;
      a[i] = s.size();
    }

    for(int i=0; i<n; i++){
      int t[5] = {5,7,5,7,7};
      int p = 0;
      int tmp = 0;
      for(int j=i; j<n; j++){
        tmp += a[j];
        if( tmp == t[p] ){
          p++;
          tmp = 0;
        }else if( tmp > t[p] ){
          tmp = 0;
          break;
        }
      }
      if( p == 5 ){
        cout << i + 1 << endl;
        break;
      }
      // cerr << " " << p << endl;
    }

  }

  return 0;
}


// EOF

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

int d[] = {5,7,5,7,7};
signed
main(){
	int n;
	while(cin >> n && n!=0)
	{
			vector<int> w(n);
			for(int i=0;i<n;i++)
			{
					string s;
					cin >> s;
					w[i] = (int)s.size();
			}

			for(int i=0;i<n;i++)
			{
					int a[5] = {};
					int key = 0;
					bool flag = true;
					for(int j=i;j<n;j++)
					{
							if(key == 5){
									break;
							}
							a[key] += w[j];
							if(a[key] == d[key]){
									key++;
							}else if(a[key] < d[key]){

							}else if(a[key] > d[key]){
									flag = false;
									break;
							}
					}

					if(flag){
							cout << i+1 << endl;
							break;
					}
			}
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  int a[]={5,7,5,7,7},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)goto L;
        }
      }
    }
    L: if(k==5)cout<<i+1<<endl;
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n];
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			a[i]=s.size();
		}
		int st=0,t=0,ct=0;
		for(int i=0;i<n;i++){
			for(int j=i;j<n;j++){
				t=t+a[j];
				if(ct==0||ct==2){
					if(t>5){
						t=0;
						ct=0;
						break;
					}
					else if(t==5){
						t=0;
						ct++;
					}
				}
				else if(ct==1||ct==3||ct==4){
					if(t>7){
						t=0;
						ct=0;
						break;
					}
					else if(t==7){
						t=0;
						ct++;
					}
				}
			}
			if(ct==5){
				st=i+1;
				break;
			}
		}
		cout<<st<<endl;
	}
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,l[45],L[45],a,d[5]={5,7,5,7,7};
string s;
 
int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++){
      cin>>s,l[i]=s.size();
      L[i]=L[i-1]+l[i];
    }
    a=0;
    for(int i=1;i<=n;i++){
      int x=0,s=i;
      for(int j=i;j<=n;j++){
    if(L[j]-L[s-1]==d[x])x++,s=j+1;
    if(!a&&x==5)a=i,cout<<a<<endl;
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n;

int main(){
    while(1){
        cin >> n;
        if(n==0)break;
        vector<string> w(n);
        int tan[] = {5,7,5,7,7};
        for(int i=0;i<n;i++){
            cin >> w[i];
        }
        int j=0;
        int ans=0;
        int sum=0;
        for(int i=0;i<n;i++){
            sum += w[i].size();
            if(sum > tan[j]){
                sum = w[i].size();
                j=0;
                ans=i;
            }
            if(sum < tan[j])continue;
            if(sum == tan[j]){
                if(j==4)break;
                else {
                    j++;
                    sum = 0;
                }
            }
        }
        cout << ans << endl;

    }
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000003
#define HOGE 100000
#define HUGA 100000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n;
string str[40];
int x[5] = {5,7,5,7,7};

void solve(){
    rep(i,n) cin >> str[i];
    rep(i,n){
        int cnt = 0;
        int sum = 0;
        for(int j = i; j < n; j++){
            sum += str[j].size();
            if(sum == 5) cnt++;
            if(sum == 12) cnt++;
            if(sum == 17) cnt++;
            if(sum == 24) cnt++;
            if(sum == 31) cnt++;
            if(sum >= 31) break;
        }
        if(cnt == 5){
            cout << i+1 << endl;
            break;
        }
    }
}

int main(){
    while(cin >> n){
        if(n == 0) break;
        solve();
    }
}