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 <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    vs vec;
    rep(i,0,n){
      cin >> s;
      vec.pb(s);
    }
    m = -1;
    rep(i,0,vec.sz){
      t = "";
      l = 0;
      rep(j,i,vec.sz){
        t += vec[j];
        // cout << t << " " << t.sz << endl;
        if(t.sz == 5)l++;
        if(t.sz == 5+7)l++;
        if(t.sz == 5+7+5)l++;
        if(t.sz == 5+7+5+7)l++;
        if(t.sz == 5+7+5+7+7)l++;
        if(t.sz >= 31){
          if(l == 5){
            m = i + 1;
            break;
          }
        }
      }
      if(m != -1)break;
    }
    print(m);
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  while(cin >> n,n){
    int i,j,k;
    string buf;
    int d[50]={};
    for(i=0;i<n;i++){
      cin >> buf;
      d[i]=buf.size();
    }
    for(i=0;i<n;i++){
      int c=0;
      j=i;
      while(c<5) c+=d[j++];
      if(c!=5) continue;
      c=0;
      while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      while(c<5) c+=d[j++];
      if(c!=5) continue;
      c=0;while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      while(c<7) c+=d[j++];
      if(c!=7) continue;
      c=0;
      cout << i+1 << endl;
      break;
    }
  }
  return 0;
}

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

int main()
{
	int n;
	string s;
	while (cin >> n, n) {
		vector<int> w(n);
		for (int i = 0; i < n; i++) {
			cin >> s;
			w[i] = s.size();
		}
		int res = -1;
		for (int i = 0; i < n; i++) {
			bool tmp[] = { false, false, false, false };
			int sum = 0;
			for (int j = i;j < n; j++) {
				sum += w[j];
				if (sum == 5) {
					tmp[0] = true;
				}
				if (sum == 12) {
					if (tmp[0]) {
						tmp[1] = true;
					}
					else {
						break;
					}
				}
				if (sum == 17) {
					if (tmp[1]) {
						tmp[2] = true;
					}
					else {
						break;
					}
				}
				if (sum == 24) {
					if (tmp[2]) {
						tmp[3] = true;
					}
					else {
						break;
					}
				}
				if (sum == 31) {
					if (tmp[3]) {
						res = i + 1;
						break;
					}
					else {
						break;
					}
				}
			}
			if (res != -1)
				break;
		}
		cout << res << endl;
	}
	return 0;
}

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

void solve(int n){
    vector<string> vs(n);
    for(int i=0;i<n;i++) cin >> vs[i];

    for(int i=0;i<n;i++){
        int idx=i;
        bool ok = true;
        //5 [i,idx]
        int sum = 0;
        for(int j=i;j<n;j++){
            sum += vs[j].size();
            if(sum > 5){
                ok = false;
                break;
            }
            if(sum == 5){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 1 " << endl;
            continue; }
        idx++;
        ///cerr << "idx " << idx << endl;
        //7
        sum = 0;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 7){
                ok = false;
                break;
            }
            if(sum == 7){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 2" << endl;
            continue; }
        idx++;

        //cerr << "idx " << idx << endl;
        //5
        sum = 0;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 5){
                ok = false;
                break;
            }
            if(sum == 5){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 3" << endl;
            continue; }
        idx++;

        //7
        sum = 0;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 7){
                ok = false;
                break;
            }
            if(sum == 7){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 4" << endl;
            continue; }
        idx++;
        //7
        sum = 0;
        //cerr << "idx  " << idx << endl;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 7){
                ok = false;
                break;
            }
            if(sum == 7){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 5"<< endl;
            continue; }
        idx++;
        cout << i+1 << endl;
        return;
    }
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        solve(n);
    }
}

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=i;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;
}