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 <string>
#include <utility>
#include <vector>

using namespace std;

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

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

        auto check = [&v](int start, int num) {
            int count{0};
            for (int j = start; j < v.size(); ++j) {
                count += v[j].size();
                if (count > num) {
                    break;
                }
                if (count == num) {
                    return make_pair(true, j + 1);
                }
            }
            return make_pair(false, start + 1);
        };
        int s = 0;
        while (true) {
            auto r1 = check(s, 5);
            if (r1.first) {
                auto r2 = check(r1.second, 7);
                if (r2.first) {
                    auto r3 = check(r2.second, 5);
                    if (r3.first) {
                        auto r4 = check(r3.second, 7);
                        if (r4.first) {
                            auto r5 = check(r4.second, 7);
                            if (r5.first) {
                                cout << (s + 1) << endl;
                                break;
                            }
                        }
                    }
                }
            }
            ++s;
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	while(cin>>n,n){
		int a[40]={0},j=0,i=0,c,k=0;
		for(;j<n;j++){
			cin>>s;
			a[i++]=s.size();
		}
		for(j=0;j<35;j++){
			int b[4]={0};
			c=0;
		for(i=j;i<40;i++){
			c+=a[i];
			if(c==5)b[0]++;
			else if(b[0]&&c==12)b[1]++;
			else if(b[1]&&c==17)b[2]++;
			else if(b[2]&&c==24)b[3]++;
			else if(b[3]&&c==31){
				k=j;
				break;
			}
			if(!b[0]&&c>5)break;
		}if(k)break;
	    }
	    
		cout<<k+1<<endl;
	}
}

C++: #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int make(int k,int p);

vector<string> a(40);

int main() {
  int n;
  scanf ("%d",&n);
  while(n){
    
    for(int t=0;t<n;t++){
      //scanf ("%s",a[t]);
      cin >> a[t];
    }
    for(int t=n;t<40;t++){
      //scanf ("%s",a[t]);
      a[t]="";
    }
    int end=0;
    int k=0;
    for(k=0;k<n;k++){
      int q=k;
      if(make(q,5)>=1){
        q=1+make(q,5);
        if(make(q,7)>=1){
          q=1+make(q,7);
          if(make(q,5)>=1){
            q=1+make(q,5);
            if(make(q,7)>=1){
              q=1+make(q,7);
              if(make(q,7)>=1){
                q=1+make(q,7);
                end=1;
              }
            }
          }
        }
      }
      if(end==1) break;
    }
    printf("%d\n",k+1);
    scanf ("%d",&n);
  }
}


int make(int k,int p){
  int l=0;
  int r=0;
  l=a[k].size();
  if(l==p){
    return k;
  }
  else{
    if(l<p){
      r=make(k+1,p-l);
      return r;
    }
    return -1;
  }
}

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



bool check(vector<int>& v, int i){

	  vector<int> x = {5,7,5,7,7};
	  int id=0;
	  for(int j=i; j<v.size(); j++){

			x[id] -= v[j];
			if( x[id] == 0 ){
				  id++;
				  if(id == 5) return true;
			}
			else if( x[id] < 0 ){
				  return false;
			}
	  }
	  return false;


}


int main(){
	  while(1){
			int n; cin >> n;
			if(!n) break;

			vector<int> v(n);
			for(int i=0; i<n; i++){
				  string in; cin >> in;
				  v[i] = in.size();
			}
			for(int i=0; i<n; i++){
				  if( check(v,i) ){
						cout << i+1 << endl;
						break;
				  }
			}
			
	  }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int i,n;
    string s;
    int haiku[]={5,7,5,7,7};
    int sum;
    vector<int> ans;
    while(1){
        haiku[0]=5;
        haiku[1]=7;
        haiku[2]=5;
        haiku[3]=7;
        haiku[4]=7;
        cin>>n;
        if(n==0)break;
        vector<int> v(n,0);
        rep(i,n){
            cin>>s;
            v[i]=s.length();
        }
        int phase=0;
        bool ch=false;
        // cout<<"-------------------------------"<<endl;
        rep(i,n-4){
            phase=0;
            int j=0;
            while(1){
                // cout<<j<<" "<<phase<<" "<<v[i+j]<<" "<<haiku[phase]<<endl;
                haiku[phase]-=v[i+j];
                if(haiku[phase]==0)phase++;
                else if(haiku[phase]<0)break;
                if(phase>=5){
                    ch=true;
                    break;
                }
                j++;
            }
            
            if(ch){
                ans.push_back(i+1);
                break;
            }
            haiku[0]=5;
            haiku[1]=7;
            haiku[2]=5;
            haiku[3]=7;
            haiku[4]=7;
        }
        
    }
    rep(i,ans.size())cout<<ans[i]<<endl;
//////////////////////////////////////////////////////
return 0;}