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"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

bool is_haiku_found(const vector<ll> &len, ll idx)
{
    ll a = 0;
    for (; idx < len.size(); ++idx) {
        a += len[idx];
        if (a == 5)break;
        else if (a > 5)return false;
    }
    ll b = 0;
    for (++idx; idx < len.size(); ++idx) {
        b += len[idx];
        if (b == 7)break;
        else if (b > 7)return false;
    }
    ll c = 0;
    for (++idx; idx < len.size(); ++idx) {
        c += len[idx];
        if (c == 5)break;
        else if (c > 5)return false;
    }
    ll d = 0;
    for (++idx; idx < len.size(); ++idx) {
        d += len[idx];
        if (d == 7)break;
        else if (d > 7)return false;
    }
    ll e = 0;
    for (++idx; idx < len.size(); ++idx) {
        e += len[idx];
        if (e == 7)break;
        else if (e > 7)return false;
    }
    return
        a == 5 &&
        b == 7 &&
        c == 5 &&
        d == 7 &&
        e == 7;
}
int main()
{
    while (true) {
        ll n = in();
        if (n == 0)break;
        vector<ll>len(n);
        REP(i, n)len[i] = in<string>().length();
        REP(i, n) {
            if (is_haiku_found(len, i)) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
}

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

int ph[5] = {5, 7, 5, 7, 7};

bool check(vector<int> &wl, int l, int r) {
    int cnt = 0, k = 0;
    for (int i=l; i<r; ++i) {
        cnt += wl[i];
        if (cnt == ph[k]) {
            cnt = 0;
            k ++;
        }
    }
    return k == 5;
}

int main() {
    int n;
    while (cin >> n) {
        if (!n) break;
        vector<int> wl(n);
        for (int i=0; i<n; ++i) {
            string w;
            cin >> w;
            wl[i] = w.size();
        }
        
        int ans = -1;
        int i=0, len = 0;
        for (int j=1; j<=n; ++j) {
            len += wl[j-1];
            while (31 < len) {
                len -= wl[i];
                i++;
            }
            if (len == 31 && check(wl, i, j)) {
                ans = i+1;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
   while(true){
       int n;
       cin>>n;

       if(n==0) break;

       int len[40];
       for (int i = 0; i < n; i++) {
           string w;
           cin>>w;

           len[i]=w.size();
       }
       for (int i = 0; i < n; i++) {
           bool flg=false;
           int sta=0;
           int sum=0;

           for (int j = 0; j < n; j++) {
               sum+=len[j];
               if(sum==5||sum==12||sum==17||sum==24||sum==31){
                   sta++;
               }
               if (sta==5) {
                   flg=true;
                   break;
               } else if(sum>=31){
                   break;
               }
           }

           if(flg){
               cout<<i+1<<endl;
               break;
           }
       }
    }
    return 0;
}

C++: #include<iostream>
#include<math.h>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int main(){
  std::ifstream in("test.txt");
  std::cin.rdbuf(in.rdbuf());
  int n;
  string inp;
  int set[5]={5,12,17,24,31};
  while(1){
    cin >> n;
    if(n==0)return 0;

    //int list[n];
    int shori[n];
    
    int size;
    int ans=0;
    //  int num=0;
    for(int i=0;i<n;i++){
      cin >> inp;
      if(ans==-1)continue;
      size=inp.size();
      shori[i]=0;
      //cout << list[i] << endl;
      for(int j=0;j<=i;j++){
	if(shori[j]==-1)continue;
       
        for(int l=0;l<5;l++){
	  if(shori[j]<set[l]){
	    if(size<=set[l]-shori[j]){
	      shori[j]+=size;
	      break;
	    }else{
	      shori[j]=-1;
	      break;
	    }
	  }
	}
	if(shori[j]==set[4]){
	  cout << j+1 << endl;
	  ans=-1;
	  break;
	}
      }
      
   
    }
 
  }
      
}

C++: //
//  main.cpp
//  Short Phrase
//
//  Created by x15071xx on 2017/06/18.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;
int main(int argc, const char * argv[]) {
    
    while (1) {
        int n,i,j;
        vector<string> str;
        cin >> n;
        
        if (n == 0) {
            break;
        }
        
        string tmp;
        for (i = 0; i < n; i++) {
            
            cin >> tmp;
            str.push_back(tmp);
            
        }
        
        for (i = 0; i < n; i++) {
            int flag = 0;
            j = i;
            int numsum = 0;
            while (1) {
                if (flag == -1) {
                    break;
                }
                
                if (flag == 5) {
                    cout << i+1 << endl;
                    break;
                }
                
                
                numsum+=str[i+j].length();
                
//                if (i == 5) {
//                    cout << numsum << str[i+j] <<endl;
//                }
                if (flag == 0 || flag == 2) {
                    
                    if (numsum > 5) {
                        flag = -1;
                    } else if (numsum < 5){
                        j++;
                    } else if (numsum == 5) {
                        flag++;
                        numsum = 0;
                        j++;
                    }
                } else {
                    if (numsum > 7) {
                        flag = -1;
                    } else if (numsum < 7) {
                        j++;
                    } else if (numsum == 7) {
                        flag++;
                        numsum = 0;
                        j++;
                    }
                }
            }
            
            if (flag == 5) {
                break;
            }
        }
        
    }
    return 0;
}