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, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<string> s(n);
            vector<int> A(n);
            REP(i, n) cin >> s[i];
            REP(i, n) A[i] = s[i].size();
            int ans;
            bool ok = false;
            REP(i, n + 1){
                int a = 0;
                bool tanka =  false;
                int now = 0; 
                FOR(j, i, A.size()){
                    a += A[j];
                    if(a > 7) break;
                    if((now == 0 or now == 2) and a == 5){
                        now++;
                        a = 0;
                    }
                    if((now == 1 or now == 3) and a == 7){
                        now++;
                        a = 0;
                    }
                    if(now == 4 and a == 7){
                        ok = true;
                        ans = i + 1;
                        break;
                    }
                }
                if(ok) break;
            }
            cout << ans << endl;
        }
    }
}

C++: #include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<numeric>
#include<map>
#include<limits>
using namespace std;

#define R(i,s,n) for(int i=s;i<n;i++)
#define D(i,n,s) for(int i=n-1;i>=s;i--)
typedef pair<int,int> P;
typedef unsigned long long ull;
typedef long long ll;

int n;
vector<string> w;
int mozi[5]={5,7,5,7,7};

int main() {
  while(cin >> n && n){
    w.resize(n);
    R(i,0,n){
      cin >> w[i];
    }

    int out = 0;
    R(i,0,n){
      int sum=0,ku=0;
      R(j,i,n){
        sum += w[j].size();
        if(sum == mozi[ku]){
          sum=0;
          ku++;
          if(ku==5){
            out=i+1;
            goto A;
          }
        }else if(sum > mozi[ku]){
          break;
        }
      }
    }
    A: ;
    cout << out << endl;
    w.clear();
  }
  return 0;
}

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

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

using namespace std;

int main(void)
{
  int tannka[5] = {5, 7, 5, 7, 7};
  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    int w;
    vector<string> v;
    v.resize(n);
    
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    
    //?????????1~5??????  //??\???????????°
    pair<int,int> count = make_pair(0,0);
    for (int i = 0; i < n; i++) {
      string str = v[i];
      //?????????1?????????5????????\?????????
      if (tannka[count.first] >= str.size()) {
	w = i;
	//5????????????
	if (tannka[count.first] == str.size()) {
	  count.first++;
	  count.second = 0;
	}
	//5??????????????????
	else {
	  count.second += str.size();
	}
	
	//?????????1?????????2?????????5??????
	for (int j = i+1; j < n; j++) {
	  str = v[j];
	  if (tannka[count.first] - count.second > str.size()) {
	    count.second += str.size();
	  } else if (tannka[count.first] - count.second == str.size()) {
	    count.first++;
	    count.second = 0;
	  } else {
	    count = make_pair(0,0);
	    break;
	  }
	  //???????????´??£???
	  if (count.first == 5) {
	    cout << w+1 << endl;
	    break;
	  }
	}

	if (count.first == 5)
	  break;
	
      }
      //?????????1?????????5????????§??????
      else { }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

int calc(int p, int c, const vector<string> &s){
	int tmp = 0;
	while(tmp < c) tmp += s[p++].size();
	if(tmp == c) return p;
	return -1;
}

int main(){
	while(1){
		int n = in.nextInt();
		if(n == 0) break;
		vector<string> s(n);
		rep(i, n) s[i] = in.next();
		vi d(n + 1);
		rep(i, n) d[i + 1] = d[i] + s[i].size();
		int a[] = {5, 7, 5, 7, 7};
		rep(i, n){
			int p = i;
			for(int j = 0; j < 5; j++){
				p = calc(p, a[j], s);
				if(p < 0) break;
			}
			if(p >= 0){
				cout<<i + 1<<endl;
				break;
			}
		}
	}
}

C++: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int n;
    while (cin >> n, n) {
        vector<string> w(n);
        REP (i, n) cin >> w[i];
        vector<int> v = {5, 7, 5, 7, 7};
        REP (i, n) {
            int sum = 0, idx = 0;
            FOR (j, i, n) {
                if (sum + w[j].size() > v[idx]) {
                    idx = -1;
                    break;
                }
                sum += w[j].size();
                if (sum == v[idx]) {
                    sum = 0;
                    idx++;
                }
                if (idx == v.size()) break;
            }
            if (idx < 0) continue;
            cout << i + 1 << endl;
            break;
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}