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,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
void solve(int N){
    vector<int> V(N);
    rep(i,0,N){
        string s;
        cin >> s;
        V[i] = s.size();
    }
    int arr[] = {5,7,5,7,7};
    rep(i,0,N){
        int sum = 0, cur = 0;
        bool ok = 1;
        rep(j,i,N){
            sum += V[j];
            if(sum > arr[cur]){
                ok = 0;
                break;
            }else if(sum == arr[cur]){
                cur++;
                sum = 0;
            }
            if(cur == 5)break;
        }
        if(!ok || cur != 5)continue;
        cout << i+1 << endl;
        return;
    }
}
main(){
    int N;
    cin >> N;
    while(N){
        solve(N);
        cin >> N;
    }
}

C++: #include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<climits>
#include<string.h>
using namespace std;

int main(){
    int n;
    while(cin>>n,n){;
    vector<int>v;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        v.push_back(s.length());
    }
    int nee[5]={5,7,5,7,7};
    for(int i=0;i<v.size();i++){
        int cur=0,ne=0,no=0;
        for(int j=i;j<v.size();j++){
            //cout<<i<<" "<<j<<" "<<cur<<" "<<ne<<endl;
            if(cur+v[j]>nee[ne]){
                break;
            }
            if(cur+v[j]==nee[ne]){
                if(ne==4){
                    cout<<i+1<<endl;
                    goto ne;
                } else {
                    cur=0;ne++;
                }
            } else {
                cur+=v[j];
            }
        }
    }
        ne:;}
}

C++: #include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int d[5]={5,7,5,7,7};
int num[40];
int n;
bool rec(int s){
    int sum=0;
    int t[5];
    REP(i,5)t[i]=d[i];
    int ss=0;
    for(int i=s;i<n;i++){
        if(t[ss]>0)t[ss]-=num[i];
        else{
            ss++;
            t[ss]-=num[i];
        }
    }
    REP(i,5)if(t[i]!=0)return false;
    return true;
}
int main(){
    while(1){
        cin>>n;
        if(n==0)break;
        REP(i,n){
            string s;cin>>s;
            num[i]=s.size();
        }
        REP(i,n){
            if(rec(i)){
                cout<<i+1<<endl;
                break;
            }
        }
    }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
    int n;
    string s;
    int len[5] = {5,7,5,7,7};
    int count;
    int now;
    int ans;
    while(1){
        cin >> n;
        if(n==0) return 0;
        vector<int> w(n);
        for(int i=0;i<n;i++){
            cin >> s;
            w[i]=s.length();
        }
        ans=-1;
        for(int i=0;i<n;i++){
            count = 0;
            now = 0;
            for(int j=i;j<n;j++){
                count+=w[j];
                if(count==len[now]){
                    now++;
                    count=0;
                    if(now==5){
                        ans=i;
                    }
                }else if(count>len[now]){
                    break;
                }
            }
            if(ans != -1){
                break;
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  while(cin >> n,n){
    int i,j,k;
    string buf;
    int d[50]={};
    for(i=0;i<n;i++){
      cin >> buf;
      d[i]=buf.size();
    }
    for(i=0;i<n;i++){
      int c=0;
      j=i;
      while(c<5) c+=d[j++];
      if(c!=5) continue;
      c=0;
      while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      while(c<5) c+=d[j++];
      if(c!=5) continue;
      c=0;while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      cout << i+1 << endl;
      break;
    }
  }
  return 0;
}

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

using namespace std;

#define reps(i,f,n) for(int i=f; i<n; ++i)
#define rep(i,n) reps(i,0,n)

void solve(int n)
{
    vector<int> v(n);
    
    rep(i, n){
        string s;
        cin >> s;
        v[i] = s.size();
    }
    
    const int len[] = {5, 7, 5, 7, 7};
    rep(i, n){
        int p = 0, j = i;
        while(p < 5 && j < n){
            int cnt = len[p];
            for(; cnt && j<n; ++j){
                cnt -= v[j];
                if(cnt < 0) goto end;
            }
            ++p;
        }
        
        if(p == 5){
            cout << i+1 << endl;
            break;
        }
    end:;
    }
}

int main()
{
    int n;
    
    while(cin >> n, n){
        solve(n);
    }
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

int n;
string w[50];
int limit[] = {5,7,5,7,7};

int main() {
  while( cin >> n, n ) {
    rep(i,n) cin >> w[i];
    rep(i,n) {
      int index = 0;
      int sum = 0;
      REP(j,i,n) {
	sum += (int)w[j].size();
	if( sum == limit[index] ) {
	  ++index;
	  sum = 0;
	  if( index >= 5 ) {
	    cout << i+1 << endl;
	    goto Fin;
	  }
	} else if( sum > limit[index] ) {
	  break;
	}
      }
    }
    Fin:;
  }
  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;
	}