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 <string>

using namespace std;

int main(){
    int i,j,k,l;
    int n;
    int d5a=0,d7a=0,d5b=0,d7b=0,d7c=0;
    int stg=0;
    int ok=0,ans,first;
    while(1){
        cin >> n;
        if(n==0) break;
        string str[n];
        for(i=0;i<n;i++){
            cin >> str[i];
        }
        first = 0;
        for(i=0;i<n;i++){
            //i番目から始める
            stg = 0;
            int tmp=0;
            for(j=i;j<n;j++){
                if(first==0){
                    if(stg==0){
                        tmp += str[j].size();
                        if(tmp==5){
                            stg = 1;
                            tmp = 0;
                        } 
                    }else if(stg==1){
                        tmp += str[j].size();
                        if(tmp==7){
                            stg = 2;
                            tmp = 0;
                        }
                    }else if(stg==2){
                        tmp += str[j].size();
                        if(tmp==5){
                            stg = 3;
                            tmp = 0;
                        }
                    }else if(stg==3){
                        tmp += str[j].size();
                        if(tmp==7){
                            stg = 4;
                            tmp = 0;
                        }
                    }else if(stg==4){
                        tmp += str[j].size();
                        if(tmp==7){
                            stg = 5;
                            tmp = 0;
                        }
                    }
                    // cout << tmp << " " << endl; 
                     
                }
                
            }
            if(stg==5&&first==0){
                    first = 1;  
                    cout << i+1 << endl;  
            }
        }
    }   
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n;
		cin >> n;
		if (!n)break;
		vi v(n);
		REP(i, n) {
			string s;
			cin >> s;
			v[i] = s.size();
		}
		vi a = { 5,7,5,7,7 };
		REP(i, n) {
			int k = 0,sum = 0;
			FOR(j, i, n) {
				while (k < 5) {
					while (j < n&&sum < a[k]) {
						sum += v[j];
						j++;
					}
					if (sum == a[k]) {
						sum = 0;
						k++;
						if (k == 5) {
							cout << i + 1 << endl;
							goto ok;
						}
					}
					else break;
				}
			}
		
		}
	ok:;
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    string tmp;
    vi a(n);
    REP(i, n) {
      cin >> tmp;
      a[i] = SZ(tmp);
    }
    REP(i, n) {
      vi b = {5, 7, 5, 7, 7};
      int cnt = 0;
      bool ok = false;
      FOR(j, i, n) {
        if(b[cnt] < a[j]) {
          break;
        } else if(b[cnt] == a[j]) {
          if(cnt == 4) {
            ok = true;
            break;
          } else {
            cnt++;
          }
        } else {
          b[cnt] -= a[j];
        }
      }
      if(ok) {
        cout << i+1 << endl;
        break;
      }
    }
  }
}

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


int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    int n;
    while(cin>>n){
        if(!n) break;
        string s[n];
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        int ans=0;
        int haiku[5] = {5,7,5,7,7};
        for(int i=0;i<n;i++){
            bool pos=true;
            int j=i;
            int cnt=0,now=0;
            while(pos && j<n){
                cnt+=s[j].size();
                if(cnt>haiku[now]){
                    pos=false;
                }
                if(cnt==haiku[now]){
                    cnt=0;
                    now++;
                }
                if(now==5) break;
                j++;
            }
            if(pos){
                cout<<i+1<<endl;
                break;
            }
        }
    }
    
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int tnk[5]={5,7,5,7,7};
	int n;
	while(cin>>n,n){
		string s[40];
		int snum=0,now=0,ans=1;
		REP(i,0,n){
			cin>>s[i];
		}
		int j=0;
		while(1){
			snum+=s[j].size();
			j++;
			if(snum==tnk[now]){
				snum=0;
				now++;
			}else if(snum>tnk[now]){
				snum=0;
				now=0;
				j=ans;
				ans++;
			}
			if(now==5){
				p(ans);
				break;
			}

		}
	}
	return 0;
}