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++: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long 
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		vector<int> cnt;
		REP(i, n) {
			string s;
			cin >> s;
			cnt.push_back(s.length());
		}
		for (int i = 0; i < cnt.size(); ++i) {
			int tmp_a = cnt[i];
			for (int q = i + 1;; ++q) {
				if (tmp_a == 5) {
					int tmp_b = cnt[q];
					for (int j = q + 1; ; ++j) {
						if (tmp_b == 7) {
							int tmp_c = cnt[j];
							for (int t = j + 1;;++t){
								if (tmp_c == 5) {
									int tmp_d = cnt[t];
									for (int p = t + 1;; ++p) {
										if (tmp_d == 7) {
											int tmp_e = cnt[p];
											for (int tea = p + 1;; ++tea) {
												if (tmp_e == 7) {
													cout << i+1 << endl;
													goto ok;
												}
												if (tea == cnt.size()) break;
												tmp_e += cnt[tea];
												if (tmp_e > 7) break;
											}
										}
										if (p == cnt.size()) break;
										tmp_d += cnt[p];
										if (tmp_d > 7) break;
									}
								}
								if (t == cnt.size()) break;
								tmp_c += cnt[t];
								if (tmp_c > 5) break;
							}
						}
						if (j == cnt.size()) break;
						tmp_b += cnt[j];
						if (tmp_b > 7) break;
					}
				}
				if (q == cnt.size()) break;
				tmp_a += cnt[q];
				if (tmp_a > 5) break;
			}
		}
	ok:;
	}
}

C++: #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int make(int w,int p);

vector<string> a(40);

int main() {
  int n;
  scanf ("%d",&n);
  while(n){

    for(int t=0;t<n;t++){
      //scanf ("%s",a[t]);
      cin >> a[t];
    }
    for(int t=n;t<40;t++){
      //scanf ("%s",a[t]);
      a[t]="";
    }
    int end=0;
    int k=0;
    for(k=0;k<n;k++){
      int q=k;
      if(make(q,5)>=1){
        q=1+make(q,5);
        if(make(q,7)>=1){
          q=1+make(q,7);
          if(make(q,5)>=1){
            q=1+make(q,5);
            if(make(q,7)>=1){
              q=1+make(q,7);
              if(make(q,7)>=1){
                end=1;
                //printf("qwqw\n");
              }
            }
          }
        }
      }
      if(end==1) break;
    }
    printf("%d\n",k+1);
    scanf ("%d",&n);
  }
}


int make(int w,int p){
  int l=a[w].size();
  int r=0;
  if(l==p){
    return w;
  }
  else{
    if(l<p){
      r=make(w+1,p-l);
      //printf("%d\n",r);
      return r;
    }
    else{
      return -1;
    }
  }
}

C++: #include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e17+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
bool solve(void){
	int n,i,j;cin>>n;
	if(n==0){return false;}
	vector<int>ta(n+1);
	for(i=0;i<n;i++){string s;cin>>s;ta[i]=s.size();}
	ta[n]=9999999;
	int tanka[5]={5,7,5,7,7};
	for(i=0;i<n;i++){
		int bas=0,num=0;
		for(j=i;;j++){
			num+=ta[j];
			if(num>tanka[bas]){break;}
			if(num==tanka[bas]){bas++;num=0;}
			if(bas==5){cout<<i+1<<endl;return true;}
		}
	}
	
	return true;
}
int main(void){
	while(solve()){}
}

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

int main(){
  string str;
  while(1){
    int temp[50] = {}, n, sum, count, f = 0, ans = 0;

    cin>>n;

    if(n == 0) break;

    for(int i = 1; i <= n; i++){
      cin>>str;
      temp[i] = str.size();//cout<<temp[i]<<endl;
      // temp[i] += tmep[i-1];
    }

    for(int i = 1; i <= n; i++){
      sum = 0;count = 0;
      for(int j = i; j <= n; j++){//cout<<"-------"<<j<<endl;
	sum += temp[j];//cout<<sum<<endl;
	if(sum == 5 && (count == 0 || count == 2)){count++;sum = 0;}
	if(sum == 7 && (count == 1 || count == 3 || count == 4)){count++;sum = 0;}
	//	if(sum == 5 && count == 2){count++;sum = 0}
	//	if(sum == 7 && count == 3){count++;sum = 0}
	//	if(sum == 7 && count == 4){count++;sum = 0}
	if(count == 5){f = 1; break;}
      }
      if(f == 1){ans = i; break;}
    }

    cout<<ans<<endl;

  }
  return 0;
}

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

int main() {
  int n;
  while (cin >> n, n) {
    auto c = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      string w; cin >> w;
      c[i] = w.length();
    }
    auto s = vector<int>(n + 1, 0);
    auto phrase = vector<int>{5, 7, 5, 7, 7};
    for (int i = 0; i < n; ++i) s[i + 1] = s[i] + c[i];

    auto solve = [&]() {
      for (int i = 0; i < n; ++i) {
        int cur = i, nxt = n + 1;
        for (int j = 0; j < 5; ++j, cur = nxt) {
          nxt = distance(begin(s), find(begin(s), end(s), s[cur] + phrase[j]));
          if (nxt == n + 1) break;
          if (j == 4) return i + 1;
        }
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}