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 <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N;

  while(cin >> N && N) {
    vector<string> v;
    rep(i, N) {
      string s; cin >> s;
      v.push_back(s);
    }

    vector<int> wsize = {5,7,5,7,7};
    rep(i, N) {
      int idx = 0;
      bool ok = 0;
      int j = i;
      int curr = 0;
//      cout << "------" << endl;
      while(j < N) {
//        cout << v[j] << endl;
        if(curr + v[j].size() < wsize[idx]) {
          curr += v[j].size();
        } else if(curr + v[j].size() == wsize[idx]) {
          curr = 0;
          idx ++;
          if(idx == wsize.size()) {
            ok = 1;
            break;
          }
        } else {
          break;
        }
        j++;
      }
      if(ok) {
        cout << i + 1 << endl;
        break;
      }
    }

  }
  
  return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main(){
  vi p = {5, 12, 17, 24, 31};
  
  while(1){
    int n; cin >> n; if(n == 0) break;

    vs w(n); rep(i,n) cin >> w[i];
    vi l(n+1); rep(i,n) l[i+1] = sz(w[i]);
    rep(i,n) l[i+1] += l[i];

    rep(i,n){
      bool f = true;
      rep(j,5) if(not binary_search(all(l),p[j] + l[i])) f = false;
      if(f){
	cout << i + 1 << endl;
	break;
      }
    }
  }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<double,pair<string,int> > mypair;
string re(string a){
	for(int i=0;i<a.size();i++){
		a[i]='a'+('z'-a[i]);
	}
	return a;
	}
	string eq(string a){
		string b;
		for(int i=0;i<20;i++)
         b.push_back('A');
		for(int i=0;i<a.size();i++)
     b[i]=a[i];
		return b;
	}
int main(void){
	int n;
	while(1){
cin>> n;
if(n==0)break;
vector<string> l(n);
vector<int> p(n),a(n),b(n),c(n),d(n),e(n),f(n),s(n),m(n);
for(int i=0;i<n;i++)
cin>>l[i]>>p[i]>>a[i]>>b[i]>>c[i]>>d[i]>>e[i]>>f[i]>>s[i]>>m[i];
vector<mypair> q(n);
for(int i=0;i<n;i++){
	q[i].first=(double)(m[i]*f[i]*s[i]-p[i])/(a[i]+b[i]+c[i]+m[i]*(d[i]+e[i]));
	q[i].second.first=re(eq(l[i]));
	q[i].second.second=i;
}

sort(q.begin(),q.end(),greater<mypair>());

for(int i=0;i<n;i++){
cout<<l[q[i].second.second] <<endl;
}
cout<<'#'<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)continue;
using namespace std;
main(){
    for(int n,v[50],s,p,c;cin>>n,n;){
        for(s=1;s<n;s++){string t;cin>>t;v[s]=t.size();}
        for(s=p=1;;p=++s){f(5);f(7);f(5);f(7);f(7);cout<<s<<endl;break;}
    }
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
const int MOD = 1000000007;

int main() {
	int n;
	int c[] = {5, 7, 5, 7, 7};
	while (cin >> n, n) {
		vs w(n);
		REP(i, n) {
			cin >> w[i];
		}
		int ans = -1;
		REP(i, n) {
			int p = 0, t = 0;
			FOR(j, i, n - 1) {
				t += w[j].size();
				if (t == c[p]) {
					if (p == 4) {
						ans = i+1;
						break;
					}
					else {
						p++;
						t = 0;
					}
				}
				else if (t > c[p]) {
					break;
				}
			}
			if (ans != -1) {
				break;
			}
		}
		cout << ans << endl;
	}
}