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 _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
	for(int n; cin >> n, n;){
		vector<string> in(n);
		for(auto & e : in) cin >> e;

		int res = -1;
		rep(i, n){
			int idx = 0;
			int T[5] = {5, 7, 5, 7, 7};

			[&]{
				rep(j, i, n){
					int & e = T[idx];
					e -= in[j].size();
					if(e < 0) return;
					if(e == 0) idx++;

					if(idx == 5) break;
				}

				res = i + 1;
			}();

			if(res != -1) break;
		}

		cout << res << endl;
	}

    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;
		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 <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    while(1){
        int n; cin>>n;
        if(n==0) return 0;

        vector<int> tanku={5, 7, 5, 7, 7};
        vector<string> w(n);
        for(int i=0; i<n; i++) cin>>w[i];

        for(int i=0; i<n; i++){
            int cnt=0, sum=0;
            for(int j=i; j<n; j++){
                sum+=w[j].size();
                if(sum==tanku[cnt]){
                    sum=0;
                    cnt++;

                    if(cnt==5){
                        cout << i+1 << endl;
                        goto END;
                    }
                }
            }
        }

        END:;
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main(void) {
    int n;
    int tan[5] = {5,7,5,7,7};
    cin >> n;
    while (n != 0) {
        vector<string> str(n);
        for (int i = 0; i < n; ++i) {
            cin >> str[i];
        }
        bool find = false;
        bool over = false;
        int ind = 0;
        int ln = 0;
        int ret;
        for (int i = 0; !find && i < n; ++i) {
            over = false;
            ind = 0;
            ln = 0;
            for (int j = i; !over && j < n; ++j) {
                if (ln + str[j].length() == tan[ind]) {
                    if (ind == 4) {
                        find = true;
                        ret = i+1;
                    }
                    else {
                        ++ind;
                        ln = 0;
                    }
                }
                else if (ln + str[j].length() < tan[ind]) {
                    ln += str[j].length();
                }
                else {
                    over = true;
                }
            }
        }
        cout << ret << endl;
        cin >> n;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int a[]={5,7,5,7,7,0},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)cout<<i+1<<endl;
          }
        }
      }
    }
  }

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 <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=1; j<n; j++){
	sum += len[j];

	if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
	  sta++;
	}

	if(sta==5){
	  flg = true;
	  cout << "OK" << endl;
	  break;
	}
	else if(sum>=31){
	  break;
	}
      }

      if(flg){
	cout << i+1 << endl;
	break;
      }
    }
    cout << "Not OK" << endl;
  }

  return 0;
}