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;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1007;





int main(){
	while(1){
		ll n;cin>>n;
		if(n==0)break;
		ll wa=0;
		string s;
		vector<ll> len;
		FOR(i,0,n){
			cin>>s;
			len.pb(s.size());
		}
		ll ans=0;
		FOR(i,0,n){
			vector<ll> v;
			v.pb(0);
			if(ans!=0)break;
			FOR(j,i,n){
				if(v.size()==1){
					if(v[0]+len[j]>5)break;
					else if(v[0]+len[j]<5){
						v[0]+=len[j];
					}else{
						v[0]=5;
						v.pb(0);
					}
				}else if(v.size()==2){
					if(v[1]+len[j]>7)break;
					else if(v[1]+len[j]<7){
						v[1]+=len[j];
					}else{
						v[1]=7;
						v.pb(0);
					}
				}else if(v.size()==3){
					if(v[2]+len[j]>5)break;
					else if(v[2]+len[j]<5){
						v[2]+=len[j];
					}else{
						v[2]=5;
						v.pb(0);
					}
				}else if(v.size()==4){
					if(v[3]+len[j]>7)break;
					else if(v[3]+len[j]<7){
						v[3]+=len[j];
					}else{
						v[3]=7;
						v.pb(0);
					}
				}else if(v.size()==5){
					if(v[4]+len[j]>7)break;
					else if(v[4]+len[j]<7){
						v[4]+=len[j];
					}else{
						v[4]=7;
						v.pb(0);
						ans=i;
						break;
					}
				}
			}
		}
		cout<<ans+1<<endl;
	}
}

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+1 << endl;

    }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int n;
    while(cin >> n,n){
         vi v(10000,0);
        rep(i, n){string s; cin >> s; v[i] = (int)s.length();}
        int ans = 0;
        rep(i, n){
            int temp = 0; int array[] = {5,7,5,7,7}; int counter = 0;
            ans = i+1;
            for(int k = i;k<n;k++){
                temp+=v[k];
                if(temp == array[counter])
                {   temp = 0; counter++;
                    if(temp == 0 && counter == 5) goto L;
                }
            }
        }
    L:cout << ans << endl;
        ans = 0;
        
    }
}

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

int check(int num,int start, string w[40]){
  int count = start;
  bool flag = true;
  while(flag){
    if(count >= n){
      flag = false;
      break;
    }
    else if(num - w[count].size() == 0){
      count++;
      break;
    }
    else if(num - w[count].size() > 0){
      num -= w[count].size();
      count++;
      continue;
    }
    else {
      flag = false;
      break;
    }
  }
  if(flag) return count;
  else return -1;
}

int main(){
  string w[40];
  while(true){
    cin >> n;
    //cout << "n="<<n << endl;
    if(n == 0) break;

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

    for(int i = 0; i < n - 4; i++){
      int point = i;

      point = check(5, i, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(5, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point != -1){
         cout << i+1 << endl;
         break;
      }
    }
  }
  return 0;
}

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

int main()
{
    int n, a[5] = { 5, 7, 5, 7, 7 }, b[40];
    string s[40];

    while( cin >> n )
    {
        if( !n )
            break;

        for( int i = 0; i < n; i++ )
        {
            cin >> s[i];
            b[i] = s[i].size();
        }

        for( int i = 0; i < n; i++ )
        {
            int sum = 0, k = 0, j = i;
            while( a[k] >= sum && j < n )
            {
                sum += b[j];
                j++;
                if( sum == a[k] )
                {
                    k++;
                    sum = 0;
                }
            }
            if( k == 5 )
            {
                cout << i + 1 << endl;
                break;
            }
        }   
    }
    return 0;
}

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

int main()
{
  while(1){
    int n;
    cin >> n;
    if(n == 0) break;
    string w[n];
    bool k[500] = {};
    k[0] = true;
    string s = "";
    int m[n+1];
    m[0] = 0;
    for(int i = 0; i < n; i++){
      cin >> w[i];
      s += w[i];
      k[s.size()] = true;
      m[i+1] = s.size();
    }
    for(int i = 0; i < n; i++){
      if(s.size()-m[i]+1 < 31) continue;
      if(k[m[i]] && k[m[i]+5] && k[m[i]+12] && k[m[i]+17] && k[m[i]+24] && k[m[i]+31]){
        cout << i+1 << endl;
        break;
      }
    }
  }
}