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"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int n;
int solve(){
    int res = 0;
    vector<string> w(n); for(auto& in:w) cin >> in;
    vector<int> tanka = {5,7,5,7,7};
    for(int i = 0; i < w.size();i++){
        int I = 0;
        for(int j = i; j < w.size();j++){
           // cout << tanka << endl;
            if(w[j].length() < tanka[I]){
                tanka[I] -= w[j].length();
            }else if(w[j].length() == tanka[I]){
                tanka[I] = 0;
                I++;
                if(I == 5){
                    return i + 1;
                }
            }else{
                tanka = vector<int>{5,7,5,7,7};
                break;
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n,n){
        cout << solve() << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;

const int step[5] = {5, 7, 5, 7, 7};

int N;
string S[40];

int solve() {
    for (int i = 0; i < N; ++i) {
        bool ok = true;
        int idx = i;
        for (int t = 0; t < 5; ++t) {
            int acc = 0;
            while (acc < step[t]) acc += S[idx++].size();
            if (acc != step[t]) {
                ok = false;
                break;
            }
        }
        if (ok)
            return i+1;
    }

    assert(false);
}

int main(void) {
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int i = 0; i < N; ++i)
            cin >> S[i];

        cout << solve() << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    int w[5] = {5, 7, 5, 7, 7};
    while (cin >> n && n){
        VI a(n);
        REP(i,n) {
            string s;
            cin >> s;
            a[i] = s.length();
        }
        REP(s,n){
            int x = 0, i = s, j = 0, f = 1;
            while (f){
                x += a[i];
                i++;
                if (x == w[j]){
                    x = 0;
                    j++;
                }
                if (x > w[j]) f = 0;
                if (j == 5) break;
            }
            if (f) cout << s+1 << endl;
        }
    }

    return 0;
}

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

C++: #include<iostream>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               if(p==5) break;
               a=0;
            }
         }
         if(p==5){
            cout<< i+1<< endl;
            break;
         }
         turai:;
      }

   }

   return 0;
}

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

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() {

  for(int N; cin >> N && N;) {
    int cnt[41];
    rep(i, N) {
      string s; cin >> s;
      cnt[i] = s.size();
    }
    const array<int, 5> arr{{5,7,5,7,7}};
    rep(st, N) {
      int sum = 0;
      int curr = 0;
      bool ok = 0;
      REP(i, st, N) {
        sum += cnt[i];
        if(sum == arr[curr]) {
          curr++;
          sum = 0;
          if(curr >= arr.size()) {
            ok = 1;
            break;
          }
        }
        if(sum > arr[curr]) {
          break;
        }
      }
      if(ok) {
        cout << st + 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[n];
  for(int i=0; i<n; i++){
   string w;
   cin >> w;
   len[i] = w.size();
  }

  for(int i=0; i<n; i++){
   bool flag = false;
   int sta = 0; //区切り
   int sum = 0; //文字数の合計

   for(int j=i; j<n; j++){
    sum = sum + len[j];
    
    if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
     sta++;
    }

    if(sta==5){
     flag = true;
     break;
    }else if(sum>=31){
     break;
    }
   }

   if(flag){
    cout << i+1 << endl;
   }
  }
 }

 return 0;
}