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 _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int main(){
  int num_word;
  while(~scanf("%d",&num_word)) {
    if (num_word == 0) break;
    
    vector<string> words;
    for (int word_i = 0; word_i < num_word; word_i++) {
      string word;
      cin >> word;
      words.push_back(word);
    }
    int res = 0;
    for (int start = 0; start < num_word; start++) {
      bool has_end[50];
      memset(has_end, 0, sizeof(has_end));
      int pos = 0;
      for (int word_i = start; word_i < num_word; word_i++) {
	pos += words[word_i].size();
	has_end[pos] = true;
      }

      if (has_end[5] && has_end[5 + 7] && has_end[5 + 7 + 5]
	  && has_end[5 + 7 + 5 + 7] && has_end[5 + 7 + 5 + 7 + 7]) {
	res = start + 1;
	break;
      }
    }
    printf("%d\n",res);
  }
}

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

int main() {
    int n;
    while(cin >> n, n) {
        int cnt[5] = {5, 7, 5, 7, 7};
        vector<string> v(n);
        for(int i=0; i<n; ++i) {
            cin >> v[i];
        }
        int res = 0;
        for(int i=0; i<n; ++i) {
            int c = 0, len = 0;
            bool ok = false;
            for(int j=i; j<n; ++j) {
                len += v[j].size();
                if(len == cnt[c]) {
                    if(c == 4) {
                        ok = true;
                        res = i+1;
                        break;
                    }
                    c++;
                    len = 0;
                } else if(len > cnt[c]) {
                    break;
                }
            }
            if(ok) {
                cout << res << endl;
                break;
            }
        }
    }
}

C++: #include <iostream>
#include <string>
using namespace std;
 
int main()
{
    while(true){
        int n;
        cin >> n;
 
        if(n==0)
            break;
 
        string w[40];
        int len[40];
        for(int i=0; i<n; i++){
            cin >> w[i];
            len[i] = w[i].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;
}

C++: #include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
int arr[7368792];
signed main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0)break;
        vector<string> s(n);
        rep(i,n)cin >> s[i];
        for(int i = 0;i <= n-5;i++){
            int num[5] = {0};
            int stage = 0;
            int flag = 0;
            for(int j = i;j < n;j++){
                if(stage == 0){
                    num[stage] += s[j].size();
                    if(num[stage] == 5)stage++;
                    else if(num[stage] > 5)break;
                }else if(stage == 1){
                    num[stage] += s[j].size();
                    if(num[stage] == 7)stage++;
                    else if(num[stage] > 7)break;
                }else if(stage == 2){
                    num[stage] += s[j].size();
                    if(num[stage] == 5)stage++;
                    else if(num[stage] > 5)break;
                }else if(stage == 3){
                    num[stage] += s[j].size();
                    if(num[stage] == 7)stage++;
                    else if(num[stage] > 7)break;
                }else if(stage == 4){
                    num[stage] += s[j].size();
                    if(num[stage] == 7){
                        cout << i+1 << endl;
                        flag = 1;
                        break;
                    }
                    else if(num[stage] > 7)break;
                }
            }
            if(flag)break;
        }
    }
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc133.contest.atcoder.jp/tasks/abc133_b

C++: #include<iostream>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0; i<n; i++)
int n;
int mem;
int count1;
int count2;
string s[40];
bool check;

void test(int k, int l){
  count1 = 0;
  for(int j=0; j+k<n; j++){
    count1 += s[k+j].length();
    if(count1 > l)return;
    if(count1==l){
      count2++;
      if(l==5&&count2==1){
        mem = k;
      }
      if(l==7){
        if(count2==5){
          check = true;
          return;
        }
      }
      switch(count2){
        case 1: return test(k+j+1,7);
        case 2: return test(k+j+1,5);
        case 3: return test(k+j+1,7);
        case 4: return test(k+j+1,7);
      }
    }
  }
}

int main(){
  while(cin>>n&&n){
    check = false;
    REP(i,n){
      cin >> s[i];
    }
    REP(i,n){
      count1 = 0;
      count2 = 0;
      test(i,5);
      if(check==true){
        cout << mem+1 << endl;
        break;
      }
    }
  }
  return 0;
}