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 <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
int main(){
  int N;
  while(1){
    cin>>N;
    if(N==0){
      break;
    }
    VE V;
    FOR(i,0,N){
      string S;
      cin>>S;
      V.PB((int)S.size());
    }
    FOR(i,0,N){
      int sum=0;
      int now=i;
      while(now<N&&sum<31){
        sum+=V[now];
        now++;
      }
      if(sum==31){
        cout<<i+1<<endl;
        break;
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
int i,j,p,n,q,a[9]={5,7,5,7,7,-1};char s[50];
main(){for(;scanf("%d\n",&n),n;){for(i=0;i<n;s[i++]=strlen(gets(s+i)));
for(i=j=0;j<6;i++)for(p=i,j=q=0;q>=0;)for(q=a[j++];q>0;q-=s[p++]);
printf("%d\n",i);
}}

C++: #include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n);i<(N);i++)
#define RREP(i,n,N) for(ll i=(N-1);i>=(n);i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a,b) memcpy(b,a, sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;
const ll inf =1e18;

ll N;
string w[50];

int main(){
    while(cin>>N && N != 0){
        REP(i,0,N){
            cin>>w[i];
        }

        REP(i,0,N){

            ll cnt = 0;
            ll v = 0;
            bool f = false;

            REP(j,i,N){
                if(v < 1){
                    if(cnt < 5){
                        cnt += w[j].size();
                    }

                    if(cnt == 5){
                        v++;
                        cnt = 0;
                    }else if(cnt > 5){
                        v = 0;
                        cnt = 0;
                        break;
                    }
                }else if(v < 2){
                    if(cnt < 7){
                        cnt += w[j].size();
                    }

                    if(cnt == 7){
                        v++;
                        cnt = 0;
                    }else if(cnt > 7){
                        v = 0;
                        cnt = 0;
                        break;
                    }
                }else if(v < 3){
                    if(cnt < 5){
                        cnt += w[j].size();
                    }

                    if(cnt == 5){
                        v++;
                        cnt = 0;
                    }else if(cnt > 5){
                        v = 0;
                        cnt = 0;
                        break;
                    }
                }else if(v < 4) {
                    if(cnt < 7){
                        cnt += w[j].size();
                    }

                    if(cnt == 7){
                        v++;
                        cnt = 0;
                    }else if(cnt > 7){
                        v = 0;
                        cnt = 0;
                        break;
                    }
                }else if(v < 5){
                    if(cnt < 7){
                        cnt += w[j].size();
                    }

                    if(cnt == 7){
                        v++;
                        cnt = 0;
                    }else if(cnt > 7){
                        v = 0;
                        cnt = 0;
                        break;
                    }
                }

                if(v == 5){
                    cout<<i+1<<endl;
                    f = true;
                    break;
                }
            }

            if(f) break;
        }
    }

    return 0;
}

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

int main(){
	while(1){
		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<vector>
#include<string>
using namespace std;
#define DBG cout<<"!"<<endl;
vector<int> size;
int fin=0;
void dfs(int flag,int count,int i,int now){
  switch(flag){
  case 0:case 2:
    if(count+size[i]>5)
      return;
    if(count+size[i]==5){
      if(flag==0){	
	flag=1;
      }
      if(flag==2)
	flag=3;
    }
    if(flag==0||flag==2)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 1:case 3:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      if(flag==1)
	flag=2;
      if(flag==3)
	flag=4;
    }
    if(flag==1||flag==3)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 4:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      fin=1;
      cout<<now<<endl;
      return;
    }
    dfs(flag,count+size[i],i+1,now);
  }
}
int main(){
  int n;
  while(cin>>n,n!=0){
    fin=0;
    string str2;
    for(int i=0;i<n;i++){
      cin>>str2;
      size.push_back(str2.size());
    }
    for(int i=0;i<n;i++){
      int flag;
      int cnt=size[i];
      int now=i+1;
      if(fin==1)
	break;
      if(cnt==5){
	flag=1;
	cnt=0;
      }
      else
	flag=0;
      if(cnt>5)
	continue;
      dfs(flag,cnt,i+1,now);
    }
    size.clear();
  }
  return 0;
}